projectSourceMaps.spec.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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, project, router, routerContext, routerProps} = 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. },
  67. });
  68. const mockRequests = renderReleaseBundlesMockRequests({
  69. orgSlug: organization.slug,
  70. projectSlug: project.slug,
  71. });
  72. render(<ProjectSourceMaps project={project} {...routerProps} />, {
  73. context: routerContext,
  74. organization,
  75. });
  76. // Title
  77. expect(screen.getByRole('heading', {name: 'Source Maps'})).toBeInTheDocument();
  78. // Active tab
  79. const tabs = screen.getAllByRole('listitem');
  80. expect(tabs).toHaveLength(2);
  81. // Tab 1
  82. expect(tabs[0]).toHaveTextContent('Artifact Bundles');
  83. expect(tabs[0]).not.toHaveClass('active');
  84. // Tab 2
  85. expect(tabs[1]).toHaveTextContent('Release Bundles');
  86. expect(tabs[1]).toHaveClass('active');
  87. // Search bar
  88. expect(screen.getByPlaceholderText('Filter by Name')).toBeInTheDocument();
  89. // Date Uploaded can be sorted
  90. await userEvent.hover(screen.getByTestId('icon-arrow'));
  91. expect(await screen.findByText('Switch to ascending order')).toBeInTheDocument();
  92. await userEvent.click(screen.getByTestId('icon-arrow'));
  93. await waitFor(() => {
  94. expect(mockRequests.sourceMaps).toHaveBeenLastCalledWith(
  95. '/projects/org-slug/project-slug/files/source-maps/',
  96. expect.objectContaining({
  97. query: expect.objectContaining({
  98. sortBy: 'date_added',
  99. }),
  100. })
  101. );
  102. });
  103. // Active tab contains correct link
  104. expect(screen.getByRole('link', {name: /Release Bundles/})).toHaveAttribute(
  105. 'href',
  106. '/settings/org-slug/projects/project-slug/source-maps/release-bundles/'
  107. );
  108. // Name
  109. expect(await screen.findByRole('link', {name: '1234'})).toBeInTheDocument();
  110. // Artifacts
  111. expect(screen.getByText('0')).toBeInTheDocument();
  112. // Date
  113. expect(screen.getByText('May 6, 2020 1:41 PM UTC')).toBeInTheDocument();
  114. // Delete buttons (this example renders 2 rows)
  115. expect(screen.getAllByRole('button', {name: 'Remove All Artifacts'})).toHaveLength(
  116. 2
  117. );
  118. expect(
  119. screen.getAllByRole('button', {name: 'Remove All Artifacts'})[0]
  120. ).toBeEnabled();
  121. renderGlobalModal();
  122. // Delete item displays a confirmation modal
  123. await userEvent.click(
  124. screen.getAllByRole('button', {name: 'Remove All Artifacts'})[0]
  125. );
  126. expect(
  127. await screen.findByText(
  128. 'Are you sure you want to remove all artifacts in this archive?'
  129. )
  130. ).toBeInTheDocument();
  131. // Close modal
  132. await userEvent.click(screen.getByRole('button', {name: 'Cancel'}));
  133. // Switch tab
  134. await userEvent.click(screen.getByRole('link', {name: 'Artifact Bundles'}));
  135. expect(router.push).toHaveBeenCalledWith({
  136. pathname:
  137. '/settings/org-slug/projects/project-slug/source-maps/artifact-bundles/',
  138. query: undefined,
  139. });
  140. });
  141. it('renders empty state', async function () {
  142. const {organization, project, routerContext, routerProps} = initializeOrg({
  143. router: {
  144. location: {
  145. query: {},
  146. pathname: `/settings/${initializeOrg().organization.slug}/projects/${
  147. initializeOrg().project.slug
  148. }/source-maps/release-bundles/`,
  149. },
  150. },
  151. });
  152. renderReleaseBundlesMockRequests({
  153. orgSlug: organization.slug,
  154. projectSlug: project.slug,
  155. empty: true,
  156. });
  157. render(<ProjectSourceMaps project={project} {...routerProps} />, {
  158. context: routerContext,
  159. organization,
  160. });
  161. expect(
  162. await screen.findByText('No release bundles found for this project.')
  163. ).toBeInTheDocument();
  164. });
  165. });
  166. describe('Artifact Bundles', function () {
  167. it('renders default state', async function () {
  168. const {organization, project, routerContext, router, routerProps} = initializeOrg({
  169. router: {
  170. location: {
  171. query: {},
  172. pathname: `/settings/${initializeOrg().organization.slug}/projects/${
  173. initializeOrg().project.slug
  174. }/source-maps/artifact-bundles/`,
  175. },
  176. },
  177. });
  178. const mockRequests = renderDebugIdBundlesMockRequests({
  179. orgSlug: organization.slug,
  180. projectSlug: project.slug,
  181. });
  182. render(<ProjectSourceMaps project={project} {...routerProps} />, {
  183. context: routerContext,
  184. organization,
  185. });
  186. // Title
  187. expect(screen.getByRole('heading', {name: 'Source Maps'})).toBeInTheDocument();
  188. // Active tab
  189. const tabs = screen.getAllByRole('listitem');
  190. expect(tabs).toHaveLength(2);
  191. // Tab 1
  192. expect(tabs[0]).toHaveTextContent('Artifact Bundles');
  193. expect(tabs[0]).toHaveClass('active');
  194. // Tab 2
  195. expect(tabs[1]).toHaveTextContent('Release Bundles');
  196. expect(tabs[1]).not.toHaveClass('active');
  197. // Search bar
  198. expect(
  199. screen.getByPlaceholderText('Filter by Bundle ID, Debug ID or Release')
  200. ).toBeInTheDocument();
  201. // Date Uploaded can be sorted
  202. await userEvent.click(screen.getByTestId('date-uploaded-header'));
  203. await userEvent.hover(screen.getByTestId('icon-arrow'));
  204. expect(await screen.findByText('Switch to ascending order')).toBeInTheDocument();
  205. await userEvent.click(screen.getByTestId('icon-arrow'));
  206. await waitFor(() => {
  207. expect(mockRequests.artifactBundles).toHaveBeenLastCalledWith(
  208. '/projects/org-slug/project-slug/files/artifact-bundles/',
  209. expect.objectContaining({
  210. query: expect.objectContaining({
  211. sortBy: 'date_added',
  212. }),
  213. })
  214. );
  215. });
  216. // Date Uploaded can be sorted in descending
  217. await userEvent.hover(screen.getByTestId('icon-arrow'));
  218. expect(await screen.findByText('Switch to descending order')).toBeInTheDocument();
  219. await userEvent.click(screen.getByTestId('icon-arrow'));
  220. await waitFor(() => {
  221. expect(mockRequests.artifactBundles).toHaveBeenLastCalledWith(
  222. '/projects/org-slug/project-slug/files/artifact-bundles/',
  223. expect.objectContaining({
  224. query: expect.objectContaining({
  225. sortBy: '-date_added',
  226. }),
  227. })
  228. );
  229. });
  230. // Date Modified can be sorted
  231. await userEvent.click(screen.getByTestId('date-modified-header'));
  232. await userEvent.hover(screen.getByTestId('icon-arrow-modified'));
  233. expect(await screen.findByText('Switch to ascending order')).toBeInTheDocument();
  234. await userEvent.click(screen.getByTestId('icon-arrow-modified'));
  235. await waitFor(() => {
  236. expect(mockRequests.artifactBundles).toHaveBeenLastCalledWith(
  237. '/projects/org-slug/project-slug/files/artifact-bundles/',
  238. expect.objectContaining({
  239. query: expect.objectContaining({
  240. sortBy: 'date_modified',
  241. }),
  242. })
  243. );
  244. });
  245. // Date Modified can be sorted in descending
  246. await userEvent.hover(screen.getByTestId('icon-arrow-modified'));
  247. expect(await screen.findByText('Switch to descending order')).toBeInTheDocument();
  248. await userEvent.click(screen.getByTestId('icon-arrow-modified'));
  249. await waitFor(() => {
  250. expect(mockRequests.artifactBundles).toHaveBeenLastCalledWith(
  251. '/projects/org-slug/project-slug/files/artifact-bundles/',
  252. expect.objectContaining({
  253. query: expect.objectContaining({
  254. sortBy: '-date_modified',
  255. }),
  256. })
  257. );
  258. });
  259. // Artifacts
  260. expect(screen.getByText('39')).toBeInTheDocument();
  261. // Date Modified
  262. expect(screen.getByText('Mar 10, 2023 8:25 AM UTC')).toBeInTheDocument();
  263. // Date Uploaded
  264. expect(screen.getByText('Mar 8, 2023 9:53 AM UTC')).toBeInTheDocument();
  265. // Delete button
  266. expect(screen.getByRole('button', {name: 'Remove All Artifacts'})).toBeEnabled();
  267. // Release information
  268. expect(
  269. await screen.findByText(textWithMarkupMatcher('2 Releases associated'))
  270. ).toBeInTheDocument();
  271. await userEvent.hover(screen.getByText('2 Releases'));
  272. expect(
  273. await screen.findByText('frontend@2e318148eac9298ec04a662ae32b4b093b027f0a')
  274. ).toBeInTheDocument();
  275. // Click on bundle id
  276. await userEvent.click(
  277. screen.getByRole('link', {name: 'b916a646-2c6b-4e45-af4c-409830a44e0e'})
  278. );
  279. expect(router.push).toHaveBeenLastCalledWith(
  280. '/settings/org-slug/projects/project-slug/source-maps/artifact-bundles/b916a646-2c6b-4e45-af4c-409830a44e0e'
  281. );
  282. renderGlobalModal();
  283. // Delete item displays a confirmation modal
  284. await userEvent.click(screen.getByRole('button', {name: 'Remove All Artifacts'}));
  285. expect(
  286. await screen.findByText(
  287. 'Are you sure you want to remove all artifacts in this archive?'
  288. )
  289. ).toBeInTheDocument();
  290. // Close modal
  291. await userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
  292. await waitFor(() => {
  293. expect(mockRequests.artifactBundlesDeletion).toHaveBeenLastCalledWith(
  294. '/projects/org-slug/project-slug/files/artifact-bundles/',
  295. expect.objectContaining({
  296. query: expect.objectContaining({
  297. bundleId: 'b916a646-2c6b-4e45-af4c-409830a44e0e',
  298. }),
  299. })
  300. );
  301. });
  302. // Switch tab
  303. await userEvent.click(screen.getByRole('link', {name: /Release Bundles/}));
  304. expect(router.push).toHaveBeenCalledWith({
  305. pathname: '/settings/org-slug/projects/project-slug/source-maps/release-bundles/',
  306. query: undefined,
  307. });
  308. });
  309. it('renders empty state', async function () {
  310. const {organization, project, routerProps, routerContext} = initializeOrg({
  311. router: {
  312. location: {
  313. query: {},
  314. pathname: `/settings/${initializeOrg().organization.slug}/projects/${
  315. initializeOrg().project.slug
  316. }/source-maps/artifact-bundles/`,
  317. },
  318. },
  319. });
  320. renderDebugIdBundlesMockRequests({
  321. orgSlug: organization.slug,
  322. projectSlug: project.slug,
  323. empty: true,
  324. });
  325. render(<ProjectSourceMaps project={project} {...routerProps} />, {
  326. context: routerContext,
  327. organization,
  328. });
  329. expect(
  330. await screen.findByText('No artifact bundles found for this project.')
  331. ).toBeInTheDocument();
  332. });
  333. });
  334. });