groupEventAttachments.spec.tsx 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import {EventAttachmentFixture} from 'sentry-fixture/eventAttachment';
  2. import {OrganizationFixture} from 'sentry-fixture/organization';
  3. import {ProjectFixture} from 'sentry-fixture/project';
  4. import {initializeOrg} from 'sentry-test/initializeOrg';
  5. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  6. import {openModal} from 'sentry/actionCreators/modal';
  7. import GroupStore from 'sentry/stores/groupStore';
  8. import ProjectsStore from 'sentry/stores/projectsStore';
  9. import GroupEventAttachments, {MAX_SCREENSHOTS_PER_PAGE} from './groupEventAttachments';
  10. jest.mock('sentry/actionCreators/modal');
  11. describe('GroupEventAttachments > Screenshots', function () {
  12. const {organization, router} = initializeOrg({
  13. organization: OrganizationFixture(),
  14. router: {
  15. params: {orgId: 'org-slug', groupId: 'group-id'},
  16. location: {query: {types: 'event.screenshot'}},
  17. },
  18. } as Parameters<typeof initializeOrg>[0]);
  19. let project;
  20. let getAttachmentsMock;
  21. beforeEach(function () {
  22. project = ProjectFixture({platform: 'apple-ios'});
  23. ProjectsStore.loadInitialData([project]);
  24. GroupStore.init();
  25. getAttachmentsMock = MockApiClient.addMockResponse({
  26. url: '/organizations/org-slug/issues/group-id/attachments/',
  27. body: [EventAttachmentFixture()],
  28. });
  29. });
  30. afterEach(() => {});
  31. function renderGroupEventAttachments() {
  32. return render(<GroupEventAttachments project={project} />, {
  33. router,
  34. organization,
  35. });
  36. }
  37. it('calls attachments api with screenshot filter', async function () {
  38. renderGroupEventAttachments();
  39. expect(screen.getByRole('radio', {name: 'Screenshots'})).toBeInTheDocument();
  40. await userEvent.click(screen.getByRole('radio', {name: 'Screenshots'}));
  41. expect(getAttachmentsMock).toHaveBeenCalledWith(
  42. '/organizations/org-slug/issues/group-id/attachments/',
  43. expect.objectContaining({
  44. query: {per_page: MAX_SCREENSHOTS_PER_PAGE, screenshot: 1, types: undefined},
  45. })
  46. );
  47. });
  48. it('does not render screenshots tab if not mobile platform', function () {
  49. project.platform = 'javascript';
  50. renderGroupEventAttachments();
  51. expect(screen.queryByText('Screenshots')).not.toBeInTheDocument();
  52. });
  53. it('calls opens modal when clicking on panel body', async function () {
  54. renderGroupEventAttachments();
  55. await userEvent.click(await screen.findByTestId('screenshot-1'));
  56. expect(openModal).toHaveBeenCalled();
  57. });
  58. it('links event id to event detail', async function () {
  59. renderGroupEventAttachments();
  60. expect(
  61. (await screen.findByText('12345678901234567890123456789012')).closest('a')
  62. ).toHaveAttribute(
  63. 'href',
  64. '/organizations/org-slug/issues/group-id/events/12345678901234567890123456789012/'
  65. );
  66. });
  67. it('links to the download URL', async function () {
  68. renderGroupEventAttachments();
  69. await userEvent.click(await screen.findByLabelText('Actions'));
  70. expect(screen.getByText('Download').closest('a')).toHaveAttribute(
  71. 'href',
  72. '/api/0/projects/org-slug/project-slug/events/12345678901234567890123456789012/attachments/1/?download=1'
  73. );
  74. });
  75. it('displays an error message when request fails', async function () {
  76. MockApiClient.addMockResponse({
  77. url: '/organizations/org-slug/issues/group-id/attachments/',
  78. statusCode: 500,
  79. });
  80. renderGroupEventAttachments();
  81. expect(await screen.findByText(/error loading/i)).toBeInTheDocument();
  82. });
  83. });