eventTitle.spec.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 {SectionKey, useEventDetails} from 'sentry/views/issueDetails/streamline/context';
  5. import {EventTitle} from './eventTitle';
  6. jest.mock('sentry/views/issueDetails/streamline/context');
  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: React.ComponentProps<typeof EventTitle> = {
  22. event: testEvent,
  23. group: GroupFixture({id: 'group-id'}),
  24. };
  25. beforeEach(() => {
  26. jest.resetAllMocks();
  27. jest.mocked(useEventDetails).mockReturnValue({
  28. sectionData: {
  29. highlights: {key: SectionKey.HIGHLIGHTS},
  30. tags: {key: SectionKey.TAGS},
  31. replay: {key: SectionKey.REPLAY},
  32. },
  33. dispatch: jest.fn(),
  34. });
  35. Object.assign(navigator, {
  36. clipboard: {writeText: jest.fn().mockResolvedValue('')},
  37. });
  38. window.open = jest.fn();
  39. MockApiClient.addMockResponse({
  40. url: `/projects/org-slug/project-slug/events/event-id/actionable-items/`,
  41. body: {
  42. errors: [],
  43. },
  44. method: 'GET',
  45. });
  46. });
  47. it('does not show jump to sections by default', () => {
  48. jest.mocked(useEventDetails).mockReturnValue({
  49. sectionData: {},
  50. dispatch: jest.fn(),
  51. });
  52. render(<EventTitle {...defaultProps} />);
  53. expect(screen.queryByText('Jump To:')).not.toBeInTheDocument();
  54. expect(screen.queryByText('Replay')).not.toBeInTheDocument();
  55. expect(screen.queryByText('Tags')).not.toBeInTheDocument();
  56. expect(screen.queryByText('Highlights')).not.toBeInTheDocument();
  57. });
  58. it('does show jump to sections when the sections render', () => {
  59. render(<EventTitle {...defaultProps} />);
  60. expect(screen.getByText('Jump to:')).toBeInTheDocument();
  61. expect(screen.getByText('Highlights')).toBeInTheDocument();
  62. expect(screen.getByText('Replay')).toBeInTheDocument();
  63. expect(screen.getByText('Tags')).toBeInTheDocument();
  64. });
  65. it('can copy event ID', async () => {
  66. render(<EventTitle {...defaultProps} />);
  67. await userEvent.click(screen.getByRole('button', {name: 'Event actions'}));
  68. await userEvent.click(screen.getByRole('menuitemradio', {name: 'Copy Event ID'}));
  69. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(testEvent.id);
  70. });
  71. it('shows event actions dropdown', async () => {
  72. render(<EventTitle {...defaultProps} />);
  73. await userEvent.click(screen.getByRole('button', {name: 'Event actions'}));
  74. await userEvent.click(screen.getByRole('menuitemradio', {name: 'Copy Event ID'}));
  75. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(testEvent.id);
  76. await userEvent.click(screen.getByRole('button', {name: 'Event actions'}));
  77. await userEvent.click(screen.getByRole('menuitemradio', {name: 'Copy Event Link'}));
  78. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(
  79. `http://localhost/organizations/org-slug/issues/group-id/events/event-id/`
  80. );
  81. await userEvent.click(screen.getByRole('button', {name: 'Event actions'}));
  82. await userEvent.click(screen.getByRole('menuitemradio', {name: 'View JSON'}));
  83. expect(window.open).toHaveBeenCalledWith(
  84. `https://us.sentry.io/api/0/projects/org-slug/project-slug/events/event-id/json/`
  85. );
  86. });
  87. it('shows processing issue button if there is an event error', async () => {
  88. MockApiClient.addMockResponse({
  89. url: `/projects/org-slug/project-slug/events/event-id/actionable-items/`,
  90. body: {
  91. errors: [
  92. {
  93. type: 'invalid_data',
  94. data: {
  95. name: 'logentry',
  96. },
  97. message: 'no message present',
  98. },
  99. ],
  100. },
  101. method: 'GET',
  102. });
  103. render(<EventTitle {...defaultProps} />);
  104. expect(
  105. await screen.findByRole('button', {name: 'Processing Error'})
  106. ).toBeInTheDocument();
  107. });
  108. });