Skip to content

Commit ae72183

Browse files
authored
test: login with github (#1551)
Signed-off-by: Adam Setch <[email protected]>
1 parent 888bac5 commit ae72183

File tree

4 files changed

+29
-10
lines changed

4 files changed

+29
-10
lines changed

src/routes/Accounts.test.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,15 @@ describe('routes/Accounts.tsx', () => {
239239

240240
describe('Add new accounts', () => {
241241
it('should show login with github app', async () => {
242+
const mockLoginWithGitHubApp = jest.fn();
243+
242244
await act(async () => {
243245
render(
244246
<AppContext.Provider
245247
value={{
246248
auth: { accounts: [mockOAuthAccount] },
247249
settings: mockSettings,
250+
loginWithGitHubApp: mockLoginWithGitHubApp,
248251
}}
249252
>
250253
<MemoryRouter>
@@ -254,9 +257,9 @@ describe('routes/Accounts.tsx', () => {
254257
);
255258
});
256259

257-
expect(screen.getByTitle('Login with GitHub App').hidden).toBe(false);
260+
fireEvent.click(screen.getByTitle('Login with GitHub'));
258261

259-
fireEvent.click(screen.getByTitle('Login with GitHub App'));
262+
expect(mockLoginWithGitHubApp).toHaveBeenCalled();
260263
});
261264

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

278-
expect(screen.getByTitle('Login with Personal Access Token').hidden).toBe(
279-
false,
280-
);
281-
282281
fireEvent.click(screen.getByTitle('Login with Personal Access Token'));
282+
283283
expect(mockNavigate).toHaveBeenNthCalledWith(
284284
1,
285285
'/login-personal-access-token',
@@ -305,9 +305,8 @@ describe('routes/Accounts.tsx', () => {
305305
);
306306
});
307307

308-
expect(screen.getByTitle('Login with OAuth App').hidden).toBe(false);
309-
310308
fireEvent.click(screen.getByTitle('Login with OAuth App'));
309+
311310
expect(mockNavigate).toHaveBeenNthCalledWith(1, '/login-oauth-app', {
312311
replace: true,
313312
});

src/routes/Accounts.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ export const AccountsRoute: FC = () => {
186186
<button
187187
type="button"
188188
className={BUTTON_CLASS_NAME}
189-
title="Login with GitHub App"
189+
title="Login with GitHub"
190190
onClick={loginWithGitHub}
191191
>
192192
<MarkGithubIcon

src/routes/Login.test.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,26 @@ describe('routes/Login.tsx', () => {
4848
expect(mockNavigate).toHaveBeenNthCalledWith(1, '/', { replace: true });
4949
});
5050

51+
it('should login with github', () => {
52+
const mockLoginWithGitHubApp = jest.fn();
53+
render(
54+
<AppContext.Provider
55+
value={{
56+
loginWithGitHubApp: mockLoginWithGitHubApp,
57+
}}
58+
>
59+
<MemoryRouter>
60+
<LoginRoute />
61+
</MemoryRouter>
62+
,
63+
</AppContext.Provider>,
64+
);
65+
66+
fireEvent.click(screen.getByLabelText('Login with GitHub'));
67+
68+
expect(mockLoginWithGitHubApp).toHaveBeenCalled();
69+
});
70+
5171
it('should navigate to login with personal access token', () => {
5272
render(
5373
<MemoryRouter>

src/routes/__snapshots__/Accounts.test.tsx.snap

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)