index.spec.jsx 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import {disablePlugin, enablePlugin, fetchPlugins} from 'sentry/actionCreators/plugins';
  3. import ProjectPlugins from 'sentry/views/settings/projectPlugins';
  4. jest.mock('sentry/actionCreators/plugins', () => ({
  5. fetchPlugins: jest.fn().mockResolvedValue([]),
  6. enablePlugin: jest.fn(),
  7. disablePlugin: jest.fn(),
  8. }));
  9. describe('ProjectPluginsContainer', function () {
  10. let org, project, plugins, wrapper, params, organization;
  11. beforeEach(function () {
  12. org = TestStubs.Organization();
  13. project = TestStubs.Project();
  14. plugins = TestStubs.Plugins();
  15. params = {
  16. orgId: org.slug,
  17. projectId: project.slug,
  18. };
  19. organization = {
  20. id: org.slug,
  21. features: [],
  22. };
  23. MockApiClient.addMockResponse({
  24. url: `/organizations/${org.slug}/`,
  25. method: 'GET',
  26. body: org,
  27. });
  28. MockApiClient.addMockResponse({
  29. url: `/organizations/${org.slug}/integrations/`,
  30. method: 'GET',
  31. body: [],
  32. });
  33. MockApiClient.addMockResponse({
  34. url: `/projects/${org.slug}/${project.slug}/plugins/`,
  35. method: 'GET',
  36. body: plugins,
  37. });
  38. MockApiClient.addMockResponse({
  39. url: `/projects/${org.slug}/${project.slug}/plugins/amazon-sqs/`,
  40. method: 'POST',
  41. });
  42. MockApiClient.addMockResponse({
  43. url: `/projects/${org.slug}/${project.slug}/plugins/github/`,
  44. method: 'DELETE',
  45. });
  46. wrapper = mountWithTheme(
  47. <ProjectPlugins params={params} organization={organization} />
  48. );
  49. });
  50. it('calls `fetchPlugins` action creator after mount', function () {
  51. expect(fetchPlugins).toHaveBeenCalled();
  52. });
  53. it('calls `enablePlugin` action creator when enabling plugin', function () {
  54. const onChange = wrapper.find('ProjectPlugins').prop('onChange');
  55. expect(enablePlugin).not.toHaveBeenCalled();
  56. onChange('pluginId', true);
  57. expect(enablePlugin).toHaveBeenCalled();
  58. });
  59. it('calls `disablePlugin` action creator when disabling plugin', function () {
  60. const onChange = wrapper.find('ProjectPlugins').prop('onChange');
  61. expect(disablePlugin).not.toHaveBeenCalled();
  62. onChange('pluginId', false);
  63. expect(disablePlugin).toHaveBeenCalled();
  64. });
  65. });