groupEventCarousel.spec.tsx 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. describe('recommended event ui', () => {
  31. const orgWithRecommendedEvent = TestStubs.Organization({
  32. features: [
  33. 'issue-details-most-helpful-event',
  34. 'issue-details-most-helpful-event-ui',
  35. ],
  36. });
  37. it('can navigate to the oldest event', async () => {
  38. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  39. render(<GroupEventCarousel {...defaultProps} />, {
  40. organization: orgWithRecommendedEvent,
  41. });
  42. await userEvent.click(screen.getByRole('button', {name: /recommended/i}));
  43. await userEvent.click(screen.getByRole('option', {name: /oldest/i}));
  44. expect(browserHistory.push).toHaveBeenCalledWith({
  45. pathname: '/organizations/org-slug/issues/group-id/events/oldest/',
  46. query: {referrer: 'oldest-event'},
  47. });
  48. });
  49. it('can navigate to the latest event', async () => {
  50. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  51. render(<GroupEventCarousel {...defaultProps} />, {
  52. organization: orgWithRecommendedEvent,
  53. });
  54. await userEvent.click(screen.getByRole('button', {name: /recommended/i}));
  55. await userEvent.click(screen.getByRole('option', {name: /latest/i}));
  56. expect(browserHistory.push).toHaveBeenCalledWith({
  57. pathname: '/organizations/org-slug/issues/group-id/events/latest/',
  58. query: {referrer: 'latest-event'},
  59. });
  60. });
  61. it('can navigate to the recommended event', async () => {
  62. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  63. render(<GroupEventCarousel {...defaultProps} />, {
  64. organization: orgWithRecommendedEvent,
  65. router: {
  66. params: {eventId: 'latest'},
  67. },
  68. });
  69. await userEvent.click(screen.getByRole('button', {name: /latest/i}));
  70. await userEvent.click(screen.getByRole('option', {name: /recommended/i}));
  71. expect(browserHistory.push).toHaveBeenCalledWith({
  72. pathname: '/organizations/org-slug/issues/group-id/events/recommended/',
  73. query: {referrer: 'recommended-event'},
  74. });
  75. });
  76. });
  77. it('can navigate next/previous events', () => {
  78. render(<GroupEventCarousel {...defaultProps} />);
  79. expect(screen.getByLabelText(/Previous Event/)).toHaveAttribute(
  80. 'href',
  81. `/organizations/org-slug/issues/group-id/events/prev-event-id/?referrer=previous-event`
  82. );
  83. expect(screen.getByLabelText(/Next Event/)).toHaveAttribute(
  84. 'href',
  85. `/organizations/org-slug/issues/group-id/events/next-event-id/?referrer=next-event`
  86. );
  87. });
  88. it('can copy event ID', async () => {
  89. render(<GroupEventCarousel {...defaultProps} />);
  90. await userEvent.click(screen.getByText(testEvent.id));
  91. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(testEvent.id);
  92. });
  93. it('can copy event link', async () => {
  94. render(<GroupEventCarousel {...defaultProps} />);
  95. await userEvent.click(screen.getByRole('button', {name: /event actions/i}));
  96. await userEvent.click(screen.getByRole('menuitemradio', {name: /copy event link/i}));
  97. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(
  98. `http://localhost/organizations/org-slug/issues/group-id/events/event-id/`
  99. );
  100. });
  101. it('links to full event details when org has discover', async () => {
  102. render(<GroupEventCarousel {...defaultProps} />, {
  103. organization: TestStubs.Organization({features: ['discover-basic']}),
  104. });
  105. await userEvent.click(screen.getByRole('button', {name: /event actions/i}));
  106. expect(
  107. within(screen.getByRole('menuitemradio', {name: /full event details/i})).getByRole(
  108. 'link'
  109. )
  110. ).toHaveAttribute('href', `/organizations/org-slug/discover/project-slug:event-id/`);
  111. });
  112. it('can open event JSON', async () => {
  113. render(<GroupEventCarousel {...defaultProps} />);
  114. await userEvent.click(screen.getByRole('button', {name: /event actions/i}));
  115. await userEvent.click(screen.getByRole('menuitemradio', {name: 'JSON (7 B)'}));
  116. expect(window.open).toHaveBeenCalledWith(
  117. `/api/0/projects/org-slug/project-slug/events/event-id/json/`
  118. );
  119. });
  120. });