eventNavigation.spec.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 EventNavigation from 'sentry/views/issueDetails/eventNavigation';
  7. describe('EventNavigation', () => {
  8. const testEvent = EventFixture({
  9. id: 'event-id',
  10. size: 7,
  11. dateCreated: '2019-03-20T00:00:00.000Z',
  12. errors: [],
  13. entries: [],
  14. tags: [
  15. {key: 'environment', value: 'dev'},
  16. {key: 'replayId', value: 'replay-id'},
  17. ],
  18. previousEventID: 'prev-event-id',
  19. nextEventID: 'next-event-id',
  20. });
  21. const defaultProps = {
  22. event: testEvent,
  23. group: GroupFixture({id: 'group-id'}),
  24. projectSlug: 'project-slug',
  25. };
  26. beforeEach(() => {
  27. Object.assign(navigator, {
  28. clipboard: {writeText: jest.fn().mockResolvedValue('')},
  29. });
  30. window.open = jest.fn();
  31. });
  32. describe('recommended event tabs', () => {
  33. it('can navigate to the oldest event', async () => {
  34. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  35. render(<EventNavigation {...defaultProps} />);
  36. await userEvent.click(screen.getByRole('tab', {name: 'First Event'}));
  37. expect(browserHistory.push).toHaveBeenCalledWith({
  38. pathname: '/organizations/org-slug/issues/group-id/events/oldest/',
  39. query: {referrer: 'oldest-event'},
  40. });
  41. });
  42. it('can navigate to the latest event', async () => {
  43. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  44. render(<EventNavigation {...defaultProps} />);
  45. await userEvent.click(screen.getByRole('tab', {name: 'Last Event'}));
  46. expect(browserHistory.push).toHaveBeenCalledWith({
  47. pathname: '/organizations/org-slug/issues/group-id/events/latest/',
  48. query: {referrer: 'latest-event'},
  49. });
  50. });
  51. it('can navigate to the recommended event', async () => {
  52. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  53. render(<EventNavigation {...defaultProps} />, {
  54. router: {
  55. params: {eventId: 'latest'},
  56. },
  57. });
  58. await userEvent.click(screen.getByRole('tab', {name: 'Recommended Event'}));
  59. expect(browserHistory.push).toHaveBeenCalledWith({
  60. pathname: '/organizations/org-slug/issues/group-id/events/recommended/',
  61. query: {referrer: 'recommended-event'},
  62. });
  63. });
  64. });
  65. it('can navigate next/previous events', () => {
  66. render(<EventNavigation {...defaultProps} />);
  67. expect(screen.getByLabelText(/Previous Event/)).toHaveAttribute(
  68. 'href',
  69. `/organizations/org-slug/issues/group-id/events/prev-event-id/?referrer=previous-event`
  70. );
  71. expect(screen.getByLabelText(/Next Event/)).toHaveAttribute(
  72. 'href',
  73. `/organizations/org-slug/issues/group-id/events/next-event-id/?referrer=next-event`
  74. );
  75. });
  76. it('shows jump to sections', async () => {
  77. render(<EventNavigation {...defaultProps} />);
  78. expect(await screen.findByText('Replay')).toBeInTheDocument();
  79. expect(await screen.findByText('Tags')).toBeInTheDocument();
  80. expect(await screen.findByText('Event Highlights')).toBeInTheDocument();
  81. });
  82. it('can copy event ID', async () => {
  83. render(<EventNavigation {...defaultProps} />);
  84. await userEvent.click(screen.getByText(testEvent.id));
  85. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(testEvent.id);
  86. });
  87. it('shows event actions dropdown', async () => {
  88. render(<EventNavigation {...defaultProps} />);
  89. await userEvent.click(screen.getByRole('button', {name: 'Event actions'}));
  90. await userEvent.click(screen.getByRole('menuitemradio', {name: 'Copy Event ID'}));
  91. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(testEvent.id);
  92. await userEvent.click(screen.getByRole('button', {name: 'Event actions'}));
  93. await userEvent.click(screen.getByRole('menuitemradio', {name: 'Copy Event Link'}));
  94. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(
  95. `http://localhost/organizations/org-slug/issues/group-id/events/event-id/`
  96. );
  97. await userEvent.click(screen.getByRole('button', {name: 'Event actions'}));
  98. await userEvent.click(screen.getByRole('menuitemradio', {name: 'View JSON'}));
  99. expect(window.open).toHaveBeenCalledWith(
  100. `https://us.sentry.io/api/0/projects/org-slug/project-slug/events/event-id/json/`
  101. );
  102. });
  103. });