resourceSubscriptions.spec.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import Form from 'sentry/components/forms/form';
  3. import Subscriptions from 'sentry/views/settings/organizationDeveloperSettings/resourceSubscriptions';
  4. describe('Resource Subscriptions', function () {
  5. describe('initial no-access permissions', function () {
  6. it('renders disabled checkbox with no issue permission', function () {
  7. render(
  8. <Form>
  9. <Subscriptions
  10. events={[]}
  11. permissions={{
  12. Event: 'no-access',
  13. Team: 'no-access',
  14. Project: 'write',
  15. Release: 'admin',
  16. Organization: 'admin',
  17. Member: 'admin',
  18. }}
  19. onChange={jest.fn()}
  20. />
  21. </Form>
  22. );
  23. expect(screen.getAllByRole('checkbox')).toHaveLength(3);
  24. expect(screen.getByRole('checkbox', {name: 'issue'})).toBeDisabled();
  25. expect(screen.getByRole('checkbox', {name: 'error'})).toBeDisabled();
  26. expect(screen.getByRole('checkbox', {name: 'comment'})).toBeDisabled();
  27. });
  28. it('updates events state when new permissions props is passed', function () {
  29. render(
  30. <Form>
  31. <Subscriptions
  32. events={[]}
  33. permissions={{
  34. Event: 'read',
  35. Team: 'no-access',
  36. Project: 'write',
  37. Release: 'admin',
  38. Organization: 'admin',
  39. Member: 'admin',
  40. }}
  41. onChange={jest.fn()}
  42. />
  43. </Form>
  44. );
  45. expect(screen.getByRole('checkbox', {name: 'issue'})).toBeEnabled();
  46. expect(screen.getByRole('checkbox', {name: 'error'})).toBeDisabled();
  47. expect(screen.getByRole('checkbox', {name: 'comment'})).toBeEnabled();
  48. });
  49. });
  50. describe('initial access to permissions', function () {
  51. it('renders nondisabled checkbox with correct permissions', function () {
  52. render(
  53. <Form>
  54. <Subscriptions
  55. events={['issue']}
  56. permissions={{
  57. Event: 'read',
  58. Team: 'no-access',
  59. Project: 'write',
  60. Release: 'admin',
  61. Organization: 'admin',
  62. Member: 'admin',
  63. }}
  64. onChange={jest.fn()}
  65. />
  66. </Form>
  67. );
  68. expect(screen.getByRole('checkbox', {name: 'issue'})).toBeEnabled();
  69. expect(screen.getByRole('checkbox', {name: 'error'})).toBeDisabled();
  70. expect(screen.getByRole('checkbox', {name: 'comment'})).toBeEnabled();
  71. });
  72. it('revoked permissions also revokes access to corresponding subscriptions', function () {
  73. render(
  74. <Form>
  75. <Subscriptions
  76. events={['issue']}
  77. permissions={{
  78. Event: 'no-access',
  79. Team: 'no-access',
  80. Project: 'write',
  81. Release: 'admin',
  82. Organization: 'admin',
  83. Member: 'admin',
  84. }}
  85. onChange={jest.fn()}
  86. />
  87. </Form>
  88. );
  89. expect(screen.getByRole('checkbox', {name: 'issue'})).toBeDisabled();
  90. expect(screen.getByRole('checkbox', {name: 'error'})).toBeDisabled();
  91. expect(screen.getByRole('checkbox', {name: 'comment'})).toBeDisabled();
  92. });
  93. });
  94. });