index.spec.jsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import {initializeOrg} from 'sentry-test/initializeOrg';
  2. import {
  3. render,
  4. renderGlobalModal,
  5. screen,
  6. userEvent,
  7. } from 'sentry-test/reactTestingLibrary';
  8. import ProjectSourceMaps from 'sentry/views/settings/projectSourceMaps/list';
  9. describe('ProjectSourceMaps', function () {
  10. const {organization, project, routerContext, router} = initializeOrg({});
  11. const endpoint = `/projects/${organization.slug}/${project.slug}/files/source-maps/`;
  12. const props = {
  13. organization,
  14. project,
  15. params: {orgId: organization.slug, projectId: project.slug},
  16. location: routerContext.context.location,
  17. router,
  18. };
  19. afterEach(() => {
  20. MockApiClient.clearMockResponses();
  21. });
  22. it('renders', function () {
  23. MockApiClient.addMockResponse({
  24. url: endpoint,
  25. body: [
  26. TestStubs.SourceMapArchive(),
  27. TestStubs.SourceMapArchive({id: 2, name: 'abc'}),
  28. ],
  29. });
  30. render(<ProjectSourceMaps {...props} />);
  31. const rows = screen.getAllByLabelText('Remove All Artifacts');
  32. expect(rows).toHaveLength(2);
  33. expect(screen.getByText('1234')).toBeInTheDocument();
  34. });
  35. it('renders empty', function () {
  36. MockApiClient.addMockResponse({
  37. url: endpoint,
  38. body: [],
  39. });
  40. render(<ProjectSourceMaps {...props} />);
  41. expect(
  42. screen.getByText('There are no archives for this project.')
  43. ).toBeInTheDocument();
  44. });
  45. it('deletes the archive', async function () {
  46. const archive = TestStubs.SourceMapArchive();
  47. MockApiClient.addMockResponse({
  48. url: endpoint,
  49. body: [archive],
  50. });
  51. const deleteMock = MockApiClient.addMockResponse({
  52. method: 'DELETE',
  53. url: endpoint,
  54. });
  55. render(<ProjectSourceMaps {...props} />);
  56. renderGlobalModal();
  57. await userEvent.click(screen.getByRole('button', {name: 'Remove All Artifacts'}));
  58. // Confirm Modal
  59. await userEvent.click(screen.getByRole('button', {name: 'Confirm'}));
  60. expect(deleteMock).toHaveBeenCalledWith(
  61. endpoint,
  62. expect.objectContaining({query: {name: archive.name}})
  63. );
  64. });
  65. it('filters archives', async function () {
  66. const mockRouter = {push: jest.fn()};
  67. const mock = MockApiClient.addMockResponse({
  68. url: endpoint,
  69. body: [],
  70. });
  71. render(
  72. <ProjectSourceMaps
  73. {...props}
  74. location={{query: {query: 'abc'}}}
  75. router={mockRouter}
  76. />
  77. );
  78. expect(mock).toHaveBeenCalledWith(
  79. endpoint,
  80. expect.objectContaining({
  81. query: {query: 'abc'},
  82. })
  83. );
  84. const filterInput = screen.getByPlaceholderText('Filter Archives');
  85. await userEvent.clear(filterInput);
  86. await userEvent.type(filterInput, 'defg{enter}');
  87. expect(mockRouter.push).toHaveBeenCalledWith({
  88. query: {cursor: undefined, query: 'defg'},
  89. });
  90. });
  91. });