groupEventCarousel.spec.tsx 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import {browserHistory} from 'react-router';
  2. import {render, screen, userEvent, within} from 'sentry-test/reactTestingLibrary';
  3. import * as useMedia from 'sentry/utils/useMedia';
  4. import {GroupEventCarousel} from 'sentry/views/issueDetails/groupEventCarousel';
  5. describe('GroupEventCarousel', () => {
  6. const testEvent = TestStubs.Event({
  7. id: 'event-id',
  8. size: 7,
  9. dateCreated: '2019-03-20T00:00:00.000Z',
  10. errors: [],
  11. entries: [],
  12. tags: [{key: 'environment', value: 'dev'}],
  13. previousEventID: 'prev-event-id',
  14. nextEventID: 'next-event-id',
  15. });
  16. const defaultProps = {
  17. event: testEvent,
  18. group: TestStubs.Group({id: 'group-id'}),
  19. projectSlug: 'project-slug',
  20. };
  21. beforeEach(() => {
  22. jest.restoreAllMocks();
  23. Object.assign(navigator, {
  24. clipboard: {
  25. writeText: jest.fn().mockResolvedValue(''),
  26. },
  27. });
  28. window.open = jest.fn();
  29. });
  30. it('can use event dropdown to navigate events', async () => {
  31. // Because it isn't rendered on smaller screens
  32. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  33. render(<GroupEventCarousel {...defaultProps} />, {
  34. organization: TestStubs.Organization({
  35. features: [
  36. 'issue-details-most-helpful-event',
  37. 'issue-details-most-helpful-event-ui',
  38. ],
  39. }),
  40. });
  41. await userEvent.click(screen.getByRole('button', {name: /recommended event/i}));
  42. await userEvent.click(screen.getByRole('option', {name: /oldest event/i}));
  43. expect(browserHistory.push).toHaveBeenCalledWith({
  44. pathname: '/organizations/org-slug/issues/group-id/events/oldest/',
  45. query: {referrer: 'oldest-event'},
  46. });
  47. await userEvent.click(screen.getByRole('button', {name: /oldest event/i}));
  48. await userEvent.click(screen.getByRole('option', {name: /latest event/i}));
  49. expect(browserHistory.push).toHaveBeenCalledWith({
  50. pathname: '/organizations/org-slug/issues/group-id/events/oldest/',
  51. query: {referrer: 'oldest-event'},
  52. });
  53. await userEvent.click(screen.getByRole('button', {name: /latest event/i}));
  54. await userEvent.click(screen.getByRole('option', {name: /recommended event/i}));
  55. expect(browserHistory.push).toHaveBeenCalledWith({
  56. pathname: '/organizations/org-slug/issues/group-id/events/recommended/',
  57. query: {referrer: 'recommended-event'},
  58. });
  59. });
  60. it('can navigate next/previous events', () => {
  61. render(<GroupEventCarousel {...defaultProps} />);
  62. expect(screen.getByLabelText(/Previous Event/)).toHaveAttribute(
  63. 'href',
  64. `/organizations/org-slug/issues/group-id/events/prev-event-id/?referrer=previous-event`
  65. );
  66. expect(screen.getByLabelText(/Next Event/)).toHaveAttribute(
  67. 'href',
  68. `/organizations/org-slug/issues/group-id/events/next-event-id/?referrer=next-event`
  69. );
  70. });
  71. it('can copy event ID', async () => {
  72. render(<GroupEventCarousel {...defaultProps} />);
  73. await userEvent.click(screen.getByText(testEvent.id));
  74. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(testEvent.id);
  75. });
  76. it('can copy event link', async () => {
  77. render(<GroupEventCarousel {...defaultProps} />);
  78. await userEvent.click(screen.getByRole('button', {name: /event actions/i}));
  79. await userEvent.click(screen.getByRole('menuitemradio', {name: /copy event link/i}));
  80. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(
  81. `http://localhost/organizations/org-slug/issues/group-id/events/event-id/`
  82. );
  83. });
  84. it('links to full event details when org has discover', async () => {
  85. render(<GroupEventCarousel {...defaultProps} />, {
  86. organization: TestStubs.Organization({features: ['discover-basic']}),
  87. });
  88. await userEvent.click(screen.getByRole('button', {name: /event actions/i}));
  89. expect(
  90. within(screen.getByRole('menuitemradio', {name: /full event details/i})).getByRole(
  91. 'link'
  92. )
  93. ).toHaveAttribute('href', `/organizations/org-slug/discover/project-slug:event-id/`);
  94. });
  95. it('can open event JSON', async () => {
  96. render(<GroupEventCarousel {...defaultProps} />);
  97. await userEvent.click(screen.getByRole('button', {name: /event actions/i}));
  98. await userEvent.click(screen.getByRole('menuitemradio', {name: 'JSON (7 B)'}));
  99. expect(window.open).toHaveBeenCalledWith(
  100. `/api/0/projects/org-slug/project-slug/events/event-id/json/`
  101. );
  102. });
  103. });