index.spec.jsx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {
  3. render,
  4. renderGlobalModal,
  5. screen,
  6. userEvent,
  7. } from 'sentry-test/reactTestingLibrary';
  8. import ProjectSourceMapsDetail from 'sentry/views/settings/projectSourceMaps/detail';
  9. describe('ProjectSourceMapsDetail', () => {
  10. const {organization, project, routerContext, router} = initializeOrg({});
  11. const archiveName = '1234';
  12. const endpoint = `/projects/${organization.slug}/${project.slug}/releases/${archiveName}/files/`;
  13. const props = {
  14. organization,
  15. project,
  16. params: {projectId: project.slug, name: archiveName},
  17. location: routerContext.context.location,
  18. router,
  19. };
  20. afterEach(() => {
  21. MockApiClient.clearMockResponses();
  22. });
  23. it('renders', () => {
  24. MockApiClient.addMockResponse({
  25. url: endpoint,
  26. body: [
  27. TestStubs.SourceMapArtifact(),
  28. TestStubs.SourceMapArtifact({name: 'abc', id: '2'}),
  29. ],
  30. });
  31. render(<ProjectSourceMapsDetail {...props} />);
  32. const items = screen.getAllByRole('button', {name: 'Remove Artifact'});
  33. expect(items).toHaveLength(2);
  34. expect(screen.getByText('abc')).toBeInTheDocument();
  35. });
  36. it('renders empty', () => {
  37. MockApiClient.addMockResponse({
  38. url: endpoint,
  39. body: [],
  40. });
  41. render(<ProjectSourceMapsDetail {...props} />);
  42. expect(
  43. screen.getByText('There are no artifacts in this archive.')
  44. ).toBeInTheDocument();
  45. });
  46. it('links to release', () => {
  47. MockApiClient.addMockResponse({
  48. url: endpoint,
  49. body: [],
  50. });
  51. render(<ProjectSourceMapsDetail {...props} />, {context: routerContext});
  52. expect(screen.getByRole('button', {name: 'Go to Release'})).toHaveAttribute(
  53. 'href',
  54. `/organizations/${organization.slug}/releases/${archiveName}/?project=${project.id}`
  55. );
  56. });
  57. it('deletes all artifacts', () => {
  58. MockApiClient.addMockResponse({
  59. url: endpoint,
  60. body: [],
  61. });
  62. const archiveDeleteEndpoint = `/projects/${organization.slug}/${project.slug}/files/source-maps/`;
  63. const deleteMock = MockApiClient.addMockResponse({
  64. method: 'DELETE',
  65. url: archiveDeleteEndpoint,
  66. });
  67. render(<ProjectSourceMapsDetail {...props} />);
  68. renderGlobalModal();
  69. userEvent.click(screen.getByRole('button', {name: 'Remove All Artifacts'}));
  70. // Confirm Modal
  71. userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
  72. expect(deleteMock).toHaveBeenCalledWith(
  73. archiveDeleteEndpoint,
  74. expect.objectContaining({
  75. query: {name: archiveName},
  76. })
  77. );
  78. });
  79. it('filters artifacts', () => {
  80. const mockRouter = {push: jest.fn()};
  81. const mock = MockApiClient.addMockResponse({
  82. url: endpoint,
  83. body: [],
  84. });
  85. render(
  86. <ProjectSourceMapsDetail
  87. {...props}
  88. location={{query: {query: 'abc'}}}
  89. router={mockRouter}
  90. />
  91. );
  92. expect(mock).toHaveBeenCalledWith(
  93. endpoint,
  94. expect.objectContaining({
  95. query: {query: 'abc'},
  96. })
  97. );
  98. const filterInput = screen.getByPlaceholderText('Filter artifacts');
  99. userEvent.clear(filterInput);
  100. userEvent.type(filterInput, 'defg{enter}');
  101. expect(mockRouter.push).toHaveBeenCalledWith({
  102. query: {cursor: undefined, query: 'defg'},
  103. });
  104. });
  105. it('deletes single artifact', () => {
  106. const artifact = TestStubs.SourceMapArtifact();
  107. MockApiClient.addMockResponse({
  108. url: endpoint,
  109. body: [artifact],
  110. });
  111. const deleteMock = MockApiClient.addMockResponse({
  112. method: 'DELETE',
  113. url: `${endpoint}${artifact.id}/`,
  114. });
  115. render(<ProjectSourceMapsDetail {...props} />);
  116. renderGlobalModal();
  117. userEvent.click(screen.getByRole('button', {name: 'Remove Artifact'}));
  118. // Confirm Modal
  119. userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
  120. expect(deleteMock).toHaveBeenCalled();
  121. });
  122. });