Skip to content

Commit d1ef0bb

Browse files
update tests
1 parent 0ea0e62 commit d1ef0bb

File tree

3 files changed

+87
-35
lines changed

3 files changed

+87
-35
lines changed

static/app/actionCreators/prompts.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,10 @@ export function usePrompt({
204204
projectId,
205205
}),
206206
() => {
207-
const soozedTs = new Date().getTime() / 1000;
207+
const snoozedTs = new Date().getTime() / 1000;
208208
return {
209-
data: {snoozed_ts: soozedTs},
210-
features: {[feature]: {snoozed_ts: soozedTs}},
209+
data: {snoozed_ts: snoozedTs},
210+
features: {[feature]: {snoozed_ts: snoozedTs}},
211211
};
212212
}
213213
);

static/app/components/dropdownMenu/index.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('DropdownMenu', function () {
3030
// Open the mneu
3131
await userEvent.click(screen.getByRole('button', {name: 'This is a Menu'}));
3232

33-
// The mneu is open
33+
// The menu is open
3434
expect(screen.getByRole('menu')).toBeInTheDocument();
3535

3636
// There are two menu items
Lines changed: 83 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,103 @@
1-
import {render, screen} from 'sentry-test/reactTestingLibrary';
2-
3-
import {usePrompt as usePromptImport} from 'sentry/actionCreators/prompts';
1+
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
42

53
import ReplayInlineOnboardingPanel from './replayInlineOnboardingPanel';
64

7-
jest.mock('sentry/actionCreators/prompts');
8-
const usePrompt = jest.mocked(usePromptImport);
9-
105
describe('replayInlineOnboardingPanel', () => {
116
beforeEach(() => {
12-
jest.clearAllMocks();
13-
usePrompt.mockClear();
7+
MockApiClient.clearMockResponses();
8+
MockApiClient.addMockResponse({
9+
url: '/organizations/org-slug/prompts-activity/',
10+
body: {data: {dismissed_ts: null}},
11+
});
1412
});
1513

16-
it('should render if not dismissed', async () => {
17-
const dismissPrompt = jest.fn();
18-
const snoozePrompt = jest.fn();
19-
usePrompt.mockImplementation(() => {
20-
return {
21-
isPromptDismissed: false,
22-
isLoading: false,
23-
isError: false,
24-
snoozePrompt,
25-
dismissPrompt,
26-
};
14+
it('shows an onboarding banner that may be dismissed', async () => {
15+
MockApiClient.addMockResponse({
16+
url: '/organizations/org-slug/prompts-activity/',
17+
body: {data: {}},
2718
});
19+
const dismissMock = MockApiClient.addMockResponse({
20+
url: '/organizations/org-slug/prompts-activity/',
21+
method: 'PUT',
22+
});
23+
2824
render(<ReplayInlineOnboardingPanel platform="react" projectId="123" />);
2925
expect(
3026
await screen.findByText('Watch the errors and latency issues your users face')
3127
).toBeInTheDocument();
28+
29+
// Open the snooze or dismiss dropdown
30+
await userEvent.click(screen.getByTestId('icon-close'));
31+
expect(screen.getByText('Dismiss')).toBeInTheDocument();
32+
expect(screen.getByText('Snooze')).toBeInTheDocument();
33+
34+
// Click dismiss
35+
await userEvent.click(screen.getByRole('menuitemradio', {name: 'Dismiss'}));
36+
expect(dismissMock).toHaveBeenCalledWith(
37+
'/organizations/org-slug/prompts-activity/',
38+
expect.objectContaining({
39+
data: expect.objectContaining({
40+
feature: 'issue_replay_inline_onboarding',
41+
status: 'dismissed',
42+
}),
43+
})
44+
);
45+
expect(
46+
screen.queryByText('Watch the errors and latency issues your users face')
47+
).not.toBeInTheDocument();
3248
});
3349

34-
it('should not render if dismissed', async () => {
35-
const dismissPrompt = jest.fn();
36-
const snoozePrompt = jest.fn();
37-
usePrompt.mockImplementation(() => {
38-
return {
39-
isPromptDismissed: true,
40-
isLoading: false,
41-
isError: false,
42-
snoozePrompt,
43-
dismissPrompt,
44-
};
50+
it('shows an onboarding banner that may be snoozed', async () => {
51+
MockApiClient.addMockResponse({
52+
url: '/organizations/org-slug/prompts-activity/',
53+
body: {data: {}},
4554
});
55+
const snoozeMock = MockApiClient.addMockResponse({
56+
url: '/organizations/org-slug/prompts-activity/',
57+
method: 'PUT',
58+
});
59+
60+
render(<ReplayInlineOnboardingPanel platform="react" projectId="123" />);
61+
expect(
62+
await screen.findByText('Watch the errors and latency issues your users face')
63+
).toBeInTheDocument();
64+
65+
// Open the snooze or dismiss dropdown
66+
await userEvent.click(screen.getByTestId('icon-close'));
67+
expect(screen.getByText('Dismiss')).toBeInTheDocument();
68+
expect(screen.getByText('Snooze')).toBeInTheDocument();
69+
70+
// Click dismiss
71+
await userEvent.click(screen.getByRole('menuitemradio', {name: 'Snooze'}));
72+
expect(snoozeMock).toHaveBeenCalledWith(
73+
'/organizations/org-slug/prompts-activity/',
74+
expect.objectContaining({
75+
data: expect.objectContaining({
76+
feature: 'issue_replay_inline_onboarding',
77+
status: 'snoozed',
78+
}),
79+
})
80+
);
81+
expect(
82+
screen.queryByText('Watch the errors and latency issues your users face')
83+
).not.toBeInTheDocument();
84+
});
85+
86+
it('does not render if already dismissed', () => {
87+
MockApiClient.addMockResponse({
88+
url: '/organizations/org-slug/prompts-activity/',
89+
body: {
90+
data: {
91+
feature: 'issue_replay_inline_onboarding',
92+
status: 'dismissed',
93+
dismissed_ts: 3,
94+
},
95+
},
96+
});
97+
4698
render(<ReplayInlineOnboardingPanel platform="react" projectId="123" />);
4799
expect(
48-
await screen.queryByText('Watch the errors and latency issues your users face')
100+
screen.queryByText('Watch the errors and latency issues your users face')
49101
).not.toBeInTheDocument();
50102
});
51103
});

0 commit comments

Comments
 (0)