organizationMemberRow.spec.jsx 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import OrganizationMemberRow from 'sentry/views/settings/organizationMembers/organizationMemberRow';
  3. describe('OrganizationMemberRow', function () {
  4. const member = {
  5. id: '1',
  6. email: '',
  7. name: '',
  8. role: 'member',
  9. roleName: 'Member',
  10. pending: false,
  11. flags: {
  12. 'sso:linked': false,
  13. },
  14. user: {
  15. id: '',
  16. has2fa: false,
  17. name: 'sentry@test.com',
  18. },
  19. };
  20. const currentUser = {
  21. id: '2',
  22. email: 'currentUser@email.com',
  23. };
  24. const defaultProps = {
  25. routes: [],
  26. organization: TestStubs.Organization(),
  27. status: '',
  28. requireLink: false,
  29. memberCanLeave: false,
  30. canAddMembers: false,
  31. canRemoveMembers: false,
  32. member,
  33. currentUser,
  34. onSendInvite: () => {},
  35. onRemove: () => {},
  36. onLeave: () => {},
  37. };
  38. function resendButton() {
  39. return screen.queryByRole('button', {name: 'Resend invite'});
  40. }
  41. function resendSsoButton() {
  42. return screen.queryByRole('button', {name: 'Resend SSO link'});
  43. }
  44. function leaveButton() {
  45. return screen.queryByRole('button', {name: 'Leave'});
  46. }
  47. function removeButton() {
  48. return screen.queryByRole('button', {name: 'Remove'});
  49. }
  50. describe('two factor', function () {
  51. it('does not have 2fa warning if user has 2fa', function () {
  52. render(
  53. <OrganizationMemberRow
  54. {...defaultProps}
  55. member={{
  56. ...member,
  57. user: {...member.user, has2fa: true},
  58. }}
  59. />
  60. );
  61. expect(screen.getByText('2FA Enabled')).toBeInTheDocument();
  62. expect(screen.queryByText('2FA Not Enabled')).not.toBeInTheDocument();
  63. });
  64. it('has 2fa warning if user does not have 2fa enabled', function () {
  65. render(
  66. <OrganizationMemberRow
  67. {...defaultProps}
  68. member={{
  69. ...member,
  70. user: {...member.user, has2fa: false},
  71. }}
  72. />
  73. );
  74. expect(screen.getByText('2FA Not Enabled')).toBeInTheDocument();
  75. expect(screen.queryByText('2FA Enabled')).not.toBeInTheDocument();
  76. });
  77. });
  78. describe('Pending user', function () {
  79. const props = {
  80. ...defaultProps,
  81. member: {...member, pending: true},
  82. };
  83. it('has "Invited" status, no "Resend Invite"', function () {
  84. render(<OrganizationMemberRow {...props} />);
  85. expect(screen.getByTestId('member-role')).toHaveTextContent('Invited Member');
  86. expect(resendButton()).toBeDisabled();
  87. });
  88. it('has "Resend Invite" button only if `canAddMembers` is true', function () {
  89. render(<OrganizationMemberRow {...props} canAddMembers />);
  90. expect(screen.getByTestId('member-role')).toHaveTextContent('Invited Member');
  91. expect(resendButton()).toBeEnabled();
  92. });
  93. it('has the right inviting states', function () {
  94. render(<OrganizationMemberRow {...props} canAddMembers />);
  95. expect(resendButton()).toBeInTheDocument();
  96. });
  97. it('has loading state', function () {
  98. render(<OrganizationMemberRow {...props} canAddMembers status="loading" />);
  99. // Should have loader
  100. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  101. // No Resend Invite button
  102. expect(resendButton()).not.toBeInTheDocument();
  103. });
  104. it('has success status', function () {
  105. render(<OrganizationMemberRow {...props} canAddMembers status="success" />);
  106. // Should not have loader
  107. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument();
  108. // No Resend Invite button
  109. expect(resendButton()).not.toBeInTheDocument();
  110. expect(screen.getByTestId('member-status')).toHaveTextContent('Sent!');
  111. });
  112. });
  113. describe('Expired user', function () {
  114. it('has "Expired" status', function () {
  115. render(
  116. <OrganizationMemberRow
  117. {...defaultProps}
  118. canAddMembers
  119. member={{...member, pending: true, expired: true}}
  120. />
  121. );
  122. expect(screen.getByTestId('member-role')).toHaveTextContent('Expired Invite');
  123. expect(resendButton()).toBeEnabled();
  124. });
  125. });
  126. describe('Requires SSO Link', function () {
  127. const props = {
  128. ...defaultProps,
  129. flags: {'sso:link': false},
  130. requireLink: true,
  131. };
  132. it('shows "Invited" status if user has not registered and not linked', function () {
  133. render(
  134. <OrganizationMemberRow
  135. {...props}
  136. canAddMembers
  137. member={{...member, pending: true}}
  138. />
  139. );
  140. expect(screen.getByTestId('member-role')).toHaveTextContent('Invited Member');
  141. expect(resendButton()).toBeEnabled();
  142. });
  143. it('shows "missing SSO link" message if user is registered and needs link', function () {
  144. render(<OrganizationMemberRow {...props} />);
  145. expect(screen.getByTestId('member-role')).toHaveTextContent('Member');
  146. expect(resendSsoButton()).toBeDisabled();
  147. });
  148. it('has "Resend SSO link" button only if `canAddMembers` is true and no link', function () {
  149. render(<OrganizationMemberRow {...props} canAddMembers />);
  150. expect(resendSsoButton()).toBeEnabled();
  151. });
  152. it('has 2fa warning if user is linked does not have 2fa enabled', function () {
  153. render(
  154. <OrganizationMemberRow
  155. {...defaultProps}
  156. member={{
  157. ...member,
  158. flags: {'sso:linked': true},
  159. user: {...member.user, has2fa: false},
  160. }}
  161. />
  162. );
  163. expect(screen.getByText('2FA Not Enabled')).toBeInTheDocument();
  164. expect(screen.queryByText('2FA Enabled')).not.toBeInTheDocument();
  165. });
  166. });
  167. describe('Is Current User', function () {
  168. const props = {
  169. ...defaultProps,
  170. member: {
  171. ...member,
  172. email: 'currentUser@email.com',
  173. },
  174. };
  175. it('has button to leave organization and no button to remove', function () {
  176. render(<OrganizationMemberRow {...props} memberCanLeave />);
  177. expect(leaveButton()).toBeInTheDocument();
  178. expect(removeButton()).not.toBeInTheDocument();
  179. });
  180. it('has disabled button to leave organization and no button to remove when member can not leave', function () {
  181. render(<OrganizationMemberRow {...props} memberCanLeave={false} />);
  182. expect(leaveButton()).toBeDisabled();
  183. expect(removeButton()).not.toBeInTheDocument();
  184. });
  185. });
  186. describe('IDP flags permissions', function () {
  187. member.flags['idp:provisioned'] = true;
  188. it('current user cannot leave if idp:provisioned', function () {
  189. const props = {
  190. ...defaultProps,
  191. member: {
  192. ...member,
  193. email: 'currentUser@email.com',
  194. },
  195. };
  196. render(
  197. <OrganizationMemberRow
  198. {...props}
  199. memberCanLeave={!member.flags['idp:provisioned']}
  200. />
  201. );
  202. expect(leaveButton()).toBeDisabled();
  203. });
  204. it('cannot remove member if member is idp:provisioned', function () {
  205. render(<OrganizationMemberRow {...defaultProps} />);
  206. expect(removeButton()).toBeDisabled();
  207. });
  208. });
  209. describe('Not Current User', function () {
  210. const props = {
  211. ...defaultProps,
  212. };
  213. it('does not have Leave button', function () {
  214. render(<OrganizationMemberRow {...props} memberCanLeave />);
  215. expect(leaveButton()).not.toBeInTheDocument();
  216. });
  217. it('has Remove disabled button when `canRemoveMembers` is false', function () {
  218. member.flags['idp:provisioned'] = false;
  219. render(<OrganizationMemberRow {...props} />);
  220. expect(removeButton()).toBeDisabled();
  221. });
  222. it('has Remove button when `canRemoveMembers` is true', function () {
  223. member.flags['idp:provisioned'] = false;
  224. render(<OrganizationMemberRow {...props} canRemoveMembers />);
  225. expect(removeButton()).toBeEnabled();
  226. });
  227. });
  228. });