-
Notifications
You must be signed in to change notification settings - Fork 295
Expand file tree
/
Copy pathProfileButton.spec.tsx
More file actions
61 lines (51 loc) · 1.6 KB
/
ProfileButton.spec.tsx
File metadata and controls
61 lines (51 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import React from 'react';
import { QueryClient } from '@tanstack/react-query';
import type { RenderResult } from '@testing-library/react';
import { waitFor, render, screen, act } from '@testing-library/react';
import ProfileButton from './ProfileButton';
import defaultUser from '../../../__tests__/fixture/loggedUser';
import { TestBootProvider } from '../../../__tests__/helpers/boot';
const logout = jest.fn();
const renderComponent = (): RenderResult => {
const client = new QueryClient();
return render(
<TestBootProvider
client={client}
auth={{
user: defaultUser,
shouldShowLogin: false,
showLogin: jest.fn(),
logout,
updateUser: jest.fn(),
tokenRefreshed: true,
getRedirectUri: jest.fn(),
closeLogin: jest.fn(),
trackingId: '21',
loginState: null,
}}
>
<ProfileButton />
</TestBootProvider>,
);
};
it('should show settings option that opens modal', async () => {
renderComponent();
const profileBtn = await screen.findByLabelText('Profile settings');
await act(async () => {
profileBtn.click();
});
const settingsButton = await screen.findByRole('button', {
name: 'Settings',
});
expect(settingsButton).toBeInTheDocument();
});
it('should click the logout button and logout', async () => {
renderComponent();
const profileBtn = await screen.findByLabelText('Profile settings');
await act(async () => {
profileBtn.click();
});
const logoutBtn = await screen.findByText('Logout');
logoutBtn.click();
await waitFor(async () => expect(logout).toBeCalled());
});