groupEventAttachments.spec.tsx 3.0 KB

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