eventNavigation.spec.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. import {EventFixture} from 'sentry-fixture/event';
  2. import {GroupFixture} from 'sentry-fixture/group';
  3. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  4. import {browserHistory} from 'sentry/utils/browserHistory';
  5. import * as useMedia from 'sentry/utils/useMedia';
  6. import {SectionKey, useEventDetails} from 'sentry/views/issueDetails/streamline/context';
  7. import {EventNavigation} from 'sentry/views/issueDetails/streamline/eventNavigation';
  8. jest.mock('sentry/views/issueDetails/streamline/context');
  9. describe('EventNavigation', () => {
  10. const testEvent = EventFixture({
  11. id: 'event-id',
  12. size: 7,
  13. dateCreated: '2019-03-20T00:00:00.000Z',
  14. errors: [],
  15. entries: [],
  16. tags: [
  17. {key: 'environment', value: 'dev'},
  18. {key: 'replayId', value: 'replay-id'},
  19. ],
  20. previousEventID: 'prev-event-id',
  21. nextEventID: 'next-event-id',
  22. });
  23. const defaultProps = {
  24. event: testEvent,
  25. group: GroupFixture({id: 'group-id'}),
  26. };
  27. beforeEach(() => {
  28. jest.resetAllMocks();
  29. jest.mocked(useEventDetails).mockReturnValue({
  30. sectionData: {
  31. highlights: {key: SectionKey.HIGHLIGHTS},
  32. tags: {key: SectionKey.TAGS},
  33. replay: {key: SectionKey.REPLAY},
  34. },
  35. dispatch: jest.fn(),
  36. });
  37. Object.assign(navigator, {
  38. clipboard: {writeText: jest.fn().mockResolvedValue('')},
  39. });
  40. window.open = jest.fn();
  41. MockApiClient.addMockResponse({
  42. url: `/projects/org-slug/project-slug/events/event-id/actionable-items/`,
  43. body: {
  44. errors: [],
  45. },
  46. method: 'GET',
  47. });
  48. });
  49. describe('recommended event tabs', () => {
  50. it('can navigate to the oldest event', async () => {
  51. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  52. render(<EventNavigation {...defaultProps} />);
  53. await userEvent.click(screen.getByRole('tab', {name: 'First'}));
  54. expect(browserHistory.push).toHaveBeenCalledWith({
  55. pathname: '/organizations/org-slug/issues/group-id/events/oldest/',
  56. query: {referrer: 'oldest-event'},
  57. });
  58. });
  59. it('can navigate to the latest event', async () => {
  60. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  61. render(<EventNavigation {...defaultProps} />);
  62. await userEvent.click(screen.getByRole('tab', {name: 'Last'}));
  63. expect(browserHistory.push).toHaveBeenCalledWith({
  64. pathname: '/organizations/org-slug/issues/group-id/events/latest/',
  65. query: {referrer: 'latest-event'},
  66. });
  67. });
  68. it('can navigate to the recommended event', async () => {
  69. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  70. render(<EventNavigation {...defaultProps} />, {
  71. router: {
  72. params: {eventId: 'latest'},
  73. },
  74. });
  75. await userEvent.click(screen.getByRole('tab', {name: 'Recommended'}));
  76. expect(browserHistory.push).toHaveBeenCalledWith({
  77. pathname: '/organizations/org-slug/issues/group-id/events/recommended/',
  78. query: {referrer: 'recommended-event'},
  79. });
  80. });
  81. });
  82. it('can navigate next/previous events', () => {
  83. render(<EventNavigation {...defaultProps} />);
  84. expect(screen.getByLabelText(/Previous Event/)).toHaveAttribute(
  85. 'href',
  86. `/organizations/org-slug/issues/group-id/events/prev-event-id/?referrer=previous-event`
  87. );
  88. expect(screen.getByLabelText(/Next Event/)).toHaveAttribute(
  89. 'href',
  90. `/organizations/org-slug/issues/group-id/events/next-event-id/?referrer=next-event`
  91. );
  92. });
  93. it('does not show jump to sections by default', () => {
  94. jest.mocked(useEventDetails).mockReturnValue({
  95. sectionData: {},
  96. dispatch: jest.fn(),
  97. });
  98. render(<EventNavigation {...defaultProps} />);
  99. expect(screen.queryByText('Jump To:')).not.toBeInTheDocument();
  100. expect(screen.queryByText('Replay')).not.toBeInTheDocument();
  101. expect(screen.queryByText('Tags')).not.toBeInTheDocument();
  102. expect(screen.queryByText('Event Highlights')).not.toBeInTheDocument();
  103. });
  104. it('does show jump to sections when the sections render', () => {
  105. render(<EventNavigation {...defaultProps} />);
  106. expect(screen.getByText('Jump to:')).toBeInTheDocument();
  107. expect(screen.getByText('Event Highlights')).toBeInTheDocument();
  108. expect(screen.getByText('Replay')).toBeInTheDocument();
  109. expect(screen.getByText('Tags')).toBeInTheDocument();
  110. });
  111. it('can copy event ID', async () => {
  112. render(<EventNavigation {...defaultProps} />);
  113. await userEvent.click(screen.getByText(testEvent.id));
  114. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(testEvent.id);
  115. });
  116. it('shows event actions dropdown', async () => {
  117. render(<EventNavigation {...defaultProps} />);
  118. await userEvent.click(screen.getByRole('button', {name: 'Event actions'}));
  119. await userEvent.click(screen.getByRole('menuitemradio', {name: 'Copy Event ID'}));
  120. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(testEvent.id);
  121. await userEvent.click(screen.getByRole('button', {name: 'Event actions'}));
  122. await userEvent.click(screen.getByRole('menuitemradio', {name: 'Copy Event Link'}));
  123. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(
  124. `http://localhost/organizations/org-slug/issues/group-id/events/event-id/`
  125. );
  126. await userEvent.click(screen.getByRole('button', {name: 'Event actions'}));
  127. await userEvent.click(screen.getByRole('menuitemradio', {name: 'View JSON'}));
  128. expect(window.open).toHaveBeenCalledWith(
  129. `https://us.sentry.io/api/0/projects/org-slug/project-slug/events/event-id/json/`
  130. );
  131. });
  132. it('shows processing issue button if there is an event error', async () => {
  133. MockApiClient.addMockResponse({
  134. url: `/projects/org-slug/project-slug/events/event-id/actionable-items/`,
  135. body: {
  136. errors: [
  137. {
  138. type: 'invalid_data',
  139. data: {
  140. name: 'logentry',
  141. },
  142. message: 'no message present',
  143. },
  144. ],
  145. },
  146. method: 'GET',
  147. });
  148. render(<EventNavigation {...defaultProps} />);
  149. expect(
  150. await screen.findByRole('button', {name: 'Processing Error'})
  151. ).toBeInTheDocument();
  152. });
  153. });