projectKeys.spec.jsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import PropTypes from 'prop-types';
  2. import React from 'react';
  3. import {mount} from 'enzyme';
  4. import ProjectKeys from 'app/views/settings/project/projectKeys';
  5. describe('ProjectKeys', function() {
  6. let org, project, wrapper;
  7. let deleteMock;
  8. let projectKeys;
  9. beforeEach(function() {
  10. org = TestStubs.Organization();
  11. project = TestStubs.Project();
  12. projectKeys = TestStubs.ProjectKeys();
  13. MockApiClient.clearMockResponses();
  14. MockApiClient.addMockResponse({
  15. url: `/projects/${org.slug}/${project.slug}/keys/`,
  16. method: 'GET',
  17. body: projectKeys,
  18. });
  19. deleteMock = MockApiClient.addMockResponse({
  20. url: `/projects/${org.slug}/${project.slug}/keys/${projectKeys[0].id}/`,
  21. method: 'DELETE',
  22. });
  23. let routerContext = TestStubs.routerContext();
  24. wrapper = mount(
  25. <ProjectKeys routes={[]} params={{orgId: org.slug, projectId: project.slug}} />,
  26. {
  27. ...routerContext,
  28. context: {
  29. ...routerContext.context,
  30. project: TestStubs.Project(),
  31. },
  32. childContextTypes: {
  33. ...routerContext.childContextTypes,
  34. project: PropTypes.object,
  35. },
  36. }
  37. );
  38. });
  39. it('renders empty', function() {
  40. MockApiClient.clearMockResponses();
  41. MockApiClient.addMockResponse({
  42. url: `/projects/${org.slug}/${project.slug}/keys/`,
  43. method: 'GET',
  44. body: [],
  45. });
  46. wrapper = mount(
  47. <ProjectKeys routes={[]} params={{orgId: org.slug, projectId: project.slug}} />,
  48. TestStubs.routerContext()
  49. );
  50. expect(wrapper.find('EmptyMessage')).toHaveLength(1);
  51. });
  52. it('has clippable box', function() {
  53. expect(wrapper.find('.clip-fade .btn')).toHaveLength(1);
  54. wrapper.find('.clip-fade .btn').simulate('click');
  55. expect(wrapper.find('.clip-fade .btn')).toHaveLength(0);
  56. });
  57. it('deletes key', function() {
  58. wrapper
  59. .find('PanelHeader Button')
  60. .last()
  61. .simulate('click');
  62. wrapper.find('ModalDialog Button[priority="danger"]').simulate('click');
  63. wrapper.update();
  64. expect(deleteMock).toHaveBeenCalled();
  65. });
  66. it('disable and enables key', function() {
  67. let enableMock = MockApiClient.addMockResponse({
  68. url: `/projects/${org.slug}/${project.slug}/keys/${projectKeys[0].id}/`,
  69. method: 'PUT',
  70. });
  71. wrapper
  72. .find('PanelHeader Button')
  73. .at(1)
  74. .simulate('click');
  75. expect(enableMock).toHaveBeenCalledWith(
  76. expect.anything(),
  77. expect.objectContaining({
  78. data: {isActive: false},
  79. })
  80. );
  81. wrapper
  82. .find('PanelHeader Button')
  83. .at(1)
  84. .simulate('click');
  85. expect(enableMock).toHaveBeenCalledWith(
  86. expect.anything(),
  87. expect.objectContaining({
  88. data: {isActive: true},
  89. })
  90. );
  91. });
  92. });