groupEventCarousel.spec.tsx 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. import {ConfigFixture} from 'sentry-fixture/config';
  2. import {EventFixture} from 'sentry-fixture/event';
  3. import {GroupFixture} from 'sentry-fixture/group';
  4. import {OrganizationFixture} from 'sentry-fixture/organization';
  5. import {RouterFixture} from 'sentry-fixture/routerFixture';
  6. import {UserFixture} 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 router = RouterFixture();
  13. const testEvent = EventFixture({
  14. id: 'event-id',
  15. size: 7,
  16. dateCreated: '2019-03-20T00:00:00.000Z',
  17. errors: [],
  18. entries: [],
  19. tags: [{key: 'environment', value: 'dev'}],
  20. previousEventID: 'prev-event-id',
  21. nextEventID: 'next-event-id',
  22. });
  23. const singleTestEvent = {...testEvent, previousEventID: null, nextEventID: null};
  24. const defaultProps = {
  25. event: testEvent,
  26. group: GroupFixture({id: 'group-id'}),
  27. projectSlug: 'project-slug',
  28. };
  29. const singleEventProps = {...defaultProps, event: singleTestEvent};
  30. beforeEach(() => {
  31. jest.restoreAllMocks();
  32. Object.assign(navigator, {
  33. clipboard: {
  34. writeText: jest.fn().mockResolvedValue(''),
  35. },
  36. });
  37. window.open = jest.fn();
  38. });
  39. describe('recommended event ui', () => {
  40. const recommendedUser = UserFixture({
  41. options: {
  42. ...UserFixture().options,
  43. defaultIssueEvent: 'recommended',
  44. },
  45. });
  46. const latestUser = UserFixture({
  47. options: {
  48. ...UserFixture().options,
  49. defaultIssueEvent: 'latest',
  50. },
  51. });
  52. const oldestUser = UserFixture({
  53. options: {
  54. ...UserFixture().options,
  55. defaultIssueEvent: 'oldest',
  56. },
  57. });
  58. it('can navigate to the oldest event', async () => {
  59. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  60. render(<GroupEventCarousel {...defaultProps} />, {router});
  61. await userEvent.click(screen.getByRole('button', {name: /recommended/i}));
  62. await userEvent.click(screen.getByRole('option', {name: /oldest/i}));
  63. expect(router.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} />, {router});
  71. await userEvent.click(screen.getByRole('button', {name: /recommended/i}));
  72. await userEvent.click(screen.getByRole('option', {name: /latest/i}));
  73. expect(router.push).toHaveBeenCalledWith({
  74. pathname: '/organizations/org-slug/issues/group-id/events/latest/',
  75. query: {referrer: 'latest-event'},
  76. });
  77. });
  78. it('can navigate to the recommended event', async () => {
  79. const newRouter = RouterFixture({params: {eventId: 'latest'}});
  80. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  81. render(<GroupEventCarousel {...defaultProps} />, {router: newRouter});
  82. await userEvent.click(screen.getByRole('button', {name: /latest/i}));
  83. await userEvent.click(screen.getByRole('option', {name: /recommended/i}));
  84. expect(newRouter.push).toHaveBeenCalledWith({
  85. pathname: '/organizations/org-slug/issues/group-id/events/recommended/',
  86. query: {referrer: 'recommended-event'},
  87. });
  88. });
  89. it('will disable the dropdown if there is only one event', async () => {
  90. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  91. render(<GroupEventCarousel {...singleEventProps} />);
  92. expect(await screen.findByRole('button', {name: 'Recommended'})).toBeDisabled();
  93. });
  94. it('if user default is recommended, it will show it as default', async () => {
  95. ConfigStore.loadInitialData(ConfigFixture({user: recommendedUser}));
  96. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  97. render(<GroupEventCarousel {...singleEventProps} />);
  98. expect(
  99. await screen.findByRole('button', {name: 'Recommended'})
  100. ).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.findByRole('button', {name: '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.findByRole('button', {name: '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: OrganizationFixture({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. });