projectPluginRow.spec.tsx 1.6 KB

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