groupEventAttachments.spec.tsx 3.0 KB

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