organizationMembersView.spec.jsx 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import PropTypes from 'prop-types';
  2. import React from 'react';
  3. import {Client} from 'app/api';
  4. import {mount} from 'enzyme';
  5. import ConfigStore from 'app/stores/configStore';
  6. import OrganizationMembersView from 'app/views/settings/organization/members/organizationMembersView';
  7. jest.mock('app/api');
  8. describe('OrganizationMembersView', function() {
  9. let currentUser = TestStubs.Members()[1];
  10. let defaultProps = {
  11. orgId: 'org-slug',
  12. orgName: 'Organization Name',
  13. status: '',
  14. routes: [],
  15. requireLink: false,
  16. memberCanLeave: false,
  17. canAddMembers: false,
  18. canRemoveMembers: false,
  19. currentUser,
  20. onSendInvite: () => {},
  21. onRemove: () => {},
  22. onLeave: () => {},
  23. };
  24. beforeAll(function() {
  25. sinon.stub(ConfigStore, 'get', () => currentUser);
  26. });
  27. afterAll(function() {
  28. ConfigStore.get.restore();
  29. });
  30. beforeEach(function() {
  31. Client.clearMockResponses();
  32. Client.addMockResponse({
  33. url: '/organizations/org-id/members/',
  34. method: 'GET',
  35. body: TestStubs.Members(),
  36. });
  37. Client.addMockResponse({
  38. url: '/organizations/org-id/access-requests/',
  39. method: 'GET',
  40. body: [],
  41. });
  42. });
  43. describe('Require Link', function() {
  44. beforeEach(function() {
  45. Client.addMockResponse({
  46. url: '/organizations/org-id/auth-provider/',
  47. method: 'GET',
  48. body: {
  49. ...TestStubs.AuthProvider(),
  50. require_link: true,
  51. },
  52. });
  53. });
  54. it('does not have 2fa warning if user has 2fa', function() {
  55. let wrapper = mount(
  56. <OrganizationMembersView
  57. {...defaultProps}
  58. params={{
  59. orgId: 'org-id',
  60. }}
  61. />,
  62. {
  63. childContextTypes: {
  64. router: PropTypes.object,
  65. },
  66. context: {
  67. organization: TestStubs.Organization(),
  68. router: TestStubs.router(),
  69. },
  70. }
  71. );
  72. expect(wrapper).toMatchSnapshot();
  73. });
  74. });
  75. describe('No Require Link', function() {
  76. beforeEach(function() {
  77. Client.addMockResponse({
  78. url: '/organizations/org-id/auth-provider/',
  79. method: 'GET',
  80. body: {
  81. ...TestStubs.AuthProvider(),
  82. require_link: false,
  83. },
  84. });
  85. });
  86. it('does not have 2fa warning if user has 2fa', function() {
  87. let wrapper = mount(
  88. <OrganizationMembersView
  89. {...defaultProps}
  90. params={{
  91. orgId: 'org-id',
  92. }}
  93. />,
  94. {
  95. childContextTypes: {
  96. router: PropTypes.object,
  97. },
  98. context: {
  99. organization: TestStubs.Organization(),
  100. router: TestStubs.router(),
  101. },
  102. }
  103. );
  104. expect(wrapper).toMatchSnapshot();
  105. });
  106. });
  107. });