index.spec.tsx 2.5 KB

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