projectSourceMaps.spec.tsx 12 KB

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