dropdown-button.spec.tsx 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818
  1. import type { PropsWithChildren } from 'react'
  2. import sinon from 'sinon'
  3. import DropdownButton from '@/features/group-management/components/members-table/dropdown-button'
  4. import { GroupMembersProvider } from '@/features/group-management/context/group-members-context'
  5. import { User } from '../../../../../../types/group-management/user'
  6. function Wrapper({ children }: PropsWithChildren<Record<string, unknown>>) {
  7. return (
  8. <table className="table">
  9. <tbody>
  10. <tr>
  11. <td className="managed-users-actions" style={{ textAlign: 'right' }}>
  12. <GroupMembersProvider>{children}</GroupMembersProvider>
  13. </td>
  14. </tr>
  15. </tbody>
  16. </table>
  17. )
  18. }
  19. function mountDropDownComponent(user: User, subscriptionId: string) {
  20. cy.mount(
  21. <Wrapper>
  22. <DropdownButton
  23. user={user}
  24. openOffboardingModalForUser={sinon.stub()}
  25. openRemoveModalForUser={sinon.stub()}
  26. openUnlinkUserModal={sinon.stub()}
  27. groupId={subscriptionId}
  28. setGroupUserAlert={sinon.stub()}
  29. />
  30. </Wrapper>
  31. )
  32. }
  33. describe('DropdownButton', function () {
  34. const subscriptionId = '123abc123abc'
  35. describe('with a standard group', function () {
  36. describe('for a pending user (has not joined group)', function () {
  37. const user: User = {
  38. _id: 'some-user',
  39. email: 'some.user@example.com',
  40. first_name: 'Some',
  41. last_name: 'User',
  42. invite: true,
  43. last_active_at: new Date(),
  44. enrollment: {},
  45. isEntityAdmin: undefined,
  46. }
  47. beforeEach(function () {
  48. cy.window().then(win => {
  49. win.metaAttributesCache.set('ol-users', [user])
  50. })
  51. mountDropDownComponent(user, subscriptionId)
  52. })
  53. it('should render dropdown button', function () {
  54. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  55. 'exist'
  56. )
  57. cy.findByRole('button', { name: /actions/i })
  58. })
  59. it('should show the correct menu when dropdown button is clicked', function () {
  60. cy.findByRole('button', { name: /actions/i }).click()
  61. cy.findByTestId('resend-group-invite-action').should('be.visible')
  62. cy.findByTestId('remove-user-action').should('be.visible')
  63. cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
  64. cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
  65. cy.findByTestId('no-actions-available').should('not.exist')
  66. })
  67. })
  68. describe('for the group admin', function () {
  69. const user: User = {
  70. _id: 'some-user',
  71. email: 'some.user@example.com',
  72. first_name: 'Some',
  73. last_name: 'User',
  74. invite: false,
  75. last_active_at: new Date(),
  76. enrollment: {},
  77. isEntityAdmin: true,
  78. }
  79. beforeEach(function () {
  80. cy.window().then(win => {
  81. win.metaAttributesCache.set('ol-users', [user])
  82. })
  83. mountDropDownComponent(user, subscriptionId)
  84. })
  85. it('should render dropdown button', function () {
  86. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  87. 'exist'
  88. )
  89. cy.findByRole('button', { name: /actions/i })
  90. })
  91. it('should show the correct menu when dropdown button is clicked', function () {
  92. cy.findByRole('button', { name: /actions/i }).click()
  93. cy.findByTestId('remove-user-action').should('be.visible')
  94. cy.findByTestId('no-actions-available').should('not.exist')
  95. })
  96. })
  97. })
  98. describe('with Managed Users enabled', function () {
  99. beforeEach(function () {
  100. cy.window().then(win => {
  101. win.metaAttributesCache.set('ol-managedUsersActive', true)
  102. win.metaAttributesCache.set('ol-groupSSOActive', false)
  103. })
  104. })
  105. describe('for a pending user (has not joined group)', function () {
  106. const user: User = {
  107. _id: 'some-user',
  108. email: 'some.user@example.com',
  109. first_name: 'Some',
  110. last_name: 'User',
  111. invite: true,
  112. last_active_at: new Date(),
  113. enrollment: {},
  114. isEntityAdmin: undefined,
  115. }
  116. beforeEach(function () {
  117. cy.window().then(win => {
  118. win.metaAttributesCache.set('ol-users', [user])
  119. })
  120. mountDropDownComponent(user, subscriptionId)
  121. })
  122. it('should render dropdown button', function () {
  123. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  124. 'exist'
  125. )
  126. cy.findByRole('button', { name: /actions/i })
  127. })
  128. it('should show the correct menu when dropdown button is clicked', function () {
  129. cy.findByRole('button', { name: /actions/i }).click()
  130. cy.findByTestId('resend-group-invite-action').should('be.visible')
  131. cy.findByTestId('remove-user-action').should('be.visible')
  132. cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
  133. cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
  134. cy.findByTestId('no-actions-available').should('not.exist')
  135. })
  136. })
  137. describe('for a managed group member', function () {
  138. const user: User = {
  139. _id: 'some-user',
  140. email: 'some.user@example.com',
  141. first_name: 'Some',
  142. last_name: 'User',
  143. invite: false,
  144. last_active_at: new Date(),
  145. enrollment: {
  146. managedBy: subscriptionId,
  147. enrolledAt: new Date(),
  148. },
  149. isEntityAdmin: undefined,
  150. }
  151. beforeEach(function () {
  152. cy.window().then(win => {
  153. win.metaAttributesCache.set('ol-users', [user])
  154. win.metaAttributesCache.set('ol-isUserGroupManager', true)
  155. })
  156. mountDropDownComponent(user, subscriptionId)
  157. })
  158. it('should render the dropdown button', function () {
  159. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  160. 'exist'
  161. )
  162. cy.findByRole('button', { name: /actions/i })
  163. })
  164. it('should show the correct menu when dropdown button is clicked', function () {
  165. cy.findByRole('button', { name: /actions/i }).click()
  166. cy.findByTestId('delete-user-action').should('be.visible')
  167. cy.findByTestId('release-user-action')
  168. cy.findByTestId('remove-user-action').should('not.exist')
  169. cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
  170. cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
  171. cy.findByTestId('no-actions-available').should('not.exist')
  172. })
  173. })
  174. describe('for a non-managed group member', function () {
  175. const user: User = {
  176. _id: 'some-user',
  177. email: 'some.user@example.com',
  178. first_name: 'Some',
  179. last_name: 'User',
  180. invite: false,
  181. last_active_at: new Date(),
  182. enrollment: {},
  183. isEntityAdmin: undefined,
  184. isEntityMember: true,
  185. }
  186. beforeEach(function () {
  187. cy.window().then(win => {
  188. win.metaAttributesCache.set('ol-users', [user])
  189. })
  190. mountDropDownComponent(user, subscriptionId)
  191. })
  192. it('should render dropdown button', function () {
  193. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  194. 'exist'
  195. )
  196. cy.findByRole('button', { name: /actions/i })
  197. })
  198. it('should show the correct menu when dropdown button is clicked', function () {
  199. cy.findByRole('button', { name: /actions/i }).click()
  200. cy.findByTestId('resend-managed-user-invite-action').should(
  201. 'be.visible'
  202. )
  203. cy.findByTestId('remove-user-action').should('be.visible')
  204. cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
  205. cy.findByTestId('no-actions-available').should('not.exist')
  206. })
  207. })
  208. describe('for a managed group admin user', function () {
  209. const user: User = {
  210. _id: 'some-user',
  211. email: 'some.user@example.com',
  212. first_name: 'Some',
  213. last_name: 'User',
  214. invite: false,
  215. last_active_at: new Date(),
  216. enrollment: {
  217. managedBy: subscriptionId,
  218. enrolledAt: new Date(),
  219. },
  220. isEntityAdmin: true,
  221. }
  222. beforeEach(function () {
  223. cy.window().then(win => {
  224. win.metaAttributesCache.set('ol-users', [user])
  225. })
  226. mountDropDownComponent(user, subscriptionId)
  227. })
  228. it('should render the button', function () {
  229. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  230. 'exist'
  231. )
  232. cy.findByRole('button', { name: /actions/i })
  233. })
  234. it('should show the (empty) menu when the button is clicked', function () {
  235. cy.findByRole('button', { name: /actions/i }).click()
  236. cy.findByTestId('no-actions-available').should('exist')
  237. })
  238. })
  239. })
  240. describe('with Group SSO enabled', function () {
  241. beforeEach(function () {
  242. cy.window().then(win => {
  243. win.metaAttributesCache.set('ol-managedUsersActive', false)
  244. win.metaAttributesCache.set('ol-groupSSOActive', true)
  245. })
  246. })
  247. describe('for a pending user (has not joined group)', function () {
  248. const user: User = {
  249. _id: 'some-user',
  250. email: 'some.user@example.com',
  251. first_name: 'Some',
  252. last_name: 'User',
  253. invite: true,
  254. last_active_at: new Date(),
  255. enrollment: {},
  256. isEntityAdmin: undefined,
  257. }
  258. beforeEach(function () {
  259. cy.window().then(win => {
  260. win.metaAttributesCache.set('ol-users', [user])
  261. })
  262. mountDropDownComponent(user, subscriptionId)
  263. })
  264. it('should render dropdown button', function () {
  265. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  266. 'exist'
  267. )
  268. cy.findByRole('button', { name: /actions/i })
  269. })
  270. it('should show the correct menu when dropdown button is clicked', function () {
  271. cy.findByRole('button', { name: /actions/i }).click()
  272. cy.findByTestId('resend-group-invite-action').should('be.visible')
  273. cy.findByTestId('remove-user-action').should('be.visible')
  274. cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
  275. cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
  276. cy.findByTestId('unlink-user-action').should('not.exist')
  277. cy.findByTestId('no-actions-available').should('not.exist')
  278. })
  279. })
  280. describe('for a group member not linked with SSO yet', function () {
  281. const user: User = {
  282. _id: 'some-user',
  283. email: 'some.user@example.com',
  284. first_name: 'Some',
  285. last_name: 'User',
  286. invite: false,
  287. last_active_at: new Date(),
  288. enrollment: {},
  289. isEntityAdmin: undefined,
  290. }
  291. beforeEach(function () {
  292. cy.window().then(win => {
  293. win.metaAttributesCache.set('ol-users', [user])
  294. })
  295. })
  296. it('should show resend invite when user is admin', function () {
  297. mountDropDownComponent({ ...user, isEntityAdmin: true }, '123abc')
  298. cy.findByRole('button', { name: /actions/i }).click()
  299. cy.findByTestId('resend-sso-link-invite-action').should('exist')
  300. })
  301. it('should not show resend invite when SSO is disabled', function () {
  302. cy.window().then(win => {
  303. win.metaAttributesCache.set('ol-groupSSOActive', false)
  304. })
  305. mountDropDownComponent(user, '123abc')
  306. cy.findByRole('button', { name: /actions/i }).click()
  307. cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
  308. })
  309. it('should show the resend SSO invite option when dropdown button is clicked', function () {
  310. cy.window().then(win => {
  311. win.metaAttributesCache.set('ol-groupSSOActive', true)
  312. })
  313. mountDropDownComponent(user, '123abc')
  314. cy.findByRole('button', { name: /actions/i }).click()
  315. cy.findByTestId('resend-sso-link-invite-action').should('be.visible')
  316. })
  317. it('should make the correct post request when resend SSO invite is clicked ', function () {
  318. cy.window().then(win => {
  319. win.metaAttributesCache.set('ol-groupSSOActive', true)
  320. })
  321. cy.intercept(
  322. 'POST',
  323. '/manage/groups/123abc/resendSSOLinkInvite/some-user',
  324. { success: true }
  325. ).as('resendInviteRequest')
  326. mountDropDownComponent(user, '123abc')
  327. cy.findByRole('button', { name: /actions/i }).click()
  328. cy.findByTestId('resend-sso-link-invite-action')
  329. .should('exist')
  330. .as('resendInvite')
  331. cy.get('@resendInvite').click()
  332. cy.wait('@resendInviteRequest')
  333. })
  334. })
  335. })
  336. describe('with Managed Users and Group SSO enabled', function () {
  337. beforeEach(function () {
  338. cy.window().then(win => {
  339. win.metaAttributesCache.set('ol-managedUsersActive', true)
  340. win.metaAttributesCache.set('ol-groupSSOActive', true)
  341. })
  342. })
  343. describe('for a pending user (has not joined group)', function () {
  344. const user: User = {
  345. _id: 'some-user',
  346. email: 'some.user@example.com',
  347. first_name: 'Some',
  348. last_name: 'User',
  349. invite: true,
  350. last_active_at: new Date(),
  351. enrollment: {},
  352. isEntityAdmin: undefined,
  353. }
  354. beforeEach(function () {
  355. cy.window().then(win => {
  356. win.metaAttributesCache.set('ol-users', [user])
  357. })
  358. mountDropDownComponent(user, subscriptionId)
  359. })
  360. it('should render dropdown button', function () {
  361. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  362. 'exist'
  363. )
  364. cy.findByRole('button', { name: /actions/i })
  365. })
  366. it('should show the correct menu when dropdown button is clicked', function () {
  367. cy.findByRole('button', { name: /actions/i }).click()
  368. cy.findByTestId('resend-group-invite-action').should('be.visible')
  369. cy.findByTestId('remove-user-action').should('be.visible')
  370. cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
  371. cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
  372. cy.findByTestId('unlink-user-action').should('not.exist')
  373. cy.findByTestId('no-actions-available').should('not.exist')
  374. })
  375. })
  376. describe('for a non-managed group member with SSO linked', function () {
  377. const user: User = {
  378. _id: 'some-user',
  379. email: 'some.user@example.com',
  380. first_name: 'Some',
  381. last_name: 'User',
  382. invite: false,
  383. last_active_at: new Date(),
  384. enrollment: {
  385. sso: [
  386. {
  387. groupId: subscriptionId,
  388. linkedAt: new Date(),
  389. primary: true,
  390. },
  391. ],
  392. },
  393. isEntityAdmin: undefined,
  394. isEntityMember: true,
  395. }
  396. beforeEach(function () {
  397. cy.window().then(win => {
  398. win.metaAttributesCache.set('ol-users', [user])
  399. })
  400. mountDropDownComponent(user, subscriptionId)
  401. })
  402. it('should render dropdown button', function () {
  403. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  404. 'exist'
  405. )
  406. cy.findByRole('button', { name: /actions/i })
  407. })
  408. it('should show the correct menu when dropdown button is clicked', function () {
  409. cy.findByRole('button', { name: /actions/i }).click()
  410. cy.findByTestId('resend-managed-user-invite-action').should(
  411. 'be.visible'
  412. )
  413. cy.findByTestId('remove-user-action').should('be.visible')
  414. cy.findByTestId('unlink-user-action').should('be.visible')
  415. cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
  416. })
  417. })
  418. describe('for a non-managed group member with SSO not linked', function () {
  419. const user: User = {
  420. _id: 'some-user',
  421. email: 'some.user@example.com',
  422. first_name: 'Some',
  423. last_name: 'User',
  424. invite: false,
  425. last_active_at: new Date(),
  426. enrollment: {
  427. sso: [],
  428. },
  429. isEntityAdmin: undefined,
  430. isEntityMember: true,
  431. }
  432. beforeEach(function () {
  433. cy.window().then(win => {
  434. win.metaAttributesCache.set('ol-users', [user])
  435. })
  436. mountDropDownComponent(user, subscriptionId)
  437. })
  438. it('should render dropdown button', function () {
  439. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  440. 'exist'
  441. )
  442. cy.findByRole('button', { name: /actions/i })
  443. })
  444. it('should show the correct menu when dropdown button is clicked', function () {
  445. cy.findByRole('button', { name: /actions/i }).click()
  446. cy.findByTestId('resend-managed-user-invite-action').should(
  447. 'be.visible'
  448. )
  449. cy.findByTestId('remove-user-action').should('be.visible')
  450. cy.findByTestId('resend-sso-link-invite-action').should('be.visible')
  451. cy.findByTestId('no-actions-available').should('not.exist')
  452. cy.findByTestId('unlink-user-action').should('not.exist')
  453. })
  454. })
  455. describe('for a non-managed group admin with SSO linked', function () {
  456. const user: User = {
  457. _id: 'some-user',
  458. email: 'some.user@example.com',
  459. first_name: 'Some',
  460. last_name: 'User',
  461. invite: false,
  462. last_active_at: new Date(),
  463. enrollment: {
  464. sso: [
  465. {
  466. groupId: subscriptionId,
  467. linkedAt: new Date(),
  468. primary: true,
  469. },
  470. ],
  471. },
  472. isEntityAdmin: true,
  473. isEntityMember: true,
  474. }
  475. beforeEach(function () {
  476. cy.window().then(win => {
  477. win.metaAttributesCache.set('ol-users', [user])
  478. })
  479. mountDropDownComponent(user, subscriptionId)
  480. })
  481. it('should render dropdown button', function () {
  482. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  483. 'exist'
  484. )
  485. cy.findByRole('button', { name: /actions/i })
  486. })
  487. it('should show the correct menu when dropdown button is clicked', function () {
  488. cy.findByRole('button', { name: /actions/i }).click()
  489. cy.findByTestId('resend-managed-user-invite-action').should(
  490. 'be.visible'
  491. )
  492. cy.findByTestId('remove-user-action').should('be.visible')
  493. cy.findByTestId('unlink-user-action').should('be.visible')
  494. cy.findByTestId('delete-user-action').should('not.exist')
  495. cy.findByTestId('release-user-action').should('not.exist')
  496. cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
  497. cy.findByTestId('no-actions-available').should('not.exist')
  498. })
  499. })
  500. describe('for a non-managed group admin with SSO not linked', function () {
  501. const user: User = {
  502. _id: 'some-user',
  503. email: 'some.user@example.com',
  504. first_name: 'Some',
  505. last_name: 'User',
  506. invite: false,
  507. last_active_at: new Date(),
  508. enrollment: {
  509. sso: [],
  510. },
  511. isEntityAdmin: true,
  512. isEntityMember: true,
  513. }
  514. beforeEach(function () {
  515. cy.window().then(win => {
  516. win.metaAttributesCache.set('ol-users', [user])
  517. })
  518. mountDropDownComponent(user, subscriptionId)
  519. })
  520. it('should render dropdown button', function () {
  521. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  522. 'exist'
  523. )
  524. cy.findByRole('button', { name: /actions/i })
  525. })
  526. it('should show the correct menu when dropdown button is clicked', function () {
  527. cy.findByRole('button', { name: /actions/i }).click()
  528. cy.findByTestId('resend-managed-user-invite-action').should(
  529. 'be.visible'
  530. )
  531. cy.findByTestId('remove-user-action').should('be.visible')
  532. cy.findByTestId('delete-user-action').should('not.exist')
  533. cy.findByTestId('release-user-action').should('not.exist')
  534. cy.findByTestId('resend-sso-link-invite-action').should('exist')
  535. cy.findByTestId('no-actions-available').should('not.exist')
  536. })
  537. })
  538. describe('for a managed group member with SSO not linked', function () {
  539. const user: User = {
  540. _id: 'some-user',
  541. email: 'some.user@example.com',
  542. first_name: 'Some',
  543. last_name: 'User',
  544. invite: false,
  545. last_active_at: new Date(),
  546. enrollment: {
  547. managedBy: subscriptionId,
  548. enrolledAt: new Date(),
  549. sso: [],
  550. },
  551. isEntityAdmin: undefined,
  552. }
  553. beforeEach(function () {
  554. cy.window().then(win => {
  555. win.metaAttributesCache.set('ol-users', [user])
  556. win.metaAttributesCache.set('ol-isUserGroupManager', true)
  557. })
  558. mountDropDownComponent(user, subscriptionId)
  559. })
  560. it('should render the dropdown button', function () {
  561. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  562. 'exist'
  563. )
  564. cy.findByRole('button', { name: /actions/i })
  565. })
  566. it('should show the correct menu when dropdown button is clicked', function () {
  567. cy.findByRole('button', { name: /actions/i }).click()
  568. cy.findByTestId('delete-user-action').should('be.visible')
  569. cy.findByTestId('release-user-action')
  570. cy.findByTestId('remove-user-action').should('not.exist')
  571. cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
  572. cy.findByTestId('resend-sso-link-invite-action').should('exist')
  573. cy.findByTestId('no-actions-available').should('not.exist')
  574. })
  575. })
  576. describe('for a managed group member with SSO linked', function () {
  577. const user: User = {
  578. _id: 'some-user',
  579. email: 'some.user@example.com',
  580. first_name: 'Some',
  581. last_name: 'User',
  582. invite: false,
  583. last_active_at: new Date(),
  584. enrollment: {
  585. managedBy: subscriptionId,
  586. enrolledAt: new Date(),
  587. sso: [
  588. {
  589. groupId: subscriptionId,
  590. linkedAt: new Date(),
  591. primary: true,
  592. },
  593. ],
  594. },
  595. isEntityAdmin: undefined,
  596. }
  597. beforeEach(function () {
  598. cy.window().then(win => {
  599. win.metaAttributesCache.set('ol-users', [user])
  600. win.metaAttributesCache.set('ol-isUserGroupManager', true)
  601. })
  602. mountDropDownComponent(user, subscriptionId)
  603. })
  604. it('should render the dropdown button', function () {
  605. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  606. 'exist'
  607. )
  608. cy.findByRole('button', { name: /actions/i })
  609. })
  610. it('should show the correct menu when dropdown button is clicked', function () {
  611. cy.findByRole('button', { name: /actions/i }).click()
  612. cy.findByTestId('delete-user-action').should('be.visible')
  613. cy.findByTestId('release-user-action')
  614. cy.findByTestId('remove-user-action').should('not.exist')
  615. cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
  616. cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
  617. cy.findByTestId('no-actions-available').should('not.exist')
  618. })
  619. })
  620. describe('for a managed group admin with SSO not linked', function () {
  621. const user: User = {
  622. _id: 'some-user',
  623. email: 'some.user@example.com',
  624. first_name: 'Some',
  625. last_name: 'User',
  626. invite: false,
  627. last_active_at: new Date(),
  628. enrollment: {
  629. managedBy: subscriptionId,
  630. enrolledAt: new Date(),
  631. sso: [],
  632. },
  633. isEntityAdmin: true,
  634. }
  635. beforeEach(function () {
  636. cy.window().then(win => {
  637. win.metaAttributesCache.set('ol-users', [user])
  638. })
  639. mountDropDownComponent(user, subscriptionId)
  640. })
  641. it('should render the button', function () {
  642. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  643. 'exist'
  644. )
  645. cy.findByRole('button', { name: /actions/i })
  646. })
  647. it('should show the correct menu when dropdown button is clicked', function () {
  648. cy.findByRole('button', { name: /actions/i }).click()
  649. cy.findByTestId('resend-sso-link-invite-action').should('exist')
  650. cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
  651. cy.findByTestId('remove-user-action').should('not.exist')
  652. cy.findByTestId('delete-user-action').should('not.exist')
  653. cy.findByTestId('release-user-action').should('not.exist')
  654. cy.findByTestId('no-actions-available').should('not.exist')
  655. })
  656. })
  657. describe('for a managed group admin with SSO linked', function () {
  658. const user: User = {
  659. _id: 'some-user',
  660. email: 'some.user@example.com',
  661. first_name: 'Some',
  662. last_name: 'User',
  663. invite: false,
  664. last_active_at: new Date(),
  665. enrollment: {
  666. managedBy: subscriptionId,
  667. enrolledAt: new Date(),
  668. sso: [
  669. {
  670. groupId: subscriptionId,
  671. linkedAt: new Date(),
  672. primary: true,
  673. },
  674. ],
  675. },
  676. isEntityAdmin: true,
  677. }
  678. beforeEach(function () {
  679. cy.window().then(win => {
  680. win.metaAttributesCache.set('ol-users', [user])
  681. })
  682. mountDropDownComponent(user, subscriptionId)
  683. })
  684. it('should render the button', function () {
  685. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  686. 'exist'
  687. )
  688. cy.findByRole('button', { name: /actions/i })
  689. })
  690. it('should show no actions except to unlink when dropdown button is clicked', function () {
  691. cy.findByRole('button', { name: /actions/i }).click()
  692. cy.findByTestId('unlink-user-action').should('exist')
  693. cy.findByTestId('no-actions-available').should('not.exist')
  694. cy.findByTestId('delete-user-action').should('not.exist')
  695. cy.findByTestId('release-user-action').should('not.exist')
  696. cy.findByTestId('remove-user-action').should('not.exist')
  697. cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
  698. cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
  699. })
  700. })
  701. })
  702. })