projectSourceMaps.spec.tsx 11 KB

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