groupEventCarousel.spec.tsx 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. import {browserHistory} from 'react-router';
  2. import {Organization} from 'sentry-fixture/organization';
  3. import {render, screen, userEvent, within} from 'sentry-test/reactTestingLibrary';
  4. import ConfigStore from 'sentry/stores/configStore';
  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 recommendedUser = TestStubs.User({
  36. options: {
  37. defaultIssueEvent: 'recommended',
  38. },
  39. });
  40. const latestUser = TestStubs.User({
  41. options: {
  42. defaultIssueEvent: 'latest',
  43. },
  44. });
  45. const oldestUser = TestStubs.User({
  46. options: {
  47. defaultIssueEvent: 'oldest',
  48. },
  49. });
  50. it('can navigate to the oldest event', async () => {
  51. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  52. render(<GroupEventCarousel {...defaultProps} />);
  53. await userEvent.click(screen.getByRole('button', {name: /recommended/i}));
  54. await userEvent.click(screen.getByRole('option', {name: /oldest/i}));
  55. expect(browserHistory.push).toHaveBeenCalledWith({
  56. pathname: '/organizations/org-slug/issues/group-id/events/oldest/',
  57. query: {referrer: 'oldest-event'},
  58. });
  59. });
  60. it('can navigate to the latest event', async () => {
  61. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  62. render(<GroupEventCarousel {...defaultProps} />);
  63. await userEvent.click(screen.getByRole('button', {name: /recommended/i}));
  64. await userEvent.click(screen.getByRole('option', {name: /latest/i}));
  65. expect(browserHistory.push).toHaveBeenCalledWith({
  66. pathname: '/organizations/org-slug/issues/group-id/events/latest/',
  67. query: {referrer: 'latest-event'},
  68. });
  69. });
  70. it('can navigate to the recommended event', async () => {
  71. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  72. render(<GroupEventCarousel {...defaultProps} />, {
  73. router: {
  74. params: {eventId: 'latest'},
  75. },
  76. });
  77. await userEvent.click(screen.getByRole('button', {name: /latest/i}));
  78. await userEvent.click(screen.getByRole('option', {name: /recommended/i}));
  79. expect(browserHistory.push).toHaveBeenCalledWith({
  80. pathname: '/organizations/org-slug/issues/group-id/events/recommended/',
  81. query: {referrer: 'recommended-event'},
  82. });
  83. });
  84. it('will disable the dropdown if there is only one event', async () => {
  85. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  86. render(<GroupEventCarousel {...singleEventProps} />);
  87. expect(await screen.getByRole('button', {name: 'Recommended'})).toBeDisabled();
  88. });
  89. it('if user default is recommended, it will show it as default', async () => {
  90. ConfigStore.loadInitialData(TestStubs.Config({user: recommendedUser}));
  91. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  92. render(<GroupEventCarousel {...singleEventProps} />);
  93. expect(await screen.getByText('Recommended')).toBeInTheDocument();
  94. });
  95. it('if user default is latest, it will show it as default', async () => {
  96. ConfigStore.loadInitialData(TestStubs.Config({user: latestUser}));
  97. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  98. render(<GroupEventCarousel {...singleEventProps} />);
  99. expect(await screen.getByText('Latest')).toBeInTheDocument();
  100. });
  101. it('if user default is oldest, it will show it as default', async () => {
  102. ConfigStore.loadInitialData(TestStubs.Config({user: oldestUser}));
  103. jest.spyOn(useMedia, 'default').mockReturnValue(true);
  104. render(<GroupEventCarousel {...singleEventProps} />);
  105. expect(await screen.getByText('Oldest')).toBeInTheDocument();
  106. });
  107. });
  108. it('can navigate next/previous events', () => {
  109. render(<GroupEventCarousel {...defaultProps} />);
  110. expect(screen.getByLabelText(/Previous Event/)).toHaveAttribute(
  111. 'href',
  112. `/organizations/org-slug/issues/group-id/events/prev-event-id/?referrer=previous-event`
  113. );
  114. expect(screen.getByLabelText(/Next Event/)).toHaveAttribute(
  115. 'href',
  116. `/organizations/org-slug/issues/group-id/events/next-event-id/?referrer=next-event`
  117. );
  118. });
  119. it('can copy event ID', async () => {
  120. render(<GroupEventCarousel {...defaultProps} />);
  121. await userEvent.click(screen.getByText(testEvent.id));
  122. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(testEvent.id);
  123. });
  124. it('can copy event link', async () => {
  125. render(<GroupEventCarousel {...defaultProps} />);
  126. await userEvent.click(screen.getByRole('button', {name: /event actions/i}));
  127. await userEvent.click(screen.getByRole('menuitemradio', {name: /copy event link/i}));
  128. expect(navigator.clipboard.writeText).toHaveBeenCalledWith(
  129. `http://localhost/organizations/org-slug/issues/group-id/events/event-id/`
  130. );
  131. });
  132. it('links to full event details when org has discover', async () => {
  133. render(<GroupEventCarousel {...defaultProps} />, {
  134. organization: Organization({features: ['discover-basic']}),
  135. });
  136. await userEvent.click(screen.getByRole('button', {name: /event actions/i}));
  137. expect(
  138. within(screen.getByRole('menuitemradio', {name: /full event details/i})).getByRole(
  139. 'link'
  140. )
  141. ).toHaveAttribute('href', `/organizations/org-slug/discover/project-slug:event-id/`);
  142. });
  143. it('can open event JSON', async () => {
  144. render(<GroupEventCarousel {...defaultProps} />);
  145. await userEvent.click(screen.getByRole('button', {name: /event actions/i}));
  146. await userEvent.click(screen.getByRole('menuitemradio', {name: 'JSON (7 B)'}));
  147. expect(window.open).toHaveBeenCalledWith(
  148. `/api/0/projects/org-slug/project-slug/events/event-id/json/`
  149. );
  150. });
  151. });