projectPluginRow.spec.tsx 1.6 KB

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