index.spec.tsx 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import {ApiApplicationFixture} from 'sentry-fixture/apiApplication';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  4. import ApiApplications from 'sentry/views/settings/account/apiApplications';
  5. describe('ApiApplications', function () {
  6. const {routerProps, router} = initializeOrg({router: {params: {}}});
  7. beforeEach(function () {
  8. MockApiClient.clearMockResponses();
  9. });
  10. it('renders empty', function () {
  11. MockApiClient.addMockResponse({
  12. url: '/api-applications/',
  13. body: [],
  14. });
  15. render(<ApiApplications {...routerProps} />);
  16. expect(
  17. screen.getByText("You haven't created any applications yet.")
  18. ).toBeInTheDocument();
  19. });
  20. it('renders', function () {
  21. const requestMock = MockApiClient.addMockResponse({
  22. url: '/api-applications/',
  23. body: [ApiApplicationFixture()],
  24. });
  25. render(<ApiApplications {...routerProps} />);
  26. expect(requestMock).toHaveBeenCalled();
  27. expect(screen.getByText('Adjusted Shrimp')).toBeInTheDocument();
  28. });
  29. it('creates application', async function () {
  30. MockApiClient.addMockResponse({
  31. url: '/api-applications/',
  32. body: [],
  33. });
  34. const createApplicationRequest = MockApiClient.addMockResponse({
  35. url: '/api-applications/',
  36. body: ApiApplicationFixture({
  37. id: '234',
  38. }),
  39. method: 'POST',
  40. });
  41. render(<ApiApplications {...routerProps} />);
  42. await userEvent.click(screen.getByLabelText('Create New Application'));
  43. expect(createApplicationRequest).toHaveBeenCalledWith(
  44. '/api-applications/',
  45. expect.objectContaining({method: 'POST'})
  46. );
  47. await waitFor(() => {
  48. expect(router.push).toHaveBeenLastCalledWith(
  49. '/settings/account/api/applications/234/'
  50. );
  51. });
  52. });
  53. it('deletes application', async function () {
  54. MockApiClient.addMockResponse({
  55. url: '/api-applications/',
  56. body: [ApiApplicationFixture({id: '123'})],
  57. });
  58. const deleteApplicationRequest = MockApiClient.addMockResponse({
  59. url: '/api-applications/123/',
  60. method: 'DELETE',
  61. });
  62. render(<ApiApplications {...routerProps} />);
  63. await userEvent.click(screen.getByLabelText('Remove'));
  64. expect(deleteApplicationRequest).toHaveBeenCalledWith(
  65. '/api-applications/123/',
  66. expect.objectContaining({method: 'DELETE'})
  67. );
  68. await waitFor(() => {
  69. expect(
  70. screen.getByText("You haven't created any applications yet.")
  71. ).toBeInTheDocument();
  72. });
  73. });
  74. });