attachmentsBadge.spec.tsx 2.2 KB

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