groupEventAttachments.spec.tsx 2.8 KB

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