projectSourceMaps.spec.tsx 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. import {SourceMapArchiveFixture} from 'sentry-fixture/sourceMapArchive';
  2. import {SourceMapsDebugIDBundlesFixture} 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. SourceMapArchiveFixture(),
  29. SourceMapArchiveFixture({
  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 ? [] : SourceMapsDebugIDBundlesFixture(),
  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. expect(mockRequests.artifactBundles).toHaveBeenCalledTimes(1);
  196. // Title
  197. expect(screen.getByRole('heading', {name: 'Source Maps'})).toBeInTheDocument();
  198. // Active tab
  199. const tabs = screen.getAllByRole('listitem');
  200. expect(tabs).toHaveLength(2);
  201. // Tab 1
  202. expect(tabs[0]).toHaveTextContent('Artifact Bundles');
  203. expect(tabs[0]).toHaveClass('active');
  204. // Tab 2
  205. expect(tabs[1]).toHaveTextContent('Release Bundles');
  206. expect(tabs[1]).not.toHaveClass('active');
  207. // Search bar
  208. expect(
  209. screen.getByPlaceholderText('Filter by Bundle ID, Debug ID or Release')
  210. ).toBeInTheDocument();
  211. // Artifacts
  212. expect(await screen.findByText('Artifacts')).toBeInTheDocument();
  213. expect(await screen.findByText('39')).toBeInTheDocument();
  214. // Release information
  215. expect(await screen.findByText('Associated Releases')).toBeInTheDocument();
  216. expect(
  217. await screen.findByText(textWithMarkupMatcher('v2.0 (Dist: none)'))
  218. ).toBeInTheDocument();
  219. expect(
  220. await screen.findByText(
  221. textWithMarkupMatcher(
  222. 'frontend@2e318148eac9298ec04a662ae32b4b093b027f0a (Dist: android, iOS)'
  223. )
  224. )
  225. ).toBeInTheDocument();
  226. // Date Uploaded
  227. expect(await screen.findByText('Date Uploaded')).toBeInTheDocument();
  228. expect(screen.getByText('Mar 8, 2023 9:53 AM UTC')).toBeInTheDocument();
  229. // Delete button
  230. expect(screen.getByRole('button', {name: 'Delete Bundle'})).toBeEnabled();
  231. // Click on release
  232. await userEvent.click(
  233. screen.getByRole('link', {
  234. name: 'frontend@2e318148eac9298ec04a662ae32b4b093b027f0a',
  235. })
  236. );
  237. expect(router.push).toHaveBeenLastCalledWith(
  238. '/organizations/org-slug/releases/frontend@2e318148eac9298ec04a662ae32b4b093b027f0a/'
  239. );
  240. // Click on bundle id
  241. await userEvent.click(
  242. screen.getByRole('link', {
  243. name: 'b916a646-2c6b-4e45-af4c-409830a44e0e',
  244. })
  245. );
  246. expect(router.push).toHaveBeenLastCalledWith(
  247. '/settings/org-slug/projects/project-slug/source-maps/artifact-bundles/b916a646-2c6b-4e45-af4c-409830a44e0e'
  248. );
  249. renderGlobalModal();
  250. // Delete item displays a confirmation modal
  251. await userEvent.click(screen.getByRole('button', {name: 'Delete Bundle'}));
  252. expect(
  253. await screen.findByText('Are you sure you want to delete this bundle?')
  254. ).toBeInTheDocument();
  255. // Close modal
  256. await userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
  257. await waitFor(() => {
  258. expect(mockRequests.artifactBundlesDeletion).toHaveBeenLastCalledWith(
  259. '/projects/org-slug/project-slug/files/artifact-bundles/',
  260. expect.objectContaining({
  261. query: expect.objectContaining({
  262. bundleId: 'b916a646-2c6b-4e45-af4c-409830a44e0e',
  263. }),
  264. })
  265. );
  266. });
  267. });
  268. it('renders empty state', async function () {
  269. const {organization, project, routerProps, routerContext} = initializeOrg({
  270. router: {
  271. location: {
  272. query: {},
  273. pathname: `/settings/${initializeOrg().organization.slug}/projects/${
  274. initializeOrg().project.slug
  275. }/source-maps/artifact-bundles/`,
  276. },
  277. },
  278. });
  279. renderDebugIdBundlesMockRequests({
  280. orgSlug: organization.slug,
  281. projectSlug: project.slug,
  282. empty: true,
  283. });
  284. render(<ProjectSourceMaps project={project} {...routerProps} />, {
  285. context: routerContext,
  286. organization,
  287. });
  288. expect(
  289. await screen.findByText('No artifact bundles found for this project.')
  290. ).toBeInTheDocument();
  291. });
  292. });
  293. });