apiApplications.spec.jsx 2.1 KB

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