projectSourceMaps.spec.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {
  3. render,
  4. renderGlobalModal,
  5. screen,
  6. userEvent,
  7. waitFor,
  8. } from 'sentry-test/reactTestingLibrary';
  9. import {textWithMarkupMatcher} from 'sentry-test/utils';
  10. import {ProjectSourceMaps} from 'sentry/views/settings/projectSourceMaps/projectSourceMaps';
  11. function renderReleaseBundlesMockRequests({
  12. orgSlug,
  13. projectSlug,
  14. empty,
  15. }: {
  16. orgSlug: string;
  17. projectSlug: string;
  18. empty?: boolean;
  19. }) {
  20. const sourceMaps = MockApiClient.addMockResponse({
  21. url: `/projects/${orgSlug}/${projectSlug}/files/source-maps/`,
  22. body: empty
  23. ? []
  24. : [
  25. TestStubs.SourceMapArchive(),
  26. TestStubs.SourceMapArchive({
  27. id: 2,
  28. name: 'abc',
  29. fileCount: 3,
  30. date: '2023-05-06T13:41:00Z',
  31. }),
  32. ],
  33. });
  34. return {sourceMaps};
  35. }
  36. function renderDebugIdBundlesMockRequests({
  37. orgSlug,
  38. projectSlug,
  39. empty,
  40. }: {
  41. orgSlug: string;
  42. projectSlug: string;
  43. empty?: boolean;
  44. }) {
  45. const artifactBundles = MockApiClient.addMockResponse({
  46. url: `/projects/${orgSlug}/${projectSlug}/files/artifact-bundles/`,
  47. body: empty ? [] : TestStubs.SourceMapsDebugIDBundles(),
  48. });
  49. const artifactBundlesDeletion = MockApiClient.addMockResponse({
  50. url: `/projects/${orgSlug}/${projectSlug}/files/artifact-bundles/`,
  51. method: 'DELETE',
  52. });
  53. return {artifactBundles, artifactBundlesDeletion};
  54. }
  55. describe('ProjectSourceMaps', function () {
  56. describe('Release Bundles', function () {
  57. it('renders default state', async function () {
  58. const {organization, route, project, router, routerContext} = initializeOrg({
  59. router: {
  60. location: {
  61. query: {},
  62. pathname: `/settings/${initializeOrg().organization.slug}/projects/${
  63. initializeOrg().project.slug
  64. }/source-maps/release-bundles/`,
  65. },
  66. params: {},
  67. },
  68. });
  69. const mockRequests = renderReleaseBundlesMockRequests({
  70. orgSlug: organization.slug,
  71. projectSlug: project.slug,
  72. });
  73. render(
  74. <ProjectSourceMaps
  75. location={routerContext.context.location}
  76. project={project}
  77. route={route}
  78. routeParams={{orgId: organization.slug, projectId: project.slug}}
  79. router={router}
  80. routes={[]}
  81. params={{orgId: organization.slug, projectId: project.slug}}
  82. />,
  83. {context: routerContext, organization}
  84. );
  85. // Title
  86. expect(screen.getByRole('heading', {name: 'Source Maps'})).toBeInTheDocument();
  87. // Active tab
  88. const tabs = screen.getAllByRole('listitem');
  89. expect(tabs).toHaveLength(2);
  90. // Tab 1
  91. expect(tabs[0]).toHaveTextContent('Artifact Bundles');
  92. expect(tabs[0]).not.toHaveClass('active');
  93. // Tab 2
  94. expect(tabs[1]).toHaveTextContent('Release Bundles');
  95. expect(tabs[1]).toHaveClass('active');
  96. // Search bar
  97. expect(screen.getByPlaceholderText('Filter by Name')).toBeInTheDocument();
  98. // Date Uploaded can be sorted
  99. await userEvent.hover(screen.getByTestId('icon-arrow'));
  100. expect(await screen.findByText('Switch to ascending order')).toBeInTheDocument();
  101. await userEvent.click(screen.getByTestId('icon-arrow'));
  102. await waitFor(() => {
  103. expect(mockRequests.sourceMaps).toHaveBeenLastCalledWith(
  104. '/projects/org-slug/project-slug/files/source-maps/',
  105. expect.objectContaining({
  106. query: expect.objectContaining({
  107. sortBy: '-date_added',
  108. }),
  109. })
  110. );
  111. });
  112. // Active tab contains correct link
  113. expect(screen.getByRole('link', {name: /Release Bundles/})).toHaveAttribute(
  114. 'href',
  115. '/settings/org-slug/projects/project-slug/source-maps/release-bundles/'
  116. );
  117. // Name
  118. expect(await screen.findByRole('link', {name: '1234'})).toBeInTheDocument();
  119. // Artifacts
  120. expect(screen.getByText('0')).toBeInTheDocument();
  121. // Date
  122. expect(screen.getByText('May 6, 2020 1:41 PM UTC')).toBeInTheDocument();
  123. // Delete buttons (this example renders 2 rows)
  124. expect(screen.getAllByRole('button', {name: 'Remove All Artifacts'})).toHaveLength(
  125. 2
  126. );
  127. expect(
  128. screen.getAllByRole('button', {name: 'Remove All Artifacts'})[0]
  129. ).toBeEnabled();
  130. renderGlobalModal();
  131. // Delete item displays a confirmation modal
  132. await userEvent.click(
  133. screen.getAllByRole('button', {name: 'Remove All Artifacts'})[0]
  134. );
  135. expect(
  136. await screen.findByText(
  137. 'Are you sure you want to remove all artifacts in this archive?'
  138. )
  139. ).toBeInTheDocument();
  140. // Close modal
  141. await userEvent.click(screen.getByRole('button', {name: 'Cancel'}));
  142. // Switch tab
  143. await userEvent.click(screen.getByRole('link', {name: 'Artifact Bundles'}));
  144. expect(router.push).toHaveBeenCalledWith({
  145. pathname:
  146. '/settings/org-slug/projects/project-slug/source-maps/artifact-bundles/',
  147. query: undefined,
  148. });
  149. });
  150. it('renders empty state', async function () {
  151. const {organization, route, project, router, routerContext} = initializeOrg({
  152. router: {
  153. location: {
  154. query: {},
  155. pathname: `/settings/${initializeOrg().organization.slug}/projects/${
  156. initializeOrg().project.slug
  157. }/source-maps/release-bundles/`,
  158. },
  159. params: {},
  160. },
  161. });
  162. renderReleaseBundlesMockRequests({
  163. orgSlug: organization.slug,
  164. projectSlug: project.slug,
  165. empty: true,
  166. });
  167. render(
  168. <ProjectSourceMaps
  169. location={routerContext.context.location}
  170. project={project}
  171. route={route}
  172. routeParams={{orgId: organization.slug, projectId: project.slug}}
  173. router={router}
  174. routes={[]}
  175. params={{orgId: organization.slug, projectId: project.slug}}
  176. />,
  177. {context: routerContext, organization}
  178. );
  179. expect(
  180. await screen.findByText('No release bundles found for this project.')
  181. ).toBeInTheDocument();
  182. });
  183. });
  184. describe('Artifact Bundles', function () {
  185. it('renders default state', async function () {
  186. const {organization, route, project, router, routerContext} = initializeOrg({
  187. router: {
  188. location: {
  189. query: {},
  190. pathname: `/settings/${initializeOrg().organization.slug}/projects/${
  191. initializeOrg().project.slug
  192. }/source-maps/artifact-bundles/`,
  193. },
  194. params: {},
  195. },
  196. });
  197. const mockRequests = renderDebugIdBundlesMockRequests({
  198. orgSlug: organization.slug,
  199. projectSlug: project.slug,
  200. });
  201. render(
  202. <ProjectSourceMaps
  203. location={routerContext.context.location}
  204. project={project}
  205. route={route}
  206. routeParams={{orgId: organization.slug, projectId: project.slug}}
  207. router={router}
  208. routes={[]}
  209. params={{orgId: organization.slug, projectId: project.slug}}
  210. />,
  211. {context: routerContext, organization}
  212. );
  213. // Title
  214. expect(screen.getByRole('heading', {name: 'Source Maps'})).toBeInTheDocument();
  215. // Active tab
  216. const tabs = screen.getAllByRole('listitem');
  217. expect(tabs).toHaveLength(2);
  218. // Tab 1
  219. expect(tabs[0]).toHaveTextContent('Artifact Bundles');
  220. expect(tabs[0]).toHaveClass('active');
  221. // Tab 2
  222. expect(tabs[1]).toHaveTextContent('Release Bundles');
  223. expect(tabs[1]).not.toHaveClass('active');
  224. // Search bar
  225. expect(screen.getByPlaceholderText('Filter by Bundle ID')).toBeInTheDocument();
  226. // Date Uploaded can be sorted
  227. await userEvent.hover(screen.getByTestId('icon-arrow'));
  228. expect(await screen.findByText('Switch to ascending order')).toBeInTheDocument();
  229. await userEvent.click(screen.getByTestId('icon-arrow'));
  230. await waitFor(() => {
  231. expect(mockRequests.artifactBundles).toHaveBeenLastCalledWith(
  232. '/projects/org-slug/project-slug/files/artifact-bundles/',
  233. expect.objectContaining({
  234. query: expect.objectContaining({
  235. sortBy: '-date_added',
  236. }),
  237. })
  238. );
  239. });
  240. // Artifacts
  241. expect(screen.getByText('39')).toBeInTheDocument();
  242. // Date Uploaded
  243. expect(screen.getByText('Mar 8, 2023 9:53 AM UTC')).toBeInTheDocument();
  244. // Delete button
  245. expect(screen.getByRole('button', {name: 'Remove All Artifacts'})).toBeEnabled();
  246. // Release information
  247. expect(
  248. await screen.findByText(textWithMarkupMatcher('2 Releases associated'))
  249. ).toBeInTheDocument();
  250. await userEvent.hover(screen.getByText('2 Releases'));
  251. expect(
  252. await screen.findByText('frontend@2e318148eac9298ec04a662ae32b4b093b027f0a')
  253. ).toBeInTheDocument();
  254. // Click on bundle id
  255. await userEvent.click(
  256. screen.getByRole('link', {name: 'b916a646-2c6b-4e45-af4c-409830a44e0e'})
  257. );
  258. expect(router.push).toHaveBeenLastCalledWith(
  259. '/settings/org-slug/projects/project-slug/source-maps/artifact-bundles/b916a646-2c6b-4e45-af4c-409830a44e0e'
  260. );
  261. renderGlobalModal();
  262. // Delete item displays a confirmation modal
  263. await userEvent.click(screen.getByRole('button', {name: 'Remove All Artifacts'}));
  264. expect(
  265. await screen.findByText(
  266. 'Are you sure you want to remove all artifacts in this archive?'
  267. )
  268. ).toBeInTheDocument();
  269. // Close modal
  270. await userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
  271. await waitFor(() => {
  272. expect(mockRequests.artifactBundlesDeletion).toHaveBeenLastCalledWith(
  273. '/projects/org-slug/project-slug/files/artifact-bundles/',
  274. expect.objectContaining({
  275. query: expect.objectContaining({
  276. bundleId: 'b916a646-2c6b-4e45-af4c-409830a44e0e',
  277. }),
  278. })
  279. );
  280. });
  281. // Switch tab
  282. await userEvent.click(screen.getByRole('link', {name: /Release Bundles/}));
  283. expect(router.push).toHaveBeenCalledWith({
  284. pathname: '/settings/org-slug/projects/project-slug/source-maps/release-bundles/',
  285. query: undefined,
  286. });
  287. });
  288. it('renders empty state', async function () {
  289. const {organization, route, project, router, routerContext} = initializeOrg({
  290. router: {
  291. location: {
  292. query: {},
  293. pathname: `/settings/${initializeOrg().organization.slug}/projects/${
  294. initializeOrg().project.slug
  295. }/source-maps/artifact-bundles/`,
  296. },
  297. params: {},
  298. },
  299. });
  300. renderDebugIdBundlesMockRequests({
  301. orgSlug: organization.slug,
  302. projectSlug: project.slug,
  303. empty: true,
  304. });
  305. render(
  306. <ProjectSourceMaps
  307. location={routerContext.context.location}
  308. project={project}
  309. route={route}
  310. routeParams={{orgId: organization.slug, projectId: project.slug}}
  311. router={router}
  312. routes={[]}
  313. params={{orgId: organization.slug, projectId: project.slug}}
  314. />,
  315. {context: routerContext, organization}
  316. );
  317. expect(
  318. await screen.findByText('No artifact bundles found for this project.')
  319. ).toBeInTheDocument();
  320. });
  321. });
  322. });