organizationMemberRow.spec.tsx 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. import {render, screen, userEvent, waitFor} from 'sentry-test/reactTestingLibrary';
  2. import OrganizationMemberRow from 'sentry/views/settings/organizationMembers/organizationMemberRow';
  3. describe('OrganizationMemberRow', function () {
  4. const member = TestStubs.Member({
  5. id: '1',
  6. email: '',
  7. name: '',
  8. orgRole: '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. groupOrgRoles: [],
  20. });
  21. const managerTeam = TestStubs.Team({
  22. orgRole: 'manager',
  23. });
  24. const memberOnManagerTeam = TestStubs.Member({
  25. id: '2',
  26. orgRole: 'member',
  27. teams: [managerTeam.slug],
  28. groupOrgRoles: [
  29. {
  30. teamSlug: managerTeam.slug,
  31. role: {name: 'Manager'},
  32. },
  33. ],
  34. });
  35. const currentUser = TestStubs.User({
  36. id: '2',
  37. email: 'currentUser@email.com',
  38. });
  39. const defaultProps: React.ComponentProps<typeof OrganizationMemberRow> = {
  40. organization: TestStubs.Organization(),
  41. status: '',
  42. requireLink: false,
  43. memberCanLeave: false,
  44. canAddMembers: false,
  45. canRemoveMembers: false,
  46. member,
  47. currentUser,
  48. onSendInvite: () => {},
  49. onRemove: () => {},
  50. onLeave: () => {},
  51. };
  52. function resendButton() {
  53. return screen.queryByRole('button', {name: 'Resend invite'});
  54. }
  55. function resendSsoButton() {
  56. return screen.queryByRole('button', {name: 'Resend SSO link'});
  57. }
  58. function leaveButton() {
  59. return screen.queryByRole('button', {name: 'Leave'});
  60. }
  61. function removeButton() {
  62. return screen.queryByRole('button', {name: 'Remove'});
  63. }
  64. describe('two factor', function () {
  65. it('does not have 2fa warning if user has 2fa', function () {
  66. render(
  67. <OrganizationMemberRow
  68. {...defaultProps}
  69. member={TestStubs.Member({
  70. ...member,
  71. user: TestStubs.User({...member.user, has2fa: true}),
  72. })}
  73. />
  74. );
  75. expect(screen.getByText('2FA Enabled')).toBeInTheDocument();
  76. expect(screen.queryByText('2FA Not Enabled')).not.toBeInTheDocument();
  77. });
  78. it('has 2fa warning if user does not have 2fa enabled', function () {
  79. render(
  80. <OrganizationMemberRow
  81. {...defaultProps}
  82. member={{
  83. ...member,
  84. user: {...member.user, has2fa: false},
  85. }}
  86. />
  87. );
  88. expect(screen.getByText('2FA Not Enabled')).toBeInTheDocument();
  89. expect(screen.queryByText('2FA Enabled')).not.toBeInTheDocument();
  90. });
  91. });
  92. describe('Pending user', function () {
  93. const props = {
  94. ...defaultProps,
  95. member: {...member, pending: true},
  96. };
  97. it('has "Invited" status, no "Resend Invite"', function () {
  98. render(<OrganizationMemberRow {...props} />);
  99. expect(screen.getByTestId('member-role')).toHaveTextContent('Invited Member');
  100. expect(resendButton()).toBeDisabled();
  101. });
  102. it('has "Resend Invite" button only if `canAddMembers` is true', function () {
  103. render(<OrganizationMemberRow {...props} canAddMembers />);
  104. expect(screen.getByTestId('member-role')).toHaveTextContent('Invited Member');
  105. expect(resendButton()).toBeEnabled();
  106. });
  107. it('has the right inviting states', function () {
  108. render(<OrganizationMemberRow {...props} canAddMembers />);
  109. expect(resendButton()).toBeInTheDocument();
  110. });
  111. it('has loading state', function () {
  112. render(<OrganizationMemberRow {...props} canAddMembers status="loading" />);
  113. // Should have loader
  114. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  115. // No Resend Invite button
  116. expect(resendButton()).not.toBeInTheDocument();
  117. });
  118. it('has success status', function () {
  119. render(<OrganizationMemberRow {...props} canAddMembers status="success" />);
  120. // Should not have loader
  121. expect(screen.queryByTestId('loading-indicator')).not.toBeInTheDocument();
  122. // No Resend Invite button
  123. expect(resendButton()).not.toBeInTheDocument();
  124. expect(screen.getByTestId('member-status')).toHaveTextContent('Sent!');
  125. });
  126. });
  127. describe('Expired user', function () {
  128. it('has "Expired" status', function () {
  129. render(
  130. <OrganizationMemberRow
  131. {...defaultProps}
  132. canAddMembers
  133. member={{...member, pending: true, expired: true}}
  134. />
  135. );
  136. expect(screen.getByTestId('member-role')).toHaveTextContent('Expired Invite');
  137. expect(resendButton()).toBeEnabled();
  138. });
  139. });
  140. describe('Requires SSO Link', function () {
  141. const props = {
  142. ...defaultProps,
  143. flags: {'sso:link': false},
  144. requireLink: true,
  145. };
  146. it('shows "Invited" status if user has not registered and not linked', function () {
  147. render(
  148. <OrganizationMemberRow
  149. {...props}
  150. canAddMembers
  151. member={{...member, pending: true}}
  152. />
  153. );
  154. expect(screen.getByTestId('member-role')).toHaveTextContent('Invited Member');
  155. expect(resendButton()).toBeEnabled();
  156. });
  157. it('shows "missing SSO link" message if user is registered and needs link', function () {
  158. render(<OrganizationMemberRow {...props} />);
  159. expect(screen.getByTestId('member-role')).toHaveTextContent('Member');
  160. expect(resendSsoButton()).toBeDisabled();
  161. });
  162. it('has "Resend SSO link" button only if `canAddMembers` is true and no link', function () {
  163. render(<OrganizationMemberRow {...props} canAddMembers />);
  164. expect(resendSsoButton()).toBeEnabled();
  165. });
  166. it('has 2fa warning if user is linked does not have 2fa enabled', function () {
  167. render(
  168. <OrganizationMemberRow
  169. {...defaultProps}
  170. member={{
  171. ...member,
  172. flags: {'sso:linked': true},
  173. user: {...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. describe('render org role', function () {
  237. it('renders org role without tooltip if no org roles from team membership', function () {
  238. render(
  239. <OrganizationMemberRow
  240. {...defaultProps}
  241. member={{...member, user: {...member.user}}}
  242. />
  243. );
  244. expect(screen.getByText('Member')).toBeInTheDocument();
  245. const questionTooltip = screen.queryByTestId('more-information');
  246. expect(questionTooltip).not.toBeInTheDocument();
  247. });
  248. });
  249. it('renders org role info tooltip if member has org roles from team membership', async function () {
  250. render(
  251. <OrganizationMemberRow
  252. {...defaultProps}
  253. member={{...memberOnManagerTeam, user: {...memberOnManagerTeam.user}}}
  254. />
  255. );
  256. const questionTooltip = screen.getByTestId('more-information');
  257. expect(questionTooltip).toBeInTheDocument();
  258. await userEvent.hover(questionTooltip);
  259. await waitFor(() => {
  260. expect(screen.getByText(`#${managerTeam.slug}`)).toBeInTheDocument();
  261. expect(screen.getByText(': Manager')).toBeInTheDocument();
  262. });
  263. });
  264. });