organizationMemberRow.spec.tsx 8.4 KB

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