groupEventCarousel.spec.tsx 6.6 KB

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