attachmentsBadge.spec.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {EventAttachmentFixture} from 'sentry-fixture/eventAttachment';
  2. import {GroupFixture} from 'sentry-fixture/group';
  3. import {OrganizationFixture} from 'sentry-fixture/organization';
  4. import {act, render, screen} from 'sentry-test/reactTestingLibrary';
  5. import {AttachmentsBadge} from './attachmentsBadge';
  6. describe('AttachmentsBadge', () => {
  7. const organization = OrganizationFixture();
  8. const group = GroupFixture();
  9. beforeEach(() => {
  10. MockApiClient.clearMockResponses();
  11. });
  12. it('does not show up if there are no attachments', async () => {
  13. MockApiClient.addMockResponse({
  14. url: `/organizations/${organization.slug}/issues/${group.id}/attachments/`,
  15. body: [],
  16. });
  17. const {container} = render(<AttachmentsBadge group={group} />);
  18. // Wait for requests to finish
  19. await act(tick);
  20. expect(container).toBeEmptyDOMElement();
  21. });
  22. it('renders 1 when there is only 1 attachment', async () => {
  23. MockApiClient.addMockResponse({
  24. url: `/organizations/${organization.slug}/issues/${group.id}/attachments/`,
  25. body: [EventAttachmentFixture()],
  26. });
  27. render(<AttachmentsBadge group={group} />);
  28. expect(await screen.findByRole('button', {name: '1 Attachment'})).toBeInTheDocument();
  29. });
  30. it('renders 50+ when there is a next page', async () => {
  31. MockApiClient.addMockResponse({
  32. url: `/organizations/${organization.slug}/issues/${group.id}/attachments/`,
  33. body: [EventAttachmentFixture()],
  34. headers: {
  35. // Assumes there is more than 50 attachments if there is a next page
  36. Link: '<https://sentry.io>; rel="previous"; results="false"; cursor="0:0:1", <https://sentry.io>; rel="next"; results="true"; cursor="0:20:0"',
  37. },
  38. });
  39. render(<AttachmentsBadge group={group} />);
  40. const button = await screen.findByRole('button', {name: '50+ Attachments'});
  41. expect(button).toBeInTheDocument();
  42. expect(button).toHaveAttribute('href', expect.stringContaining('/attachments/'));
  43. });
  44. });