permissionSelection.spec.jsx 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import selectEvent from 'react-select-event';
  2. import {render, screen} from 'sentry-test/reactTestingLibrary';
  3. import Form from 'sentry/components/forms/form';
  4. import FormModel from 'sentry/components/forms/model';
  5. import ModalStore from 'sentry/stores/modalStore';
  6. import PermissionSelection from 'sentry/views/settings/organizationDeveloperSettings/permissionSelection';
  7. describe('PermissionSelection', () => {
  8. let onChange;
  9. let model;
  10. beforeEach(() => {
  11. model = new FormModel();
  12. onChange = jest.fn();
  13. render(
  14. <Form model={model}>
  15. <PermissionSelection
  16. permissions={{
  17. Event: 'no-access',
  18. Team: 'no-access',
  19. Project: 'write',
  20. Release: 'admin',
  21. Organization: 'admin',
  22. }}
  23. onChange={onChange}
  24. />
  25. </Form>
  26. );
  27. ModalStore.reset();
  28. });
  29. it('renders a row for each resource', () => {
  30. expect(screen.getByRole('textbox', {name: 'Project'})).toBeInTheDocument();
  31. expect(screen.getByRole('textbox', {name: 'Team'})).toBeInTheDocument();
  32. expect(screen.getByRole('textbox', {name: 'Release'})).toBeInTheDocument();
  33. expect(screen.getByRole('textbox', {name: 'Issue & Event'})).toBeInTheDocument();
  34. expect(screen.getByRole('textbox', {name: 'Organization'})).toBeInTheDocument();
  35. expect(screen.getByRole('textbox', {name: 'Member'})).toBeInTheDocument();
  36. });
  37. it('lists human readable permissions', async () => {
  38. const expectOptions = async (name, options) => {
  39. for (const option of options) {
  40. await selectEvent.select(screen.getByRole('textbox', {name}), option);
  41. }
  42. };
  43. await expectOptions('Project', ['No Access', 'Read', 'Read & Write', 'Admin']);
  44. await expectOptions('Team', ['No Access', 'Read', 'Read & Write', 'Admin']);
  45. await expectOptions('Release', ['No Access', 'Admin']);
  46. await expectOptions('Issue & Event', ['No Access', 'Read', 'Read & Write', 'Admin']);
  47. await expectOptions('Organization', ['No Access', 'Read', 'Read & Write', 'Admin']);
  48. await expectOptions('Member', ['No Access', 'Read', 'Read & Write', 'Admin']);
  49. });
  50. it('stores the permissions the User has selected', async () => {
  51. const selectByValue = (name, value) =>
  52. selectEvent.select(screen.getByRole('textbox', {name}), value);
  53. await selectByValue('Project', 'Read & Write');
  54. await selectByValue('Team', 'Read');
  55. await selectByValue('Release', 'Admin');
  56. await selectByValue('Issue & Event', 'Admin');
  57. await selectByValue('Organization', 'Read');
  58. await selectByValue('Member', 'No Access');
  59. expect(model.getValue('Project--permission')).toEqual('write');
  60. expect(model.getValue('Team--permission')).toEqual('read');
  61. expect(model.getValue('Release--permission')).toEqual('admin');
  62. expect(model.getValue('Event--permission')).toEqual('admin');
  63. expect(model.getValue('Organization--permission')).toEqual('read');
  64. expect(model.getValue('Member--permission')).toEqual('no-access');
  65. });
  66. });