index.spec.jsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import * as PropTypes from 'prop-types';
  2. import {mountWithTheme} from 'sentry-test/enzyme';
  3. import {mountGlobalModal} from 'sentry-test/modal';
  4. import ProjectKeys from 'sentry/views/settings/project/projectKeys/list';
  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. wrapper = mountWithTheme(
  24. <ProjectKeys routes={[]} params={{orgId: org.slug, projectId: project.slug}} />,
  25. {
  26. context: {
  27. project: TestStubs.Project(),
  28. },
  29. childContextTypes: {
  30. project: PropTypes.object,
  31. },
  32. }
  33. );
  34. });
  35. it('renders empty', function () {
  36. MockApiClient.clearMockResponses();
  37. MockApiClient.addMockResponse({
  38. url: `/projects/${org.slug}/${project.slug}/keys/`,
  39. method: 'GET',
  40. body: [],
  41. });
  42. wrapper = mountWithTheme(
  43. <ProjectKeys routes={[]} params={{orgId: org.slug, projectId: project.slug}} />
  44. );
  45. expect(wrapper.find('EmptyMessage')).toHaveLength(1);
  46. });
  47. it('has clippable box', function () {
  48. const clipFade = wrapper.find('ClipFade');
  49. expect(clipFade).toHaveLength(1);
  50. const clipFadeButton = clipFade.find('button');
  51. expect(clipFadeButton).toHaveLength(1);
  52. clipFadeButton.simulate('click');
  53. expect(wrapper.find('ClipFade button')).toHaveLength(0);
  54. });
  55. it('deletes key', async function () {
  56. wrapper.find('PanelHeader Button').last().simulate('click');
  57. // Confirm modal
  58. const modal = await mountGlobalModal();
  59. modal.find('Button[priority="danger"]').simulate('click');
  60. expect(deleteMock).toHaveBeenCalled();
  61. });
  62. it('disable and enables key', function () {
  63. const enableMock = MockApiClient.addMockResponse({
  64. url: `/projects/${org.slug}/${project.slug}/keys/${projectKeys[0].id}/`,
  65. method: 'PUT',
  66. });
  67. wrapper.find('PanelHeader Button').at(1).simulate('click');
  68. expect(enableMock).toHaveBeenCalledWith(
  69. expect.anything(),
  70. expect.objectContaining({
  71. data: {isActive: false},
  72. })
  73. );
  74. wrapper.find('PanelHeader Button').at(1).simulate('click');
  75. expect(enableMock).toHaveBeenCalledWith(
  76. expect.anything(),
  77. expect.objectContaining({
  78. data: {isActive: true},
  79. })
  80. );
  81. });
  82. });