attachmentsBadge.spec.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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(
  29. await screen.findByRole('button', {name: "View this issue's attachments"})
  30. ).toBeInTheDocument();
  31. });
  32. it('renders 50+ when there is a next page', async () => {
  33. MockApiClient.addMockResponse({
  34. url: `/organizations/${organization.slug}/issues/${group.id}/attachments/`,
  35. body: [EventAttachmentFixture()],
  36. headers: {
  37. // Assumes there is more than 50 attachments if there is a next page
  38. Link: '<https://sentry.io>; rel="previous"; results="false"; cursor="0:0:1", <https://sentry.io>; rel="next"; results="true"; cursor="0:20:0"',
  39. },
  40. });
  41. render(<AttachmentsBadge group={group} />);
  42. const button = await screen.findByRole('button', {
  43. name: "View this issue's attachments",
  44. });
  45. expect(button).toBeInTheDocument();
  46. expect(button).toHaveAttribute('href', expect.stringContaining('/attachments/'));
  47. });
  48. });