eventNavigation.spec.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import {EventFixture} from 'sentry-fixture/event';
  2. import {EventAttachmentFixture} from 'sentry-fixture/eventAttachment';
  3. import {GroupFixture} from 'sentry-fixture/group';
  4. import {LocationFixture} from 'sentry-fixture/locationFixture';
  5. import {RouterFixture} from 'sentry-fixture/routerFixture';
  6. import {initializeOrg} from 'sentry-test/initializeOrg';
  7. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  8. import {SectionKey, useIssueDetails} from 'sentry/views/issueDetails/streamline/context';
  9. import {Tab, TabPaths} from 'sentry/views/issueDetails/types';
  10. import {IssueEventNavigation} from './eventNavigation';
  11. jest.mock('sentry/views/issueDetails/streamline/context');
  12. describe('EventNavigation', () => {
  13. const {organization} = initializeOrg();
  14. const group = GroupFixture({id: 'group-id'});
  15. const testEvent = EventFixture({
  16. id: 'event-id',
  17. size: 7,
  18. dateCreated: '2019-03-20T00:00:00.000Z',
  19. errors: [],
  20. entries: [],
  21. tags: [
  22. {key: 'environment', value: 'dev'},
  23. {key: 'replayId', value: 'replay-id'},
  24. ],
  25. previousEventID: 'prev-event-id',
  26. nextEventID: 'next-event-id',
  27. });
  28. const defaultProps: React.ComponentProps<typeof IssueEventNavigation> = {
  29. event: testEvent,
  30. group,
  31. };
  32. beforeEach(() => {
  33. jest.resetAllMocks();
  34. jest.mocked(useIssueDetails).mockReturnValue({
  35. sectionData: {
  36. highlights: {key: SectionKey.HIGHLIGHTS},
  37. tags: {key: SectionKey.TAGS},
  38. replay: {key: SectionKey.REPLAY},
  39. },
  40. eventCount: 0,
  41. isSidebarOpen: true,
  42. navScrollMargin: 0,
  43. dispatch: jest.fn(),
  44. });
  45. MockApiClient.addMockResponse({
  46. url: `/organizations/${organization.slug}/issues/${group.id}/tags/`,
  47. body: [],
  48. });
  49. MockApiClient.addMockResponse({
  50. url: `/organizations/${organization.slug}/issues/${group.id}/attachments/`,
  51. body: [],
  52. });
  53. MockApiClient.addMockResponse({
  54. url: '/organizations/org-slug/replay-count/',
  55. body: {},
  56. });
  57. });
  58. describe('all events buttons', () => {
  59. it('renders the all events controls', () => {
  60. const allEventsRouter = RouterFixture({
  61. params: {groupId: group.id},
  62. routes: [{path: TabPaths[Tab.EVENTS]}],
  63. location: LocationFixture({
  64. pathname: `/organizations/${organization.slug}/issues/${group.id}/events/`,
  65. }),
  66. });
  67. render(<IssueEventNavigation {...defaultProps} />, {router: allEventsRouter});
  68. const discoverButton = screen.getByLabelText('Open in Discover');
  69. expect(discoverButton).toBeInTheDocument();
  70. expect(discoverButton).toHaveAttribute(
  71. 'href',
  72. expect.stringContaining(`/organizations/${organization.slug}/discover/results/`)
  73. );
  74. const closeButton = screen.getByRole('button', {name: 'Return to event details'});
  75. expect(closeButton).toBeInTheDocument();
  76. expect(closeButton).toHaveAttribute(
  77. 'href',
  78. expect.stringContaining(`/organizations/${organization.slug}/issues/${group.id}/`)
  79. );
  80. });
  81. });
  82. describe('counts', () => {
  83. it('renders default counts', async () => {
  84. render(<IssueEventNavigation {...defaultProps} />);
  85. await userEvent.click(screen.getByRole('button', {name: 'Select issue content'}));
  86. expect(
  87. await screen.findByRole('menuitemradio', {name: 'Attachments 0'})
  88. ).toBeInTheDocument();
  89. expect(screen.getByRole('menuitemradio', {name: 'Events 0'})).toBeInTheDocument();
  90. expect(screen.getByRole('menuitemradio', {name: 'Replays 0'})).toBeInTheDocument();
  91. expect(screen.getByRole('menuitemradio', {name: 'Feedback 0'})).toBeInTheDocument();
  92. });
  93. it('renders 1 attachment', async () => {
  94. MockApiClient.addMockResponse({
  95. url: `/organizations/${organization.slug}/issues/${group.id}/attachments/`,
  96. body: [EventAttachmentFixture()],
  97. });
  98. render(<IssueEventNavigation {...defaultProps} />);
  99. await userEvent.click(screen.getByRole('button', {name: 'Select issue content'}));
  100. expect(
  101. await screen.findByRole('menuitemradio', {name: 'Attachments 1'})
  102. ).toBeInTheDocument();
  103. });
  104. it('renders 50+ attachments', async () => {
  105. MockApiClient.addMockResponse({
  106. url: `/organizations/${organization.slug}/issues/${group.id}/attachments/`,
  107. body: [EventAttachmentFixture()],
  108. headers: {
  109. // Assumes there is more than 50 attachments if there is a next page
  110. Link: '<https://sentry.io>; rel="previous"; results="false"; cursor="0:0:1", <https://sentry.io>; rel="next"; results="true"; cursor="0:20:0"',
  111. },
  112. });
  113. render(<IssueEventNavigation {...defaultProps} />);
  114. await userEvent.click(screen.getByRole('button', {name: 'Select issue content'}));
  115. expect(
  116. await screen.findByRole('menuitemradio', {name: 'Attachments 50+'})
  117. ).toBeInTheDocument();
  118. });
  119. });
  120. });