-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathProfileSettingsSelector.test.tsx
More file actions
98 lines (75 loc) · 2.61 KB
/
Copy pathProfileSettingsSelector.test.tsx
File metadata and controls
98 lines (75 loc) · 2.61 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { setInitialGlobalState } from '@/test/__mocks__/store';
import { MemoryRouter } from 'react-router-dom';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { useProfileStore } from '@/store';
import { ProfileSettingsSelector } from './ProfileSettingsSelector';
const mockGetRecordProfileId = jest.fn();
jest.mock('@/common/helpers/record.helper', () => ({
getRecordProfileId: () => mockGetRecordProfileId(),
}));
describe('ProfileSettingsSelector', () => {
const mockProfileId = 'profile-id';
const mockSetSelectedProfileSettingsId = jest.fn();
const renderComponent = () => {
setInitialGlobalState([
{
store: useProfileStore,
state: {
selectedProfileSettingsId: '32',
setSelectedProfileSettingsId: mockSetSelectedProfileSettingsId,
},
},
]);
const queryClient = new QueryClient({
defaultOptions: { queries: { retry: false } },
});
queryClient.setQueryData(
['profileSettingsMeta', mockProfileId],
[
{
id: 15,
name: 'fifteen',
},
{
id: 32,
name: 'thirty-two',
},
],
);
return render(
<QueryClientProvider client={queryClient}>
<MemoryRouter>
<ProfileSettingsSelector />
</MemoryRouter>
</QueryClientProvider>,
);
};
it('renders the component', () => {
renderComponent();
expect(screen.getByTestId('profile-settings-selector-button')).toBeInTheDocument();
});
it('clicking button shows menu', () => {
renderComponent();
fireEvent.click(screen.getByTestId('profile-settings-selector-button'));
expect(screen.getByTestId('profile-settings-selector-menu')).toBeInTheDocument();
});
it('profile setting currently in use is disabled', async () => {
mockGetRecordProfileId.mockReturnValue(mockProfileId);
renderComponent();
fireEvent.click(screen.getByTestId('profile-settings-selector-button'));
await waitFor(() => {
expect(screen.getByText('thirty-two')).toBeDisabled();
});
});
it('clicking a setting selects it', async () => {
mockGetRecordProfileId.mockReturnValue(mockProfileId);
renderComponent();
fireEvent.click(screen.getByTestId('profile-settings-selector-button'));
fireEvent.click(screen.getByText('fifteen'));
await waitFor(() => {
expect(screen.queryByTestId('profile-settings-selector-menu')).not.toBeInTheDocument();
expect(mockSetSelectedProfileSettingsId).toHaveBeenCalledWith('15');
});
});
});