|
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'; |
4 | 2 |
|
5 | 3 | import ReplayInlineOnboardingPanel from './replayInlineOnboardingPanel';
|
6 | 4 |
|
7 |
| -jest.mock('sentry/actionCreators/prompts'); |
8 |
| -const usePrompt = jest.mocked(usePromptImport); |
9 |
| - |
10 | 5 | describe('replayInlineOnboardingPanel', () => {
|
11 | 6 | 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 | + }); |
14 | 12 | });
|
15 | 13 |
|
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: {}}, |
27 | 18 | });
|
| 19 | + const dismissMock = MockApiClient.addMockResponse({ |
| 20 | + url: '/organizations/org-slug/prompts-activity/', |
| 21 | + method: 'PUT', |
| 22 | + }); |
| 23 | + |
28 | 24 | render(<ReplayInlineOnboardingPanel platform="react" projectId="123" />);
|
29 | 25 | expect(
|
30 | 26 | await screen.findByText('Watch the errors and latency issues your users face')
|
31 | 27 | ).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(); |
32 | 48 | });
|
33 | 49 |
|
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: {}}, |
45 | 54 | });
|
| 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 | + |
46 | 98 | render(<ReplayInlineOnboardingPanel platform="react" projectId="123" />);
|
47 | 99 | 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') |
49 | 101 | ).not.toBeInTheDocument();
|
50 | 102 | });
|
51 | 103 | });
|
0 commit comments