organizationApiKeysView.spec.jsx 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import React from 'react';
  2. import {mount} from 'enzyme';
  3. import {Client} from 'app/api';
  4. import OrganizationApiKeys from 'app/views/settings/organizationApiKeys';
  5. const routes = [
  6. {path: '/'},
  7. {path: '/:orgId/'},
  8. {path: '/organizations/:orgId/'},
  9. {path: 'api-keys/', name: 'API Key'},
  10. ];
  11. describe('OrganizationApiKeys', function() {
  12. const routerContext = TestStubs.routerContext();
  13. beforeEach(function() {
  14. Client.clearMockResponses();
  15. Client.addMockResponse({
  16. url: '/organizations/org-slug/api-keys/',
  17. method: 'GET',
  18. body: [TestStubs.ApiKey()],
  19. });
  20. Client.addMockResponse({
  21. url: '/organizations/org-slug/api-keys/1/',
  22. method: 'GET',
  23. body: TestStubs.ApiKey(),
  24. });
  25. Client.addMockResponse({
  26. url: '/organizations/org-slug/api-keys/1/',
  27. method: 'DELETE',
  28. });
  29. });
  30. it('fetches api keys', function() {
  31. const wrapper = mount(
  32. <OrganizationApiKeys
  33. location={TestStubs.location()}
  34. params={{orgId: 'org-slug'}}
  35. routes={routes}
  36. />,
  37. routerContext
  38. );
  39. expect(wrapper.state('keys')).toEqual([TestStubs.ApiKey()]);
  40. });
  41. it('can delete a key', function() {
  42. const wrapper = mount(
  43. <OrganizationApiKeys
  44. location={TestStubs.location()}
  45. params={{orgId: 'org-slug'}}
  46. routes={routes}
  47. />,
  48. routerContext
  49. );
  50. // OrganizationApiKeys.handleRemove = jest.fn();
  51. // expect(OrganizationApiKeys.handleRemove).not.toHaveBeenCalled();
  52. wrapper.instance().handleRemove(1);
  53. expect(wrapper.state('keys')).toEqual([]);
  54. });
  55. });