-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathnewOnboardingStatus.spec.tsx
114 lines (94 loc) · 3.47 KB
/
newOnboardingStatus.spec.tsx
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import {OrganizationFixture} from 'sentry-fixture/organization';
import {UserFixture} from 'sentry-fixture/user';
import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
import {NewOnboardingStatus} from 'sentry/components/sidebar/newOnboardingStatus';
import {SidebarPanelKey} from 'sentry/components/sidebar/types';
import {OnboardingTaskKey} from 'sentry/types/onboarding';
import type {Organization} from 'sentry/types/organization';
function renderMockRequests(organization: Organization) {
const getOnboardingTasksMock = MockApiClient.addMockResponse({
url: `/organizations/${organization.slug}/onboarding-tasks/`,
method: 'GET',
body: {
onboardingTasks: organization.onboardingTasks,
},
});
return {getOnboardingTasksMock};
}
describe('Onboarding Status', function () {
it('panel is collapsed and has pending tasks to be seen', async function () {
const organization = OrganizationFixture({
features: ['onboarding'],
onboardingTasks: [
{
task: OnboardingTaskKey.FIRST_PROJECT,
status: 'complete',
user: UserFixture(),
completionSeen: undefined,
dateCompleted: undefined,
},
],
});
const {getOnboardingTasksMock} = renderMockRequests(organization);
const handleShowPanel = jest.fn();
render(
<NewOnboardingStatus
currentPanel=""
onShowPanel={handleShowPanel}
hidePanel={jest.fn()}
collapsed
orientation="left"
/>,
{
organization,
}
);
expect(screen.getByText('1 completed task')).toBeInTheDocument();
expect(screen.getByTestId('pending-seen-indicator')).toBeInTheDocument();
// By hovering over the button, we should refetch the data
await userEvent.hover(screen.getByRole('button', {name: 'Onboarding'}));
await waitFor(() => expect(getOnboardingTasksMock).toHaveBeenCalled());
// Open the panel
await userEvent.click(screen.getByRole('button', {name: 'Onboarding'}));
await waitFor(() => expect(getOnboardingTasksMock).toHaveBeenCalled());
expect(handleShowPanel).toHaveBeenCalled();
});
it('panel is expanded and has no pending tasks to be seen', async function () {
const organization = OrganizationFixture({
features: ['onboarding'],
onboardingTasks: [
{
task: OnboardingTaskKey.FIRST_PROJECT,
status: 'complete',
user: UserFixture(),
completionSeen: '2024-12-16T14:52:01.385227Z',
dateCompleted: '2024-12-13T09:35:05.010028Z',
},
],
});
const {getOnboardingTasksMock} = renderMockRequests(organization);
const handleHidePanel = jest.fn();
render(
<NewOnboardingStatus
currentPanel={SidebarPanelKey.ONBOARDING_WIZARD}
onShowPanel={jest.fn()}
hidePanel={handleHidePanel}
collapsed={false}
orientation="left"
/>,
{
organization,
}
);
expect(screen.getByText('1 completed task')).toBeInTheDocument();
// Do not show the pending indicator
expect(screen.queryByTestId('pending-seen-indicator')).not.toBeInTheDocument();
// Shows the panel
expect(screen.getByText('Quick Setup')).toBeInTheDocument();
// Triggers a fetch request
expect(getOnboardingTasksMock).toHaveBeenCalled();
// Hide Panel
await userEvent.click(screen.getByLabelText('Close Panel'));
await waitFor(() => expect(handleHidePanel).toHaveBeenCalled());
});
});