projectPluginRow.spec.jsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import ProjectPluginRow from 'sentry/views/settings/projectPlugins/projectPluginRow';
  3. describe('ProjectPluginRow', function () {
  4. const plugin = TestStubs.Plugin();
  5. const org = TestStubs.Organization({access: ['project:write']});
  6. const project = TestStubs.Project();
  7. const params = {orgId: org.slug, projectId: project.slug};
  8. const routerContext = TestStubs.routerContext([{organization: org, project}]);
  9. it('renders', function () {
  10. const {container} = render(
  11. <ProjectPluginRow {...params} {...plugin} project={project} />,
  12. {
  13. context: routerContext,
  14. }
  15. );
  16. expect(container).toSnapshot();
  17. });
  18. it('calls `onChange` when clicked', function () {
  19. const onChange = jest.fn();
  20. render(
  21. <ProjectPluginRow {...params} {...plugin} onChange={onChange} project={project} />,
  22. {context: routerContext}
  23. );
  24. userEvent.click(screen.getByRole('checkbox'));
  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. render(
  30. <ProjectPluginRow {...params} {...plugin} onChange={onChange} project={project} />,
  31. {
  32. context: TestStubs.routerContext([
  33. {organization: TestStubs.Organization({access: []})},
  34. ]),
  35. }
  36. );
  37. userEvent.click(screen.getByRole('checkbox'));
  38. expect(onChange).not.toHaveBeenCalled();
  39. });
  40. });