groupEventCarousel.spec.tsx 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. import {browserHistory} from 'react-router';
  2. import {Config as ConfigFixture} from 'sentry-fixture/config';
  3. import {Event as EventFixture} from 'sentry-fixture/event';
  4. import {Group as GroupFixture} from 'sentry-fixture/group';
  5. import {Organization} from 'sentry-fixture/organization';
  6. import {User} from 'sentry-fixture/user';
  7. import {render, screen, userEvent, within} from 'sentry-test/reactTestingLibrary';
  8. import ConfigStore from 'sentry/stores/configStore';
  9. import * as useMedia from 'sentry/utils/useMedia';
  10. import {GroupEventCarousel} from 'sentry/views/issueDetails/groupEventCarousel';
  11. describe('GroupEventCarousel', () => {
  12. const testEvent = EventFixture({
  13. id: 'event-id',
  14. size: 7,
  15. dateCreated: '2019-03-20T00:00:00.000Z',
  16. errors: [],
  17. entries: [],
  18. tags: [{key: 'environment', value: 'dev'}],
  19. previousEventID: 'prev-event-id',
  20. nextEventID: 'next-event-id',
  21. });
  22. const singleTestEvent = {...testEvent, previousEventID: null, nextEventID: null};
  23. const defaultProps = {
  24. event: testEvent,
  25. group: GroupFixture({id: 'group-id'}),
  26. projectSlug: 'project-slug',
  27. };
  28. const singleEventProps = {...defaultProps, event: singleTestEvent};
  29. beforeEach(() => {
  30. jest.restoreAllMocks();
  31. Object.assign(navigator, {
  32. clipboard: {
  33. writeText: jest.fn().mockResolvedValue(''),
  34. },
  35. });
  36. window.open = jest.fn();
  37. });
  38. describe('recommended event ui', () => {
  39. const recommendedUser = User({
  40. options: {
  41. ...User().options,
  42. defaultIssueEvent: 'recommended',
  43. },
  44. });
  45. const latestUser = User({
  46. options: {
  47. ...User().options,
  48. defaultIssueEvent: 'latest',
  49. },
  50. });
  51. const oldestUser = User({
  52. options: {
  53. ...User().options,
  54. defaultIssueEvent: 'oldest',
  55. },
  56. });
  57. it('can navigate to the oldest event', async () => {
  58. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  59. render(<GroupEventCarousel {...defaultProps} />);
  60. await userEvent.click(screen.getByRole('button', {name: /recommended/i}));
  61. await userEvent.click(screen.getByRole('option', {name: /oldest/i}));
  62. expect(browserHistory.push).toHaveBeenCalledWith({
  63. pathname: '/organizations/org-slug/issues/group-id/events/oldest/',
  64. query: {referrer: 'oldest-event'},
  65. });
  66. });
  67. it('can navigate to the latest event', async () => {
  68. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  69. render(<GroupEventCarousel {...defaultProps} />);
  70. await userEvent.click(screen.getByRole('button', {name: /recommended/i}));
  71. await userEvent.click(screen.getByRole('option', {name: /latest/i}));
  72. expect(browserHistory.push).toHaveBeenCalledWith({
  73. pathname: '/organizations/org-slug/issues/group-id/events/latest/',
  74. query: {referrer: 'latest-event'},
  75. });
  76. });
  77. it('can navigate to the recommended event', async () => {
  78. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  79. render(<GroupEventCarousel {...defaultProps} />, {
  80. router: {
  81. params: {eventId: 'latest'},
  82. },
  83. });
  84. await userEvent.click(screen.getByRole('button', {name: /latest/i}));
  85. await userEvent.click(screen.getByRole('option', {name: /recommended/i}));
  86. expect(browserHistory.push).toHaveBeenCalledWith({
  87. pathname: '/organizations/org-slug/issues/group-id/events/recommended/',
  88. query: {referrer: 'recommended-event'},
  89. });
  90. });
  91. it('will disable the dropdown if there is only one event', async () => {
  92. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  93. render(<GroupEventCarousel {...singleEventProps} />);
  94. expect(await screen.getByRole('button', {name: 'Recommended'})).toBeDisabled();
  95. });
  96. it('if user default is recommended, it will show it as default', async () => {
  97. ConfigStore.loadInitialData(ConfigFixture({user: recommendedUser}));
  98. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  99. render(<GroupEventCarousel {...singleEventProps} />);
  100. expect(await screen.getByText('Recommended')).toBeInTheDocument();
  101. });
  102. it('if user default is latest, it will show it as default', async () => {
  103. ConfigStore.loadInitialData(ConfigFixture({user: latestUser}));
  104. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  105. render(<GroupEventCarousel {...singleEventProps} />);
  106. expect(await screen.getByText('Latest')).toBeInTheDocument();
  107. });
  108. it('if user default is oldest, it will show it as default', async () => {
  109. ConfigStore.loadInitialData(ConfigFixture({user: oldestUser}));
  110. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  111. render(<GroupEventCarousel {...singleEventProps} />);
  112. expect(await screen.getByText('Oldest')).toBeInTheDocument();
  113. });
  114. });
  115. it('can navigate next/previous events', () => {
  116. render(<GroupEventCarousel {...defaultProps} />);
  117. expect(screen.getByLabelText(/Previous Event/)).toHaveAttribute(
  118. 'href',
  119. `/organizations/org-slug/issues/group-id/events/prev-event-id/?referrer=previous-event`
  120. );
  121. expect(screen.getByLabelText(/Next Event/)).toHaveAttribute(
  122. 'href',
  123. `/organizations/org-slug/issues/group-id/events/next-event-id/?referrer=next-event`
  124. );
  125. });
  126. it('can copy event ID', async () => {
  127. render(<GroupEventCarousel {...defaultProps} />);
  128. await userEvent.click(screen.getByText(testEvent.id));
  129. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(testEvent.id);
  130. });
  131. it('can copy event link', async () => {
  132. render(<GroupEventCarousel {...defaultProps} />);
  133. await userEvent.click(screen.getByRole('button', {name: /event actions/i}));
  134. await userEvent.click(screen.getByRole('menuitemradio', {name: /copy event link/i}));
  135. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(
  136. `http://localhost/organizations/org-slug/issues/group-id/events/event-id/`
  137. );
  138. });
  139. it('links to full event details when org has discover', async () => {
  140. render(<GroupEventCarousel {...defaultProps} />, {
  141. organization: Organization({features: ['discover-basic']}),
  142. });
  143. await userEvent.click(screen.getByRole('button', {name: /event actions/i}));
  144. expect(
  145. within(screen.getByRole('menuitemradio', {name: /full event details/i})).getByRole(
  146. 'link'
  147. )
  148. ).toHaveAttribute('href', `/organizations/org-slug/discover/project-slug:event-id/`);
  149. });
  150. it('can open event JSON', async () => {
  151. render(<GroupEventCarousel {...defaultProps} />);
  152. await userEvent.click(screen.getByRole('button', {name: /event actions/i}));
  153. await userEvent.click(screen.getByRole('menuitemradio', {name: 'JSON (7.0 B)'}));
  154. expect(window.open).toHaveBeenCalledWith(
  155. `https://us.sentry.io/api/0/projects/org-slug/project-slug/events/event-id/json/`
  156. );
  157. });
  158. });