permissionSelection.spec.tsx 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import selectEvent from 'sentry-test/selectEvent';
  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. });