groupEventCarousel.spec.tsx 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import {browserHistory} from 'react-router';
  2. import {ConfigFixture} from 'sentry-fixture/config';
  3. import {EventFixture} from 'sentry-fixture/event';
  4. import {GroupFixture} from 'sentry-fixture/group';
  5. import {OrganizationFixture} from 'sentry-fixture/organization';
  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 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 = UserFixture({
  40. options: {
  41. ...UserFixture().options,
  42. defaultIssueEvent: 'recommended',
  43. },
  44. });
  45. const latestUser = UserFixture({
  46. options: {
  47. ...UserFixture().options,
  48. defaultIssueEvent: 'latest',
  49. },
  50. });
  51. const oldestUser = UserFixture({
  52. options: {
  53. ...UserFixture().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.findByRole('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(
  101. await screen.findByRole('button', {name: 'Recommended'})
  102. ).toBeInTheDocument();
  103. });
  104. it('if user default is latest, it will show it as default', async () => {
  105. ConfigStore.loadInitialData(ConfigFixture({user: latestUser}));
  106. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  107. render(<GroupEventCarousel {...singleEventProps} />);
  108. expect(await screen.findByRole('button', {name: 'Latest'})).toBeInTheDocument();
  109. });
  110. it('if user default is oldest, it will show it as default', async () => {
  111. ConfigStore.loadInitialData(ConfigFixture({user: oldestUser}));
  112. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  113. render(<GroupEventCarousel {...singleEventProps} />);
  114. expect(await screen.findByRole('button', {name: 'Oldest'})).toBeInTheDocument();
  115. });
  116. });
  117. it('can navigate next/previous events', () => {
  118. render(<GroupEventCarousel {...defaultProps} />);
  119. expect(screen.getByLabelText(/Previous Event/)).toHaveAttribute(
  120. 'href',
  121. `/organizations/org-slug/issues/group-id/events/prev-event-id/?referrer=previous-event`
  122. );
  123. expect(screen.getByLabelText(/Next Event/)).toHaveAttribute(
  124. 'href',
  125. `/organizations/org-slug/issues/group-id/events/next-event-id/?referrer=next-event`
  126. );
  127. });
  128. it('can copy event ID', async () => {
  129. render(<GroupEventCarousel {...defaultProps} />);
  130. await userEvent.click(screen.getByText(testEvent.id));
  131. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(testEvent.id);
  132. });
  133. it('can copy event link', async () => {
  134. render(<GroupEventCarousel {...defaultProps} />);
  135. await userEvent.click(screen.getByRole('button', {name: /event actions/i}));
  136. await userEvent.click(screen.getByRole('menuitemradio', {name: /copy event link/i}));
  137. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(
  138. `http://localhost/organizations/org-slug/issues/group-id/events/event-id/`
  139. );
  140. });
  141. it('links to full event details when org has discover', async () => {
  142. render(<GroupEventCarousel {...defaultProps} />, {
  143. organization: OrganizationFixture({features: ['discover-basic']}),
  144. });
  145. await userEvent.click(screen.getByRole('button', {name: /event actions/i}));
  146. expect(
  147. within(screen.getByRole('menuitemradio', {name: /full event details/i})).getByRole(
  148. 'link'
  149. )
  150. ).toHaveAttribute('href', `/organizations/org-slug/discover/project-slug:event-id/`);
  151. });
  152. it('can open event JSON', async () => {
  153. render(<GroupEventCarousel {...defaultProps} />);
  154. await userEvent.click(screen.getByRole('button', {name: /event actions/i}));
  155. await userEvent.click(screen.getByRole('menuitemradio', {name: 'JSON (7.0 B)'}));
  156. expect(window.open).toHaveBeenCalledWith(
  157. `https://us.sentry.io/api/0/projects/org-slug/project-slug/events/event-id/json/`
  158. );
  159. });
  160. });