organizationAuthList.spec.jsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. import React from 'react';
  2. import {shallow, mount} from 'enzyme';
  3. import OrganizationAuthList from 'app/views/settings/organizationAuth/organizationAuthList';
  4. jest.mock('jquery');
  5. describe('OrganizationAuthList', function() {
  6. it('renders with no providers', function() {
  7. const wrapper = shallow(
  8. <OrganizationAuthList providerList={[]} />,
  9. TestStubs.routerContext()
  10. );
  11. expect(wrapper).toMatchSnapshot();
  12. });
  13. it('renders', function() {
  14. const wrapper = shallow(
  15. <OrganizationAuthList
  16. orgId="org-slug"
  17. onSendReminders={() => {}}
  18. providerList={TestStubs.AuthProviders()}
  19. />,
  20. TestStubs.routerContext()
  21. );
  22. expect(wrapper).toMatchSnapshot();
  23. });
  24. it('renders for members', function() {
  25. const wrapper = mount(
  26. <OrganizationAuthList
  27. orgId="org-slug"
  28. onSendReminders={() => {}}
  29. providerList={TestStubs.AuthProviders()}
  30. activeProvider={TestStubs.AuthProviders()[0]}
  31. />,
  32. TestStubs.routerContext([
  33. {
  34. organization: TestStubs.Organization({access: ['org:read']}),
  35. },
  36. ])
  37. );
  38. expect(wrapper.find('ProviderItem ActiveIndicator')).toHaveLength(1);
  39. });
  40. describe('with 2fa warning', function() {
  41. const require2fa = {require2FA: true};
  42. const withSSO = {features: ['sso-basic']};
  43. const withSAML = {features: ['sso-saml2']};
  44. it('renders', function() {
  45. const context = TestStubs.routerContext([
  46. {organization: TestStubs.Organization({...require2fa, ...withSSO})},
  47. ]);
  48. const wrapper = shallow(
  49. <OrganizationAuthList
  50. orgId="org-slug"
  51. onSendReminders={() => {}}
  52. providerList={TestStubs.AuthProviders()}
  53. />,
  54. context
  55. );
  56. expect(wrapper.find('PanelAlert[type="warning"]').exists()).toBe(true);
  57. });
  58. it('renders with saml available', function() {
  59. const context = TestStubs.routerContext([
  60. {organization: TestStubs.Organization({...require2fa, ...withSAML})},
  61. ]);
  62. const wrapper = shallow(
  63. <OrganizationAuthList
  64. orgId="org-slug"
  65. onSendReminders={() => {}}
  66. providerList={TestStubs.AuthProviders()}
  67. />,
  68. context
  69. );
  70. expect(wrapper.find('PanelAlert[type="warning"]').exists()).toBe(true);
  71. });
  72. it('does not render without sso available', function() {
  73. const context = TestStubs.routerContext([
  74. {organization: TestStubs.Organization({...require2fa})},
  75. ]);
  76. const wrapper = shallow(
  77. <OrganizationAuthList
  78. orgId="org-slug"
  79. onSendReminders={() => {}}
  80. providerList={TestStubs.AuthProviders()}
  81. />,
  82. context
  83. );
  84. expect(wrapper.find('PanelAlert[type="warning"]').exists()).toBe(false);
  85. });
  86. it('does not render with sso and require 2fa disabled', function() {
  87. const context = TestStubs.routerContext([
  88. {organization: TestStubs.Organization({...withSSO})},
  89. ]);
  90. const wrapper = shallow(
  91. <OrganizationAuthList
  92. orgId="org-slug"
  93. onSendReminders={() => {}}
  94. providerList={TestStubs.AuthProviders()}
  95. />,
  96. context
  97. );
  98. expect(wrapper.find('PanelAlert[type="warning"]').exists()).toBe(false);
  99. });
  100. it('does not render with saml and require 2fa disabled', function() {
  101. const context = TestStubs.routerContext([
  102. {organization: TestStubs.Organization({...withSAML})},
  103. ]);
  104. const wrapper = shallow(
  105. <OrganizationAuthList
  106. orgId="org-slug"
  107. onSendReminders={() => {}}
  108. providerList={TestStubs.AuthProviders()}
  109. />,
  110. context
  111. );
  112. expect(wrapper.find('PanelAlert[type="warning"]').exists()).toBe(false);
  113. });
  114. });
  115. });