projectPluginRow.spec.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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', async function () {
  19. const onChange = jest.fn();
  20. render(
  21. <ProjectPluginRow {...params} {...plugin} onChange={onChange} project={project} />,
  22. {context: routerContext}
  23. );
  24. await 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`', async function () {
  28. const onChange = jest.fn();
  29. render(
  30. <ProjectPluginRow {...params} {...plugin} onChange={onChange} project={project} />,
  31. {
  32. organization: TestStubs.Organization({access: []}),
  33. }
  34. );
  35. await userEvent.click(screen.getByRole('checkbox'));
  36. expect(onChange).not.toHaveBeenCalled();
  37. });
  38. });