resourceSubscriptions.spec.jsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import {mountWithTheme} from 'sentry-test/enzyme';
  2. import Form from 'sentry/components/forms/form';
  3. import Subscriptions from 'sentry/views/settings/organizationDeveloperSettings/resourceSubscriptions';
  4. describe('Resource Subscriptions', () => {
  5. let wrapper;
  6. let onChange;
  7. describe('initial no-access permissions', () => {
  8. beforeEach(() => {
  9. onChange = jest.fn();
  10. wrapper = mountWithTheme(
  11. <Form>
  12. <Subscriptions
  13. events={[]}
  14. permissions={{
  15. Event: 'no-access',
  16. Team: 'no-access',
  17. Project: 'write',
  18. Release: 'admin',
  19. Organization: 'admin',
  20. }}
  21. onChange={onChange}
  22. />
  23. </Form>
  24. );
  25. });
  26. it('renders disabled checkbox with no issue permission', () => {
  27. expect(
  28. wrapper.find('SubscriptionBox').first().prop('disabledFromPermissions')
  29. ).toBe(true);
  30. });
  31. it('updates events state when new permissions props is passed', () => {
  32. const permissions = {
  33. Event: 'read',
  34. Team: 'no-access',
  35. Project: 'write',
  36. Release: 'admin',
  37. Organization: 'admin',
  38. };
  39. wrapper = mountWithTheme(
  40. <Form>
  41. <Subscriptions events={[]} permissions={permissions} onChange={onChange} />
  42. </Form>
  43. );
  44. expect(
  45. wrapper.find('SubscriptionBox').first().prop('disabledFromPermissions')
  46. ).toBe(false);
  47. });
  48. });
  49. describe('initial access to permissions', () => {
  50. beforeEach(() => {
  51. onChange = jest.fn();
  52. wrapper = mountWithTheme(
  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. }}
  63. onChange={onChange}
  64. />
  65. </Form>
  66. );
  67. });
  68. it('renders nondisabled checkbox with correct permissions', () => {
  69. expect(
  70. wrapper.find('SubscriptionBox').first().prop('disabledFromPermissions')
  71. ).toBe(false);
  72. });
  73. it('revoked permissions also revokes access to corresponding subscriptions', () => {
  74. const permissions = {
  75. Event: 'no-access',
  76. Team: 'no-access',
  77. Project: 'write',
  78. Release: 'admin',
  79. Organization: 'admin',
  80. };
  81. wrapper = mountWithTheme(
  82. <Form>
  83. <Subscriptions
  84. events={['issue']}
  85. permissions={permissions}
  86. onChange={onChange}
  87. />
  88. </Form>
  89. );
  90. wrapper.setProps({permissions});
  91. expect(
  92. wrapper.find('SubscriptionBox').first().prop('disabledFromPermissions')
  93. ).toBe(true);
  94. });
  95. });
  96. });