organizationApiKeysView.spec.jsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import PropTypes from 'prop-types';
  2. import React from 'react';
  3. import {mount} from 'enzyme';
  4. import {Client} from 'app/api';
  5. import OrganizationApiKeysView from 'app/views/settings/organization/apiKeys/organizationApiKeysView';
  6. const childContextTypes = {
  7. organization: PropTypes.object,
  8. router: PropTypes.object,
  9. location: PropTypes.object,
  10. };
  11. const routes = [
  12. {path: '/'},
  13. {path: '/:orgId/'},
  14. {path: '/organizations/:orgId/'},
  15. {path: 'api-keys/', name: 'API Key'},
  16. ];
  17. describe('OrganizationApiKeysView', function() {
  18. beforeEach(function() {
  19. Client.clearMockResponses();
  20. Client.addMockResponse({
  21. url: '/organizations/org-slug/api-keys/',
  22. method: 'GET',
  23. body: [TestStubs.ApiKey()],
  24. });
  25. Client.addMockResponse({
  26. url: '/organizations/org-slug/api-keys/1/',
  27. method: 'GET',
  28. body: TestStubs.ApiKey(),
  29. });
  30. Client.addMockResponse({
  31. url: '/organizations/org-slug/api-keys/1/',
  32. method: 'DELETE',
  33. });
  34. });
  35. it('fetches api keys', function() {
  36. let wrapper = mount(
  37. <OrganizationApiKeysView
  38. location={TestStubs.location()}
  39. params={{orgId: 'org-slug'}}
  40. routes={routes}
  41. />,
  42. {
  43. context: {
  44. router: TestStubs.router(),
  45. organization: TestStubs.Organization(),
  46. location: TestStubs.location(),
  47. },
  48. childContextTypes,
  49. }
  50. );
  51. expect(wrapper.state('keys')).toEqual([TestStubs.ApiKey()]);
  52. });
  53. it('can delete a key', function() {
  54. let wrapper = mount(
  55. <OrganizationApiKeysView
  56. location={TestStubs.location()}
  57. params={{orgId: 'org-slug'}}
  58. routes={routes}
  59. />,
  60. {
  61. context: {
  62. router: TestStubs.router(),
  63. organization: TestStubs.Organization(),
  64. location: TestStubs.location(),
  65. },
  66. childContextTypes,
  67. }
  68. );
  69. // OrganizationApiKeysView.handleRemove = jest.fn();
  70. // expect(OrganizationApiKeysView.handleRemove).not.toHaveBeenCalled();
  71. wrapper.instance().handleRemove(1);
  72. expect(wrapper.state('keys')).toEqual([]);
  73. });
  74. });