permissionSelection.spec.jsx 2.9 KB

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