projectPluginRow.spec.tsx 1.4 KB

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