organizationMemberRow.spec.tsx 10 KB

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