projectPluginsRow.spec.jsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import ProjectPluginRow from 'sentry/views/settings/projectPlugins/projectPluginRow';
  3. describe('ProjectPluginRow', function () {
  4. let wrapper;
  5. const plugin = TestStubs.Plugin();
  6. const org = TestStubs.Organization({access: ['project:write']});
  7. const project = TestStubs.Project();
  8. const params = {orgId: org.slug, projectId: project.slug};
  9. const routerContext = TestStubs.routerContext([{organization: org, project}]);
  10. it('renders', function () {
  11. wrapper = mountWithTheme(
  12. <ProjectPluginRow {...params} {...plugin} project={project} />,
  13. routerContext
  14. );
  15. expect(wrapper).toSnapshot();
  16. });
  17. it('calls `onChange` when clicked', function () {
  18. const onChange = jest.fn();
  19. wrapper = mountWithTheme(
  20. <ProjectPluginRow {...params} {...plugin} onChange={onChange} project={project} />,
  21. routerContext
  22. );
  23. expect(onChange).not.toHaveBeenCalled();
  24. wrapper.find('Switch').simulate('click');
  25. expect(onChange).toHaveBeenCalledWith('amazon-sqs', true);
  26. });
  27. it('can not enable/disable or configure plugin without `project:write`', function () {
  28. const onChange = jest.fn();
  29. wrapper = mountWithTheme(
  30. <ProjectPluginRow {...params} {...plugin} onChange={onChange} project={project} />,
  31. TestStubs.routerContext([{organization: TestStubs.Organization({access: []})}])
  32. );
  33. expect(onChange).not.toHaveBeenCalled();
  34. wrapper.find('Switch').simulate('click');
  35. expect(onChange).not.toHaveBeenCalled();
  36. });
  37. });