releaseActions.spec.jsx 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. import {browserHistory} from 'react-router';
  2. import {
  3. render,
  4. renderGlobalModal,
  5. screen,
  6. userEvent,
  7. waitFor,
  8. } from 'sentry-test/reactTestingLibrary';
  9. import ReleaseActions from 'sentry/views/releases/detail/header/releaseActions';
  10. describe('ReleaseActions', function () {
  11. const organization = TestStubs.Organization();
  12. const release = TestStubs.Release({projects: [{slug: 'project1'}, {slug: 'project2'}]});
  13. const location = {
  14. pathname: `/organizations/sentry/releases/${release.version}/`,
  15. query: {
  16. project: 1,
  17. statsPeriod: '24h',
  18. yAxis: 'events',
  19. },
  20. };
  21. let mockUpdate;
  22. beforeEach(function () {
  23. mockUpdate = MockApiClient.addMockResponse({
  24. url: `/organizations/${organization.slug}/releases/`,
  25. method: 'POST',
  26. });
  27. });
  28. afterEach(function () {
  29. MockApiClient.clearMockResponses();
  30. });
  31. it('archives a release', async function () {
  32. render(
  33. <ReleaseActions
  34. organization={organization}
  35. projectSlug={release.projects[0].slug}
  36. release={release}
  37. refetchData={jest.fn()}
  38. releaseMeta={{projects: release.projects}}
  39. location={location}
  40. />
  41. );
  42. renderGlobalModal();
  43. userEvent.click(screen.getByLabelText('Actions'));
  44. const archiveAction = screen.getByTestId('archive');
  45. expect(archiveAction).toBeInTheDocument();
  46. expect(archiveAction).toHaveTextContent('Archive');
  47. userEvent.click(archiveAction);
  48. expect(await screen.findByText('Archive Release')).toBeInTheDocument();
  49. const affectedProjects = screen.getAllByTestId('badge-display-name');
  50. expect(affectedProjects.length).toBe(2);
  51. // confirm modal
  52. userEvent.click(screen.getByTestId('confirm-button'));
  53. expect(mockUpdate).toHaveBeenCalledWith(
  54. expect.anything(),
  55. expect.objectContaining({
  56. data: {
  57. projects: [],
  58. status: 'archived',
  59. version: release.version,
  60. },
  61. })
  62. );
  63. await waitFor(() =>
  64. expect(browserHistory.push).toHaveBeenCalledWith(
  65. `/organizations/${organization.slug}/releases/`
  66. )
  67. );
  68. });
  69. it('restores a release', async function () {
  70. const refetchDataMock = jest.fn();
  71. render(
  72. <ReleaseActions
  73. organization={organization}
  74. projectSlug={release.projects[0].slug}
  75. release={{...release, status: 'archived'}}
  76. refetchData={refetchDataMock}
  77. releaseMeta={{projects: release.projects}}
  78. location={location}
  79. />
  80. );
  81. renderGlobalModal();
  82. userEvent.click(screen.getByLabelText('Actions'));
  83. const restoreAction = screen.getByTestId('restore');
  84. expect(restoreAction).toBeInTheDocument(1);
  85. expect(restoreAction).toHaveTextContent('Restore');
  86. userEvent.click(restoreAction);
  87. expect(await screen.findByText('Restore Release')).toBeInTheDocument();
  88. const affectedProjects = screen.getAllByTestId('badge-display-name');
  89. expect(affectedProjects.length).toBe(2);
  90. // confirm modal
  91. userEvent.click(screen.getByTestId('confirm-button'));
  92. expect(mockUpdate).toHaveBeenCalledWith(
  93. expect.anything(),
  94. expect.objectContaining({
  95. data: {
  96. projects: [],
  97. status: 'open',
  98. version: release.version,
  99. },
  100. })
  101. );
  102. await waitFor(() => expect(refetchDataMock).toHaveBeenCalledTimes(1));
  103. });
  104. it('navigates to a next/prev release', function () {
  105. const routerContext = TestStubs.routerContext();
  106. const {rerender} = render(
  107. <ReleaseActions
  108. organization={organization}
  109. projectSlug={release.projects[0].slug}
  110. release={release}
  111. refetchData={jest.fn()}
  112. releaseMeta={{projects: release.projects}}
  113. location={location}
  114. />,
  115. {context: routerContext}
  116. );
  117. expect(screen.getByLabelText('Oldest')).toHaveAttribute(
  118. 'href',
  119. '/organizations/sentry/releases/0/?project=1&statsPeriod=24h&yAxis=events'
  120. );
  121. expect(screen.getByLabelText('Older')).toHaveAttribute(
  122. 'href',
  123. '/organizations/sentry/releases/123/?project=1&statsPeriod=24h&yAxis=events'
  124. );
  125. expect(screen.getByLabelText('Newer')).toHaveAttribute(
  126. 'href',
  127. '/organizations/sentry/releases/456/?project=1&statsPeriod=24h&yAxis=events'
  128. );
  129. expect(screen.getByLabelText('Newest')).toHaveAttribute(
  130. 'href',
  131. '/organizations/sentry/releases/999/?project=1&statsPeriod=24h&yAxis=events'
  132. );
  133. rerender(
  134. <ReleaseActions
  135. organization={organization}
  136. projectSlug={release.projects[0].slug}
  137. release={release}
  138. refetchData={jest.fn()}
  139. releaseMeta={{projects: release.projects}}
  140. location={{
  141. ...location,
  142. pathname: `/organizations/sentry/releases/${release.version}/files-changed/`,
  143. }}
  144. />,
  145. {context: routerContext}
  146. );
  147. expect(screen.getByLabelText('Newer')).toHaveAttribute(
  148. 'href',
  149. '/organizations/sentry/releases/456/files-changed/?project=1&statsPeriod=24h&yAxis=events'
  150. );
  151. });
  152. });