organizationMemberRow.spec.tsx 8.4 KB

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