index.spec.tsx 2.9 KB

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