projectSourceMapsArtifacts.spec.tsx 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  3. import ConfigStore from 'sentry/stores/configStore';
  4. import {ProjectSourceMapsArtifacts} from 'sentry/views/settings/projectSourceMaps/projectSourceMapsArtifacts';
  5. function renderReleaseBundlesMockRequests({
  6. orgSlug,
  7. projectSlug,
  8. empty,
  9. }: {
  10. orgSlug: string;
  11. projectSlug: string;
  12. empty?: boolean;
  13. }) {
  14. const sourceMaps = MockApiClient.addMockResponse({
  15. url: `/projects/${orgSlug}/${projectSlug}/files/source-maps/`,
  16. body: empty
  17. ? []
  18. : [
  19. TestStubs.SourceMapArchive(),
  20. TestStubs.SourceMapArchive({
  21. id: 2,
  22. name: 'abc',
  23. fileCount: 3,
  24. date: '2023-05-06T13:41:00Z',
  25. }),
  26. ],
  27. });
  28. const sourceMapsFiles = MockApiClient.addMockResponse({
  29. url: `/projects/${orgSlug}/${projectSlug}/releases/bea7335dfaebc0ca6e65a057/files/`,
  30. body: empty ? [] : [TestStubs.SourceMapArtifact()],
  31. });
  32. return {sourceMaps, sourceMapsFiles};
  33. }
  34. function renderDebugIdBundlesMockRequests({
  35. orgSlug,
  36. projectSlug,
  37. empty,
  38. }: {
  39. orgSlug: string;
  40. projectSlug: string;
  41. empty?: boolean;
  42. }) {
  43. const artifactBundlesFiles = MockApiClient.addMockResponse({
  44. url: `/projects/${orgSlug}/${projectSlug}/artifact-bundles/7227e105-744e-4066-8c69-3e5e344723fc/files/`,
  45. body: empty ? {} : TestStubs.SourceMapsDebugIDBundlesArtifacts(),
  46. });
  47. return {artifactBundlesFiles};
  48. }
  49. describe('ProjectSourceMapsArtifacts', function () {
  50. describe('Release Bundles', function () {
  51. it('renders default state', async function () {
  52. const {organization, route, project, router, routerContext} = initializeOrg({
  53. router: {
  54. location: {
  55. query: {},
  56. },
  57. params: {},
  58. },
  59. });
  60. ConfigStore.config = {
  61. ...ConfigStore.config,
  62. user: {...ConfigStore.config.user, isSuperuser: true},
  63. };
  64. renderReleaseBundlesMockRequests({
  65. orgSlug: organization.slug,
  66. projectSlug: project.slug,
  67. });
  68. render(
  69. <ProjectSourceMapsArtifacts
  70. location={routerContext.context.location}
  71. project={project}
  72. route={route}
  73. routeParams={{orgId: organization.slug, projectId: project.slug}}
  74. router={router}
  75. routes={[]}
  76. params={{
  77. orgId: organization.slug,
  78. projectId: project.slug,
  79. bundleId: 'bea7335dfaebc0ca6e65a057',
  80. }}
  81. />,
  82. {context: routerContext, organization}
  83. );
  84. // Title
  85. expect(screen.getByRole('heading')).toHaveTextContent('Release Bundle');
  86. // Subtitle
  87. expect(screen.getByText('bea7335dfaebc0ca6e65a057')).toBeInTheDocument();
  88. // Search bar
  89. expect(screen.getByPlaceholderText('Filter by Path')).toBeInTheDocument();
  90. // Path
  91. expect(
  92. await screen.findByText('https://example.com/AcceptOrganizationInvite.js')
  93. ).toBeInTheDocument();
  94. // Time
  95. expect(screen.getByText(/in 3 year/)).toBeInTheDocument();
  96. // File size
  97. expect(screen.getByText('8.1 KiB')).toBeInTheDocument();
  98. // Download button
  99. expect(screen.getByRole('button', {name: 'Download Artifact'})).toHaveAttribute(
  100. 'href',
  101. '/projects/org-slug/project-slug/releases/bea7335dfaebc0ca6e65a057/files/5678/?download=1'
  102. );
  103. });
  104. it('renders empty state', async function () {
  105. const {organization, route, project, router, routerContext} = initializeOrg({
  106. router: {
  107. location: {
  108. query: {},
  109. },
  110. params: {},
  111. },
  112. });
  113. renderReleaseBundlesMockRequests({
  114. orgSlug: organization.slug,
  115. projectSlug: project.slug,
  116. empty: true,
  117. });
  118. render(
  119. <ProjectSourceMapsArtifacts
  120. location={routerContext.context.location}
  121. project={project}
  122. route={route}
  123. routeParams={{orgId: organization.slug, projectId: project.slug}}
  124. router={router}
  125. routes={[]}
  126. params={{
  127. orgId: organization.slug,
  128. projectId: project.slug,
  129. bundleId: 'bea7335dfaebc0ca6e65a057',
  130. }}
  131. />,
  132. {context: routerContext, organization}
  133. );
  134. expect(
  135. await screen.findByText('There are no artifacts in this archive.')
  136. ).toBeInTheDocument();
  137. });
  138. });
  139. describe('Artifact Bundles', function () {
  140. it('renders default state', async function () {
  141. const {organization, route, project, router, routerContext} = initializeOrg({
  142. router: {
  143. location: {
  144. pathname: `/settings/${initializeOrg().organization.slug}/projects/${
  145. initializeOrg().project.slug
  146. }/source-maps/artifact-bundles/7227e105-744e-4066-8c69-3e5e344723fc/`,
  147. query: {},
  148. },
  149. params: {},
  150. },
  151. });
  152. ConfigStore.config = {
  153. ...ConfigStore.config,
  154. user: {...ConfigStore.config.user, isSuperuser: true},
  155. };
  156. renderDebugIdBundlesMockRequests({
  157. orgSlug: organization.slug,
  158. projectSlug: project.slug,
  159. });
  160. render(
  161. <ProjectSourceMapsArtifacts
  162. location={routerContext.context.location}
  163. project={project}
  164. route={route}
  165. routeParams={{orgId: organization.slug, projectId: project.slug}}
  166. router={router}
  167. routes={[]}
  168. params={{
  169. orgId: organization.slug,
  170. projectId: project.slug,
  171. bundleId: '7227e105-744e-4066-8c69-3e5e344723fc',
  172. }}
  173. />,
  174. {context: routerContext, organization}
  175. );
  176. // Title
  177. expect(screen.getByRole('heading')).toHaveTextContent('Artifact Bundle');
  178. // Subtitle
  179. expect(
  180. screen.getByText('7227e105-744e-4066-8c69-3e5e344723fc')
  181. ).toBeInTheDocument();
  182. // Chips
  183. await userEvent.hover(await screen.findByText('2.0'));
  184. expect(
  185. await screen.findByText('Associated with release "2.0"')
  186. ).toBeInTheDocument();
  187. await userEvent.hover(await screen.findByText('android'));
  188. expect(
  189. await screen.findByText('Associated with distribution "android"')
  190. ).toBeInTheDocument();
  191. // Search bar
  192. expect(screen.getByPlaceholderText('Filter by Path or ID')).toBeInTheDocument();
  193. // Path
  194. expect(await screen.findByText('files/_/_/main.js')).toBeInTheDocument();
  195. // Debug Id
  196. expect(
  197. screen.getByText('69ac68eb-cc62-44c0-a5dc-b67f219a3696')
  198. ).toBeInTheDocument();
  199. // Type
  200. expect(screen.getByText('Minified')).toBeInTheDocument();
  201. // Download Button
  202. expect(screen.getByRole('button', {name: 'Download Artifact'})).toHaveAttribute(
  203. 'href',
  204. '/projects/org-slug/project-slug/artifact-bundles/7227e105-744e-4066-8c69-3e5e344723fc/files/ZmlsZXMvXy9fL21haW4uanM=/?download=1'
  205. );
  206. });
  207. it('renders empty state', async function () {
  208. const {organization, route, project, router, routerContext} = initializeOrg({
  209. router: {
  210. location: {
  211. pathname: `/settings/${initializeOrg().organization.slug}/projects/${
  212. initializeOrg().project.slug
  213. }/source-maps/artifact-bundles/7227e105-744e-4066-8c69-3e5e344723fc/`,
  214. query: {},
  215. },
  216. params: {},
  217. },
  218. });
  219. renderDebugIdBundlesMockRequests({
  220. orgSlug: organization.slug,
  221. projectSlug: project.slug,
  222. empty: true,
  223. });
  224. render(
  225. <ProjectSourceMapsArtifacts
  226. location={routerContext.context.location}
  227. project={project}
  228. route={route}
  229. routeParams={{orgId: organization.slug, projectId: project.slug}}
  230. router={router}
  231. routes={[]}
  232. params={{
  233. orgId: organization.slug,
  234. projectId: project.slug,
  235. bundleId: '7227e105-744e-4066-8c69-3e5e344723fc',
  236. }}
  237. />,
  238. {context: routerContext, organization}
  239. );
  240. expect(
  241. await screen.findByText('There are no artifacts in this bundle.')
  242. ).toBeInTheDocument();
  243. });
  244. });
  245. });