groupEventCarousel.spec.tsx 7.1 KB

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