permissionSelection.spec.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. appPublished={false}
  17. permissions={{
  18. Event: 'no-access',
  19. Team: 'no-access',
  20. Member: 'no-access',
  21. Project: 'write',
  22. Release: 'admin',
  23. Organization: 'admin',
  24. }}
  25. onChange={onChange}
  26. />
  27. </Form>
  28. );
  29. ModalStore.reset();
  30. });
  31. it('renders a row for each resource', () => {
  32. expect(screen.getByRole('textbox', {name: 'Project'})).toBeInTheDocument();
  33. expect(screen.getByRole('textbox', {name: 'Team'})).toBeInTheDocument();
  34. expect(screen.getByRole('textbox', {name: 'Release'})).toBeInTheDocument();
  35. expect(screen.getByRole('textbox', {name: 'Issue & Event'})).toBeInTheDocument();
  36. expect(screen.getByRole('textbox', {name: 'Organization'})).toBeInTheDocument();
  37. expect(screen.getByRole('textbox', {name: 'Member'})).toBeInTheDocument();
  38. });
  39. it('lists human readable permissions', async () => {
  40. const expectOptions = async (name, options) => {
  41. for (const option of options) {
  42. await selectEvent.select(screen.getByRole('textbox', {name}), option);
  43. }
  44. };
  45. await expectOptions('Project', ['No Access', 'Read', 'Read & Write', 'Admin']);
  46. await expectOptions('Team', ['No Access', 'Read', 'Read & Write', 'Admin']);
  47. await expectOptions('Release', ['No Access', 'Admin']);
  48. await expectOptions('Issue & Event', ['No Access', 'Read', 'Read & Write', 'Admin']);
  49. await expectOptions('Organization', ['No Access', 'Read', 'Read & Write', 'Admin']);
  50. await expectOptions('Member', ['No Access', 'Read', 'Read & Write', 'Admin']);
  51. });
  52. it('stores the permissions the User has selected', async () => {
  53. const selectByValue = (name, value) =>
  54. selectEvent.select(screen.getByRole('textbox', {name}), value);
  55. await selectByValue('Project', 'Read & Write');
  56. await selectByValue('Team', 'Read');
  57. await selectByValue('Release', 'Admin');
  58. await selectByValue('Issue & Event', 'Admin');
  59. await selectByValue('Organization', 'Read');
  60. await selectByValue('Member', 'No Access');
  61. expect(model.getValue('Project--permission')).toEqual('write');
  62. expect(model.getValue('Team--permission')).toEqual('read');
  63. expect(model.getValue('Release--permission')).toEqual('admin');
  64. expect(model.getValue('Event--permission')).toEqual('admin');
  65. expect(model.getValue('Organization--permission')).toEqual('read');
  66. expect(model.getValue('Member--permission')).toEqual('no-access');
  67. });
  68. });