index.spec.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. it('renders empty', function () {
  6. const {router} = initializeOrg();
  7. MockApiClient.addMockResponse({
  8. url: '/api-applications/',
  9. body: [],
  10. });
  11. render(
  12. <ApiApplications
  13. router={router}
  14. params={{}}
  15. location={router.location}
  16. routes={router.routes}
  17. route={{}}
  18. routeParams={{}}
  19. />
  20. );
  21. expect(
  22. screen.getByText("You haven't created any applications yet.")
  23. ).toBeInTheDocument();
  24. });
  25. it('renders', function () {
  26. const {router} = initializeOrg();
  27. const requestMock = MockApiClient.addMockResponse({
  28. url: '/api-applications/',
  29. body: [TestStubs.ApiApplication()],
  30. });
  31. render(
  32. <ApiApplications
  33. router={router}
  34. params={{}}
  35. location={router.location}
  36. routes={router.routes}
  37. route={{}}
  38. routeParams={{}}
  39. />
  40. );
  41. expect(requestMock).toHaveBeenCalled();
  42. expect(screen.getByText('Adjusted Shrimp')).toBeInTheDocument();
  43. });
  44. it('creates application', async function () {
  45. const {router} = initializeOrg();
  46. const createApplicationRequest = MockApiClient.addMockResponse({
  47. url: '/api-applications/',
  48. body: TestStubs.ApiApplication({
  49. id: '234',
  50. }),
  51. method: 'POST',
  52. });
  53. render(
  54. <ApiApplications
  55. router={router}
  56. params={{}}
  57. location={router.location}
  58. routes={router.routes}
  59. route={{}}
  60. routeParams={{}}
  61. />
  62. );
  63. userEvent.click(screen.getByLabelText('Create New Application'));
  64. expect(createApplicationRequest).toHaveBeenCalledWith(
  65. '/api-applications/',
  66. expect.objectContaining({method: 'POST'})
  67. );
  68. await waitFor(() => {
  69. expect(router.push).toHaveBeenLastCalledWith(
  70. '/settings/account/api/applications/234/'
  71. );
  72. });
  73. });
  74. it('deletes application', async function () {
  75. const deleteApplicationRequest = MockApiClient.addMockResponse({
  76. url: '/api-applications/123/',
  77. method: 'DELETE',
  78. });
  79. const {router} = initializeOrg();
  80. render(
  81. <ApiApplications
  82. router={router}
  83. params={{}}
  84. location={router.location}
  85. routes={router.routes}
  86. route={{}}
  87. routeParams={{}}
  88. />
  89. );
  90. userEvent.click(screen.getByLabelText('Remove'));
  91. expect(deleteApplicationRequest).toHaveBeenCalledWith(
  92. '/api-applications/123/',
  93. expect.objectContaining({method: 'DELETE'})
  94. );
  95. await waitFor(() => {
  96. expect(
  97. screen.getByText("You haven't created any applications yet.")
  98. ).toBeInTheDocument();
  99. });
  100. });
  101. });