-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Hide tokenless banner for signed out user
- Loading branch information
1 parent
02d5b6b
commit ef1d10b
Showing
2 changed files
with
66 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ import { setupServer } from 'msw/node' | |
import { Suspense } from 'react' | ||
import { MemoryRouter, Route } from 'react-router-dom' | ||
|
||
import { Plans } from 'shared/utils/billing' | ||
|
||
import TokenlessBanner from './TokenlessBanner' | ||
|
||
const mocks = vi.hoisted(() => ({ | ||
|
@@ -15,6 +17,8 @@ vi.mock('shared/featureFlags', () => ({ | |
useFlags: mocks.useFlags, | ||
})) | ||
|
||
vi.mock('services/users') | ||
|
||
vi.mock('./TokenRequiredBanner', () => ({ | ||
default: () => 'TokenRequiredBanner', | ||
})) | ||
|
@@ -41,6 +45,50 @@ afterAll(() => { | |
server.close() | ||
}) | ||
|
||
const mockSignedInUser = { | ||
me: { | ||
owner: { | ||
defaultOrgUsername: 'codecov', | ||
}, | ||
email: '[email protected]', | ||
privateAccess: true, | ||
onboardingCompleted: true, | ||
businessEmail: '[email protected]', | ||
termsAgreement: true, | ||
user: { | ||
name: 'Jane Doe', | ||
username: 'janedoe', | ||
avatarUrl: 'http://127.0.0.1/avatar-url', | ||
avatar: 'http://127.0.0.1/avatar-url', | ||
student: false, | ||
studentCreatedAt: null, | ||
studentUpdatedAt: null, | ||
customerIntent: 'PERSONAL', | ||
}, | ||
trackingMetadata: { | ||
service: 'github', | ||
ownerid: 123, | ||
serviceId: '123', | ||
plan: Plans.USERS_BASIC, | ||
staff: false, | ||
hasYaml: false, | ||
bot: null, | ||
delinquent: null, | ||
didTrial: null, | ||
planProvider: null, | ||
planUserCount: 1, | ||
createdAt: 'timestamp', | ||
updatedAt: 'timestamp', | ||
profile: { | ||
createdAt: 'timestamp', | ||
otherGoal: null, | ||
typeProjects: [], | ||
goals: [], | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
const wrapper = | ||
(initialEntries = ['/gh/codecov']): React.FC<React.PropsWithChildren> => | ||
({ children }) => ( | ||
|
@@ -57,9 +105,11 @@ describe('TokenlessBanner', () => { | |
function setup({ | ||
tokenlessSection = true, | ||
uploadTokenRequired = false, | ||
currentUser, | ||
}: { | ||
tokenlessSection?: boolean | ||
uploadTokenRequired?: boolean | ||
currentUser?: any | ||
} = {}) { | ||
mocks.useFlags.mockReturnValue({ tokenlessSection }) | ||
|
||
|
@@ -74,12 +124,15 @@ describe('TokenlessBanner', () => { | |
}, | ||
}, | ||
}) | ||
}), | ||
graphql.query('CurrentUser', () => { | ||
return HttpResponse.json({ data: currentUser }) | ||
}) | ||
) | ||
} | ||
|
||
it('renders nothing when tokenlessSection flag is false', () => { | ||
setup({ tokenlessSection: false }) | ||
setup({ tokenlessSection: false, currentUser: mockSignedInUser }) | ||
const { container } = render(<TokenlessBanner />, { wrapper: wrapper() }) | ||
expect(container).toBeEmptyDOMElement() | ||
}) | ||
|
@@ -93,7 +146,7 @@ describe('TokenlessBanner', () => { | |
}) | ||
|
||
it('renders TokenRequiredBanner when uploadTokenRequired is true', async () => { | ||
setup({ uploadTokenRequired: true }) | ||
setup({ uploadTokenRequired: true, currentUser: mockSignedInUser }) | ||
render(<TokenlessBanner />, { wrapper: wrapper() }) | ||
|
||
await waitFor(() => { | ||
|
@@ -102,13 +155,19 @@ describe('TokenlessBanner', () => { | |
}) | ||
}) | ||
|
||
it('renders TokenNotRequiredBanner when uploadTokenRequired is false', async () => { | ||
setup({ uploadTokenRequired: false }) | ||
it.only('renders TokenNotRequiredBanner when uploadTokenRequired is false', async () => { | ||
setup({ uploadTokenRequired: false, currentUser: mockSignedInUser }) | ||
render(<TokenlessBanner />, { wrapper: wrapper() }) | ||
|
||
await waitFor(() => { | ||
const banner = screen.getByText('TokenNotRequiredBanner') | ||
expect(banner).toBeInTheDocument() | ||
}) | ||
}) | ||
|
||
it.only('renders nothing when currentUser is not provided', () => { | ||
setup({ uploadTokenRequired: false, currentUser: mockSignedInUser }) | ||
const { container } = render(<TokenlessBanner />, { wrapper: wrapper() }) | ||
expect(container).toBeEmptyDOMElement() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters