|
| 1 | +import {GroupFixture} from 'sentry-fixture/group'; |
| 2 | +import {OrganizationFixture} from 'sentry-fixture/organization'; |
| 3 | +import {ProjectFixture} from 'sentry-fixture/project'; |
| 4 | +import {TeamFixture} from 'sentry-fixture/team'; |
| 5 | +import {UserFixture} from 'sentry-fixture/user'; |
| 6 | + |
| 7 | +import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary'; |
| 8 | + |
| 9 | +import {ConfigStore} from 'sentry/stores/configStore'; |
| 10 | +import {ProjectsStore} from 'sentry/stores/projectsStore'; |
| 11 | +import {IssueCategory} from 'sentry/types/group'; |
| 12 | +import {IssuePreviewDrawer} from 'sentry/views/issueDetails/issuePreview/issuePreviewDrawer'; |
| 13 | + |
| 14 | +const organization = OrganizationFixture({id: '4660', slug: 'org'}); |
| 15 | + |
| 16 | +const project = ProjectFixture({ |
| 17 | + id: '2448', |
| 18 | + name: 'project name', |
| 19 | + slug: 'project', |
| 20 | + teams: [TeamFixture({id: '3', slug: 'frontend', name: 'Frontend'})], |
| 21 | +}); |
| 22 | + |
| 23 | +const group = GroupFixture({ |
| 24 | + id: '1337', |
| 25 | + issueCategory: IssueCategory.ERROR, |
| 26 | + project, |
| 27 | +}); |
| 28 | + |
| 29 | +describe('IssuePreviewDrawer', () => { |
| 30 | + beforeEach(() => { |
| 31 | + ConfigStore.init(); |
| 32 | + ConfigStore.set('user', UserFixture()); |
| 33 | + ProjectsStore.reset(); |
| 34 | + ProjectsStore.loadInitialData([project]); |
| 35 | + |
| 36 | + MockApiClient.addMockResponse({ |
| 37 | + url: `/organizations/${organization.slug}/issues/${group.id}/`, |
| 38 | + body: group, |
| 39 | + }); |
| 40 | + MockApiClient.addMockResponse({ |
| 41 | + url: `/organizations/${organization.slug}/users/`, |
| 42 | + body: [], |
| 43 | + }); |
| 44 | + MockApiClient.addMockResponse({ |
| 45 | + url: `/organizations/${organization.slug}/issues/${group.id}/autofix/setup/`, |
| 46 | + body: { |
| 47 | + billing: null, |
| 48 | + integration: {ok: false, reason: null}, |
| 49 | + seerReposLinked: false, |
| 50 | + githubWriteIntegration: null, |
| 51 | + }, |
| 52 | + }); |
| 53 | + MockApiClient.addMockResponse({ |
| 54 | + url: `/organizations/${organization.slug}/integrations/coding-agents/`, |
| 55 | + body: {integrations: []}, |
| 56 | + }); |
| 57 | + MockApiClient.addMockResponse({ |
| 58 | + url: `/organizations/${organization.slug}/replay-count/`, |
| 59 | + body: {}, |
| 60 | + }); |
| 61 | + MockApiClient.addMockResponse({ |
| 62 | + url: `/organizations/${organization.slug}/issues/${group.id}/attachments/`, |
| 63 | + body: [], |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | + afterEach(() => { |
| 68 | + MockApiClient.clearMockResponses(); |
| 69 | + jest.clearAllMocks(); |
| 70 | + }); |
| 71 | + |
| 72 | + it('resolves the issue', async () => { |
| 73 | + const updateRequest = MockApiClient.addMockResponse({ |
| 74 | + url: `/projects/${organization.slug}/${project.slug}/issues/`, |
| 75 | + method: 'PUT', |
| 76 | + body: {...group, status: 'resolved'}, |
| 77 | + }); |
| 78 | + |
| 79 | + render(<IssuePreviewDrawer groupId={group.id} />, {organization}); |
| 80 | + |
| 81 | + const resolveButton = await screen.findByRole('button', {name: 'Resolve'}); |
| 82 | + |
| 83 | + // The drawer refetches the group after the update; return the resolved group. |
| 84 | + MockApiClient.addMockResponse({ |
| 85 | + url: `/organizations/${organization.slug}/issues/${group.id}/`, |
| 86 | + body: {...group, status: 'resolved'}, |
| 87 | + }); |
| 88 | + |
| 89 | + await userEvent.click(resolveButton); |
| 90 | + |
| 91 | + await waitFor(() => { |
| 92 | + expect(updateRequest).toHaveBeenCalledWith( |
| 93 | + `/projects/${organization.slug}/${project.slug}/issues/`, |
| 94 | + expect.objectContaining({ |
| 95 | + data: {status: 'resolved', statusDetails: {}, substatus: null}, |
| 96 | + }) |
| 97 | + ); |
| 98 | + }); |
| 99 | + |
| 100 | + expect(await screen.findAllByText('Resolved')).not.toHaveLength(0); |
| 101 | + }); |
| 102 | +}); |
0 commit comments