Skip to content

Commit

Permalink
test: login with github (#1551)
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Setch <[email protected]>
  • Loading branch information
setchy authored Sep 25, 2024
1 parent 888bac5 commit ae72183
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
15 changes: 7 additions & 8 deletions src/routes/Accounts.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,15 @@ describe('routes/Accounts.tsx', () => {

describe('Add new accounts', () => {
it('should show login with github app', async () => {
const mockLoginWithGitHubApp = jest.fn();

await act(async () => {
render(
<AppContext.Provider
value={{
auth: { accounts: [mockOAuthAccount] },
settings: mockSettings,
loginWithGitHubApp: mockLoginWithGitHubApp,
}}
>
<MemoryRouter>
Expand All @@ -254,9 +257,9 @@ describe('routes/Accounts.tsx', () => {
);
});

expect(screen.getByTitle('Login with GitHub App').hidden).toBe(false);
fireEvent.click(screen.getByTitle('Login with GitHub'));

fireEvent.click(screen.getByTitle('Login with GitHub App'));
expect(mockLoginWithGitHubApp).toHaveBeenCalled();
});

it('should show login with personal access token', async () => {
Expand All @@ -275,11 +278,8 @@ describe('routes/Accounts.tsx', () => {
);
});

expect(screen.getByTitle('Login with Personal Access Token').hidden).toBe(
false,
);

fireEvent.click(screen.getByTitle('Login with Personal Access Token'));

expect(mockNavigate).toHaveBeenNthCalledWith(
1,
'/login-personal-access-token',
Expand All @@ -305,9 +305,8 @@ describe('routes/Accounts.tsx', () => {
);
});

expect(screen.getByTitle('Login with OAuth App').hidden).toBe(false);

fireEvent.click(screen.getByTitle('Login with OAuth App'));

expect(mockNavigate).toHaveBeenNthCalledWith(1, '/login-oauth-app', {
replace: true,
});
Expand Down
2 changes: 1 addition & 1 deletion src/routes/Accounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export const AccountsRoute: FC = () => {
<button
type="button"
className={BUTTON_CLASS_NAME}
title="Login with GitHub App"
title="Login with GitHub"
onClick={loginWithGitHub}
>
<MarkGithubIcon
Expand Down
20 changes: 20 additions & 0 deletions src/routes/Login.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ describe('routes/Login.tsx', () => {
expect(mockNavigate).toHaveBeenNthCalledWith(1, '/', { replace: true });
});

it('should login with github', () => {
const mockLoginWithGitHubApp = jest.fn();
render(
<AppContext.Provider
value={{
loginWithGitHubApp: mockLoginWithGitHubApp,
}}
>
<MemoryRouter>
<LoginRoute />
</MemoryRouter>
,
</AppContext.Provider>,
);

fireEvent.click(screen.getByLabelText('Login with GitHub'));

expect(mockLoginWithGitHubApp).toHaveBeenCalled();
});

it('should navigate to login with personal access token', () => {
render(
<MemoryRouter>
Expand Down
2 changes: 1 addition & 1 deletion src/routes/__snapshots__/Accounts.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ae72183

Please sign in to comment.