projectPluginRow.spec.tsx 1.5 KB

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