projectSourceMapsArtifacts.spec.tsx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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. ...initializeOrg(),
  54. router: {
  55. location: {
  56. query: {},
  57. },
  58. params: {},
  59. },
  60. });
  61. ConfigStore.config = {
  62. ...ConfigStore.config,
  63. user: {...ConfigStore.config.user, isSuperuser: true},
  64. };
  65. renderReleaseBundlesMockRequests({
  66. orgSlug: organization.slug,
  67. projectSlug: project.slug,
  68. });
  69. render(
  70. <ProjectSourceMapsArtifacts
  71. location={routerContext.context.location}
  72. project={project}
  73. route={route}
  74. routeParams={{orgId: organization.slug, projectId: project.slug}}
  75. router={router}
  76. routes={[]}
  77. params={{
  78. orgId: organization.slug,
  79. projectId: project.slug,
  80. bundleId: 'bea7335dfaebc0ca6e65a057',
  81. }}
  82. />,
  83. {context: routerContext, organization}
  84. );
  85. // Title
  86. expect(screen.getByRole('heading')).toHaveTextContent('Release Bundle');
  87. // Subtitle
  88. expect(screen.getByText('bea7335dfaebc0ca6e65a057')).toBeInTheDocument();
  89. // Search bar
  90. expect(screen.getByPlaceholderText('Filter by Path')).toBeInTheDocument();
  91. // Path
  92. expect(
  93. await screen.findByText('https://example.com/AcceptOrganizationInvite.js')
  94. ).toBeInTheDocument();
  95. // Time
  96. expect(screen.getByText(/in 3 year/)).toBeInTheDocument();
  97. // File size
  98. expect(screen.getByText('8.1 KiB')).toBeInTheDocument();
  99. // Chip
  100. await userEvent.hover(screen.getByText('none'));
  101. expect(await screen.findByText('No distribution set')).toBeInTheDocument();
  102. // Download button
  103. expect(screen.getByRole('button', {name: 'Download Artifact'})).toHaveAttribute(
  104. 'href',
  105. '/projects/org-slug/project-slug/releases/bea7335dfaebc0ca6e65a057/files/5678/?download=1'
  106. );
  107. });
  108. it('renders empty state', async function () {
  109. const {organization, route, project, router, routerContext} = initializeOrg({
  110. ...initializeOrg(),
  111. router: {
  112. location: {
  113. query: {},
  114. },
  115. params: {},
  116. },
  117. });
  118. renderReleaseBundlesMockRequests({
  119. orgSlug: organization.slug,
  120. projectSlug: project.slug,
  121. empty: true,
  122. });
  123. render(
  124. <ProjectSourceMapsArtifacts
  125. location={routerContext.context.location}
  126. project={project}
  127. route={route}
  128. routeParams={{orgId: organization.slug, projectId: project.slug}}
  129. router={router}
  130. routes={[]}
  131. params={{
  132. orgId: organization.slug,
  133. projectId: project.slug,
  134. bundleId: 'bea7335dfaebc0ca6e65a057',
  135. }}
  136. />,
  137. {context: routerContext, organization}
  138. );
  139. expect(
  140. await screen.findByText('There are no artifacts in this archive.')
  141. ).toBeInTheDocument();
  142. });
  143. });
  144. describe('Artifact Bundles', function () {
  145. it('renders default state', async function () {
  146. const {organization, route, project, router, routerContext} = initializeOrg({
  147. ...initializeOrg(),
  148. router: {
  149. location: {
  150. pathname: `/settings/${initializeOrg().organization.slug}/projects/${
  151. initializeOrg().project.slug
  152. }/source-maps/artifact-bundles/7227e105-744e-4066-8c69-3e5e344723fc/`,
  153. query: {},
  154. },
  155. params: {},
  156. },
  157. });
  158. ConfigStore.config = {
  159. ...ConfigStore.config,
  160. user: {...ConfigStore.config.user, isSuperuser: true},
  161. };
  162. renderDebugIdBundlesMockRequests({
  163. orgSlug: organization.slug,
  164. projectSlug: project.slug,
  165. });
  166. render(
  167. <ProjectSourceMapsArtifacts
  168. location={routerContext.context.location}
  169. project={project}
  170. route={route}
  171. routeParams={{orgId: organization.slug, projectId: project.slug}}
  172. router={router}
  173. routes={[]}
  174. params={{
  175. orgId: organization.slug,
  176. projectId: project.slug,
  177. bundleId: '7227e105-744e-4066-8c69-3e5e344723fc',
  178. }}
  179. />,
  180. {context: routerContext, organization}
  181. );
  182. // Title
  183. expect(screen.getByRole('heading')).toHaveTextContent('Artifact Bundle');
  184. // Subtitle
  185. expect(
  186. screen.getByText('7227e105-744e-4066-8c69-3e5e344723fc')
  187. ).toBeInTheDocument();
  188. // Chips
  189. await userEvent.hover(await screen.findByText('2.0'));
  190. expect(
  191. await screen.findByText('Associated with release "2.0"')
  192. ).toBeInTheDocument();
  193. await userEvent.hover(await screen.findByText('android'));
  194. expect(
  195. await screen.findByText('Associated with distribution "android"')
  196. ).toBeInTheDocument();
  197. // Search bar
  198. expect(screen.getByPlaceholderText('Filter by Path or ID')).toBeInTheDocument();
  199. // Path
  200. expect(await screen.findByText('files/_/_/main.js')).toBeInTheDocument();
  201. // Debug Id
  202. expect(
  203. screen.getByText('69ac68eb-cc62-44c0-a5dc-b67f219a3696')
  204. ).toBeInTheDocument();
  205. // Type
  206. expect(screen.getByText('Minified')).toBeInTheDocument();
  207. // Download Button
  208. expect(screen.getByRole('button', {name: 'Download Artifact'})).toHaveAttribute(
  209. 'href',
  210. '/projects/org-slug/project-slug/artifact-bundles/7227e105-744e-4066-8c69-3e5e344723fc/files/ZmlsZXMvXy9fL21haW4uanM=/?download=1'
  211. );
  212. });
  213. it('renders empty state', async function () {
  214. const {organization, route, project, router, routerContext} = initializeOrg({
  215. ...initializeOrg(),
  216. router: {
  217. location: {
  218. pathname: `/settings/${initializeOrg().organization.slug}/projects/${
  219. initializeOrg().project.slug
  220. }/source-maps/artifact-bundles/7227e105-744e-4066-8c69-3e5e344723fc/`,
  221. query: {},
  222. },
  223. params: {},
  224. },
  225. });
  226. renderDebugIdBundlesMockRequests({
  227. orgSlug: organization.slug,
  228. projectSlug: project.slug,
  229. empty: true,
  230. });
  231. render(
  232. <ProjectSourceMapsArtifacts
  233. location={routerContext.context.location}
  234. project={project}
  235. route={route}
  236. routeParams={{orgId: organization.slug, projectId: project.slug}}
  237. router={router}
  238. routes={[]}
  239. params={{
  240. orgId: organization.slug,
  241. projectId: project.slug,
  242. bundleId: '7227e105-744e-4066-8c69-3e5e344723fc',
  243. }}
  244. />,
  245. {context: routerContext, organization}
  246. );
  247. expect(
  248. await screen.findByText('There are no artifacts in this bundle.')
  249. ).toBeInTheDocument();
  250. });
  251. });
  252. });