sourceMapsList.spec.tsx 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. } from 'sentry-test/reactTestingLibrary';
  11. import {textWithMarkupMatcher} from 'sentry-test/utils';
  12. import {SourceMapsList} from 'sentry/views/settings/projectSourceMaps/sourceMapsList';
  13. function renderReleaseBundlesMockRequests({
  14. orgSlug,
  15. projectSlug,
  16. empty,
  17. }: {
  18. orgSlug: string;
  19. projectSlug: string;
  20. empty?: boolean;
  21. }) {
  22. const sourceMaps = MockApiClient.addMockResponse({
  23. url: `/projects/${orgSlug}/${projectSlug}/files/source-maps/`,
  24. body: empty
  25. ? []
  26. : [
  27. SourceMapArchiveFixture(),
  28. SourceMapArchiveFixture({
  29. id: 2,
  30. name: 'abc',
  31. fileCount: 3,
  32. date: '2023-05-06T13:41:00Z',
  33. }),
  34. ],
  35. });
  36. return {sourceMaps};
  37. }
  38. function renderDebugIdBundlesMockRequests({
  39. orgSlug,
  40. projectSlug,
  41. empty,
  42. }: {
  43. orgSlug: string;
  44. projectSlug: string;
  45. empty?: boolean;
  46. }) {
  47. const artifactBundles = MockApiClient.addMockResponse({
  48. url: `/projects/${orgSlug}/${projectSlug}/files/artifact-bundles/`,
  49. body: empty ? [] : SourceMapsDebugIDBundlesFixture(),
  50. });
  51. const artifactBundlesDeletion = MockApiClient.addMockResponse({
  52. url: `/projects/${orgSlug}/${projectSlug}/files/artifact-bundles/`,
  53. method: 'DELETE',
  54. });
  55. return {artifactBundles, artifactBundlesDeletion};
  56. }
  57. describe('ProjectSourceMaps', function () {
  58. describe('Artifact Bundles', function () {
  59. it('renders default state', async function () {
  60. const {organization, project, router, routerProps} = initializeOrg({
  61. router: {
  62. location: {
  63. query: {},
  64. pathname: `/settings/${initializeOrg().organization.slug}/projects/${
  65. initializeOrg().project.slug
  66. }/source-maps/`,
  67. },
  68. },
  69. });
  70. renderReleaseBundlesMockRequests({
  71. orgSlug: organization.slug,
  72. projectSlug: project.slug,
  73. empty: true,
  74. });
  75. const mockRequests = renderDebugIdBundlesMockRequests({
  76. orgSlug: organization.slug,
  77. projectSlug: project.slug,
  78. });
  79. render(<SourceMapsList project={project} {...routerProps} />, {
  80. router,
  81. organization,
  82. });
  83. expect(mockRequests.artifactBundles).toHaveBeenCalledTimes(1);
  84. // Title
  85. expect(
  86. screen.getByRole('heading', {name: 'Source Map Uploads'})
  87. ).toBeInTheDocument();
  88. // Search bar
  89. expect(
  90. screen.getByPlaceholderText('Filter by Debug ID or Upload ID')
  91. ).toBeInTheDocument();
  92. // Artifacts
  93. expect(await screen.findByText('Upload ID')).toBeInTheDocument();
  94. // Release information
  95. expect(await screen.findByText('Found in Releases')).toBeInTheDocument();
  96. expect(await screen.findByText(textWithMarkupMatcher('v2.0'))).toBeInTheDocument();
  97. expect(
  98. await screen.findByText(textWithMarkupMatcher('2e318148eac9'))
  99. ).toBeInTheDocument();
  100. expect(
  101. await screen.findByText(textWithMarkupMatcher('(Dist: android, iOS)'))
  102. ).toBeInTheDocument();
  103. // Date Uploaded
  104. expect(screen.getByText('Mar 8, 2023 9:53 AM')).toBeInTheDocument();
  105. expect(screen.getByText('(39 files)')).toBeInTheDocument();
  106. // Delete button
  107. expect(screen.getByRole('button', {name: 'Delete Source Maps'})).toBeEnabled();
  108. renderGlobalModal();
  109. // Delete item displays a confirmation modal
  110. await userEvent.click(screen.getByRole('button', {name: 'Delete Source Maps'}));
  111. expect(
  112. await screen.findByText('Are you sure you want to delete Source Maps?')
  113. ).toBeInTheDocument();
  114. // Close modal
  115. await userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
  116. await waitFor(() => {
  117. expect(mockRequests.artifactBundlesDeletion).toHaveBeenLastCalledWith(
  118. '/projects/org-slug/project-slug/files/artifact-bundles/',
  119. expect.objectContaining({
  120. query: expect.objectContaining({
  121. bundleId: 'b916a646-2c6b-4e45-af4c-409830a44e0e',
  122. }),
  123. })
  124. );
  125. });
  126. });
  127. it('renders empty state', async function () {
  128. const {organization, project, routerProps, router} = initializeOrg({
  129. router: {
  130. location: {
  131. query: {},
  132. pathname: `/settings/${initializeOrg().organization.slug}/projects/${
  133. initializeOrg().project.slug
  134. }/source-maps/artifact-bundles/`,
  135. },
  136. },
  137. });
  138. renderReleaseBundlesMockRequests({
  139. orgSlug: organization.slug,
  140. projectSlug: project.slug,
  141. empty: true,
  142. });
  143. renderDebugIdBundlesMockRequests({
  144. orgSlug: organization.slug,
  145. projectSlug: project.slug,
  146. empty: true,
  147. });
  148. render(<SourceMapsList project={project} {...routerProps} />, {
  149. router,
  150. organization,
  151. });
  152. expect(await screen.findByText('No source map uploads found')).toBeInTheDocument();
  153. });
  154. });
  155. });