groupEventCarousel.spec.tsx 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import {render, screen, userEvent, within} from 'sentry-test/reactTestingLibrary';
  2. import {GroupEventCarousel} from 'sentry/views/issueDetails/groupEventCarousel';
  3. describe('GroupEventCarousel', () => {
  4. const testEvent = TestStubs.Event({
  5. id: 'event-id',
  6. size: 7,
  7. dateCreated: '2019-03-20T00:00:00.000Z',
  8. errors: [],
  9. entries: [],
  10. tags: [{key: 'environment', value: 'dev'}],
  11. previousEventID: 'prev-event-id',
  12. nextEventID: 'next-event-id',
  13. });
  14. const defaultProps = {
  15. event: testEvent,
  16. group: TestStubs.Group({id: 'group-id'}),
  17. projectSlug: 'project-slug',
  18. };
  19. beforeEach(() => {
  20. jest.clearAllMocks();
  21. Object.assign(navigator, {
  22. clipboard: {
  23. writeText: jest.fn().mockResolvedValue(''),
  24. },
  25. });
  26. window.open = jest.fn();
  27. });
  28. it('can navigate next/previous events', () => {
  29. render(<GroupEventCarousel {...defaultProps} />);
  30. expect(screen.getByLabelText(/First Event/)).toHaveAttribute(
  31. 'href',
  32. `/organizations/org-slug/issues/group-id/events/oldest/?referrer=oldest-event`
  33. );
  34. expect(screen.getByLabelText(/Previous Event/)).toHaveAttribute(
  35. 'href',
  36. `/organizations/org-slug/issues/group-id/events/prev-event-id/?referrer=previous-event`
  37. );
  38. expect(screen.getByLabelText(/Next Event/)).toHaveAttribute(
  39. 'href',
  40. `/organizations/org-slug/issues/group-id/events/next-event-id/?referrer=next-event`
  41. );
  42. expect(screen.getByLabelText(/Latest Event/)).toHaveAttribute(
  43. 'href',
  44. `/organizations/org-slug/issues/group-id/events/latest/?referrer=latest-event`
  45. );
  46. });
  47. it('can copy event ID', async () => {
  48. render(<GroupEventCarousel {...defaultProps} />);
  49. await userEvent.click(screen.getByText(testEvent.id));
  50. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(testEvent.id);
  51. });
  52. it('can copy event link', async () => {
  53. render(<GroupEventCarousel {...defaultProps} />);
  54. await userEvent.click(screen.getByRole('button', {name: /event actions/i}));
  55. await userEvent.click(screen.getByRole('menuitemradio', {name: /copy event link/i}));
  56. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(
  57. `http://localhost/organizations/org-slug/issues/group-id/events/event-id/`
  58. );
  59. });
  60. it('links to full event details when org has discover', async () => {
  61. render(<GroupEventCarousel {...defaultProps} />, {
  62. organization: TestStubs.Organization({features: ['discover-basic']}),
  63. });
  64. await userEvent.click(screen.getByRole('button', {name: /event actions/i}));
  65. expect(
  66. within(screen.getByRole('menuitemradio', {name: /full event details/i})).getByRole(
  67. 'link'
  68. )
  69. ).toHaveAttribute('href', `/organizations/org-slug/discover/project-slug:event-id/`);
  70. });
  71. it('can open event JSON', async () => {
  72. render(<GroupEventCarousel {...defaultProps} />);
  73. await userEvent.click(screen.getByRole('button', {name: /event actions/i}));
  74. await userEvent.click(screen.getByRole('menuitemradio', {name: 'JSON (7 B)'}));
  75. expect(window.open).toHaveBeenCalledWith(
  76. `/api/0/projects/org-slug/project-slug/events/event-id/json/`
  77. );
  78. });
  79. });