groupEventAttachmentsDrawer.spec.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import {EventAttachmentFixture} from 'sentry-fixture/eventAttachment';
  2. import {ProjectFixture} from 'sentry-fixture/project';
  3. import {initializeOrg} from 'sentry-test/initializeOrg';
  4. import {
  5. render,
  6. renderGlobalModal,
  7. screen,
  8. userEvent,
  9. within,
  10. } from 'sentry-test/reactTestingLibrary';
  11. import GroupStore from 'sentry/stores/groupStore';
  12. import ModalStore from 'sentry/stores/modalStore';
  13. import ProjectsStore from 'sentry/stores/projectsStore';
  14. import type {Project} from 'sentry/types/project';
  15. import {GroupEventAttachmentsDrawer} from './groupEventAttachmentsDrawer';
  16. describe('GroupEventAttachmentsDrawer', function () {
  17. const groupId = 'group-id';
  18. const {organization, router} = initializeOrg({
  19. organization: {
  20. features: ['event-attachments'],
  21. orgRole: 'member',
  22. attachmentsRole: 'member',
  23. },
  24. });
  25. const {router: screenshotRouter} = initializeOrg({
  26. router: {
  27. params: {orgId: 'org-slug', groupId: 'group-id'},
  28. location: {query: {attachmentFilter: 'screenshot'}},
  29. },
  30. });
  31. let project: Project;
  32. let getAttachmentsMock: jest.Mock;
  33. beforeEach(function () {
  34. project = ProjectFixture({platform: 'apple-ios'});
  35. ProjectsStore.loadInitialData([project]);
  36. GroupStore.init();
  37. getAttachmentsMock = MockApiClient.addMockResponse({
  38. url: `/organizations/org-slug/issues/${groupId}/attachments/`,
  39. body: [EventAttachmentFixture()],
  40. });
  41. });
  42. afterEach(() => {
  43. MockApiClient.clearMockResponses();
  44. ModalStore.reset();
  45. });
  46. it('calls attachments api with screenshot filter', async function () {
  47. render(<GroupEventAttachmentsDrawer project={project} groupId={groupId} />, {
  48. router: screenshotRouter,
  49. organization,
  50. });
  51. expect(screen.getByRole('radio', {name: 'Screenshots'})).toBeInTheDocument();
  52. await userEvent.click(screen.getByRole('radio', {name: 'Screenshots'}));
  53. expect(getAttachmentsMock).toHaveBeenCalledWith(
  54. '/organizations/org-slug/issues/group-id/attachments/',
  55. expect.objectContaining({
  56. query: {screenshot: '1'},
  57. })
  58. );
  59. });
  60. it('does not render screenshots tab if not mobile platform', function () {
  61. project.platform = 'javascript';
  62. render(<GroupEventAttachmentsDrawer project={project} groupId={groupId} />, {
  63. router: screenshotRouter,
  64. organization,
  65. });
  66. expect(screen.queryByText('Screenshots')).not.toBeInTheDocument();
  67. });
  68. it('links event id to event detail', async function () {
  69. render(<GroupEventAttachmentsDrawer project={project} groupId={groupId} />, {
  70. router,
  71. organization,
  72. });
  73. expect(await screen.findByRole('link', {name: '12345678'})).toHaveAttribute(
  74. 'href',
  75. '/organizations/org-slug/issues/group-id/events/12345678901234567890123456789012/'
  76. );
  77. });
  78. it('links to the download URL', async function () {
  79. render(<GroupEventAttachmentsDrawer project={project} groupId={groupId} />, {
  80. router: screenshotRouter,
  81. organization,
  82. });
  83. expect(await screen.findByRole('button', {name: 'Download'})).toHaveAttribute(
  84. 'href',
  85. '/api/0/projects/org-slug/project-slug/events/12345678901234567890123456789012/attachments/1/?download=1'
  86. );
  87. });
  88. it('displays error message when request fails', async function () {
  89. MockApiClient.addMockResponse({
  90. url: '/organizations/org-slug/issues/group-id/attachments/',
  91. statusCode: 500,
  92. });
  93. render(<GroupEventAttachmentsDrawer project={project} groupId={groupId} />, {
  94. router,
  95. organization,
  96. });
  97. expect(await screen.findByText(/error loading/i)).toBeInTheDocument();
  98. });
  99. it('can delete an attachment', async function () {
  100. const deleteMock = MockApiClient.addMockResponse({
  101. url: '/projects/org-slug/project-slug/events/12345678901234567890123456789012/attachments/1/',
  102. method: 'DELETE',
  103. });
  104. render(<GroupEventAttachmentsDrawer project={project} groupId={groupId} />, {
  105. router,
  106. organization,
  107. });
  108. renderGlobalModal();
  109. expect(await screen.findByText('12345678')).toBeInTheDocument();
  110. expect(screen.getByRole('button', {name: 'Delete'})).toBeEnabled();
  111. await userEvent.click(screen.getByRole('button', {name: 'Delete'}));
  112. expect(
  113. await screen.findByText('Are you sure you wish to delete this file?')
  114. ).toBeInTheDocument();
  115. await userEvent.click(
  116. within(screen.getByRole('dialog')).getByRole('button', {name: 'Delete'})
  117. );
  118. expect(deleteMock).toHaveBeenCalled();
  119. expect(screen.queryByText('12345678')).not.toBeInTheDocument();
  120. });
  121. });