sentryAppPermissionsModal.spec.jsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import {Modal} from 'react-bootstrap';
  2. import React from 'react';
  3. import {mount} from 'enzyme';
  4. import SentryAppPermissionsModal from 'app/components/modals/sentryAppPermissionsModal';
  5. describe('SentryAppPermissionsModal', function() {
  6. const org = TestStubs.Organization();
  7. const routerContext = TestStubs.routerContext();
  8. it('renders permissions modal', function() {
  9. const onInstall = jest.fn();
  10. const onClose = jest.fn();
  11. const sentryApp = TestStubs.SentryApp();
  12. const wrapper = mount(
  13. <SentryAppPermissionsModal
  14. app={sentryApp}
  15. closeModal={onClose}
  16. orgId={org.slug}
  17. onInstall={onInstall}
  18. Header={Modal.Header}
  19. Body={Modal.Body}
  20. />,
  21. routerContext
  22. );
  23. expect(wrapper).toMatchSnapshot();
  24. wrapper
  25. .find('Button')
  26. .last()
  27. .simulate('click');
  28. expect(onClose).toHaveBeenCalled();
  29. });
  30. describe('displays resources that the Sentry App has access to', function() {
  31. it('matches resource with highest level', function() {
  32. const onInstall = jest.fn();
  33. const onClose = jest.fn();
  34. const scopes = [
  35. 'project:read',
  36. 'project:write',
  37. 'member:read',
  38. 'team:write',
  39. 'team:admin',
  40. 'org:admin',
  41. ];
  42. const sentryApp = TestStubs.SentryApp({scopes});
  43. const wrapper = mount(
  44. <SentryAppPermissionsModal
  45. app={sentryApp}
  46. closeModal={onClose}
  47. orgId={org.slug}
  48. onInstall={onInstall}
  49. Header={Modal.Header}
  50. Body={Modal.Body}
  51. />,
  52. routerContext
  53. );
  54. expect(
  55. wrapper
  56. .find('PanelItem')
  57. .first()
  58. .text()
  59. ).toEqual('Read access to Member');
  60. expect(
  61. wrapper
  62. .find('PanelItem')
  63. .at(1)
  64. .text()
  65. ).toEqual('Read and write access to Project');
  66. expect(
  67. wrapper
  68. .find('PanelItem')
  69. .at(2)
  70. .text()
  71. ).toEqual('Admin access to Team, Organization');
  72. });
  73. it('matches releases with admin', function() {
  74. const onInstall = jest.fn();
  75. const onClose = jest.fn();
  76. const sentryApp = TestStubs.SentryApp({scopes: ['project:releases']});
  77. const wrapper = mount(
  78. <SentryAppPermissionsModal
  79. app={sentryApp}
  80. closeModal={onClose}
  81. orgId={org.slug}
  82. onInstall={onInstall}
  83. Header={Modal.Header}
  84. Body={Modal.Body}
  85. />,
  86. routerContext
  87. );
  88. expect(wrapper.find('PanelItem').text()).toEqual('Admin access to Release');
  89. });
  90. });
  91. it('installs the application', function() {
  92. const onInstall = jest.fn();
  93. const onClose = jest.fn();
  94. const sentryApp = TestStubs.SentryApp();
  95. const wrapper = mount(
  96. <SentryAppPermissionsModal
  97. app={sentryApp}
  98. closeModal={onClose}
  99. orgId={org.slug}
  100. onInstall={onInstall}
  101. Header={Modal.Header}
  102. Body={Modal.Body}
  103. />,
  104. routerContext
  105. );
  106. expect(wrapper).toMatchSnapshot();
  107. wrapper
  108. .find('Button')
  109. .first()
  110. .simulate('click');
  111. expect(onInstall).toHaveBeenCalled();
  112. });
  113. });