apiApplications.spec.jsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {initializeOrg} from 'sentry-test/initializeOrg';
  3. import ApiApplications from 'sentry/views/settings/account/apiApplications';
  4. describe('ApiApplications', function () {
  5. let requestMock;
  6. let wrapper;
  7. const {router, routerContext} = initializeOrg();
  8. const createWrapper = props => {
  9. wrapper = mountWithTheme(
  10. <ApiApplications {...props} router={router} />,
  11. routerContext
  12. );
  13. };
  14. beforeEach(function () {
  15. MockApiClient.clearMockResponses();
  16. requestMock = MockApiClient.addMockResponse({
  17. url: '/api-applications/',
  18. body: [TestStubs.ApiApplication()],
  19. });
  20. });
  21. afterEach(function () {
  22. if (wrapper) {
  23. wrapper.unmount();
  24. wrapper = null;
  25. }
  26. });
  27. it('renders empty', function () {
  28. requestMock = MockApiClient.addMockResponse({
  29. url: '/api-applications/',
  30. body: [],
  31. });
  32. createWrapper();
  33. expect(wrapper.find('EmptyMessage')).toHaveLength(1);
  34. });
  35. it('renders', function () {
  36. createWrapper();
  37. expect(requestMock).toHaveBeenCalled();
  38. expect(wrapper.find('Row')).toHaveLength(1);
  39. });
  40. it('creates application', async function () {
  41. const createApplicationRequest = MockApiClient.addMockResponse({
  42. url: '/api-applications/',
  43. body: TestStubs.ApiApplication({
  44. id: '234',
  45. }),
  46. method: 'POST',
  47. });
  48. createWrapper();
  49. wrapper.find('button[aria-label="Create New Application"]').simulate('click');
  50. await tick();
  51. expect(createApplicationRequest).toHaveBeenCalledWith(
  52. '/api-applications/',
  53. expect.objectContaining({method: 'POST'})
  54. );
  55. expect(router.push).toHaveBeenLastCalledWith(
  56. '/settings/account/api/applications/234/'
  57. );
  58. });
  59. it('deletes application', async function () {
  60. const deleteApplicationRequest = MockApiClient.addMockResponse({
  61. url: '/api-applications/123/',
  62. method: 'DELETE',
  63. });
  64. createWrapper();
  65. wrapper.find('button[aria-label="Remove"]').simulate('click');
  66. await tick();
  67. wrapper.update();
  68. expect(deleteApplicationRequest).toHaveBeenCalledWith(
  69. '/api-applications/123/',
  70. expect.objectContaining({method: 'DELETE'})
  71. );
  72. expect(wrapper.find('EmptyMessage')).toHaveLength(1);
  73. });
  74. });