dropdown-button.spec.tsx 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  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. }
  185. beforeEach(function () {
  186. cy.window().then(win => {
  187. win.metaAttributesCache.set('ol-users', [user])
  188. })
  189. mountDropDownComponent(user, subscriptionId)
  190. })
  191. it('should render dropdown button', function () {
  192. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  193. 'exist'
  194. )
  195. cy.findByRole('button', { name: /actions/i })
  196. })
  197. it('should show the correct menu when dropdown button is clicked', function () {
  198. cy.findByRole('button', { name: /actions/i }).click()
  199. cy.findByTestId('resend-managed-user-invite-action').should(
  200. 'be.visible'
  201. )
  202. cy.findByTestId('remove-user-action').should('be.visible')
  203. cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
  204. cy.findByTestId('no-actions-available').should('not.exist')
  205. })
  206. })
  207. describe('for a managed group admin user', function () {
  208. const user: User = {
  209. _id: 'some-user',
  210. email: 'some.user@example.com',
  211. first_name: 'Some',
  212. last_name: 'User',
  213. invite: false,
  214. last_active_at: new Date(),
  215. enrollment: {
  216. managedBy: subscriptionId,
  217. enrolledAt: new Date(),
  218. },
  219. isEntityAdmin: true,
  220. }
  221. beforeEach(function () {
  222. cy.window().then(win => {
  223. win.metaAttributesCache.set('ol-users', [user])
  224. })
  225. mountDropDownComponent(user, subscriptionId)
  226. })
  227. it('should render the button', function () {
  228. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  229. 'exist'
  230. )
  231. cy.findByRole('button', { name: /actions/i })
  232. })
  233. it('should show the (empty) menu when the button is clicked', function () {
  234. cy.findByRole('button', { name: /actions/i }).click()
  235. cy.findByTestId('no-actions-available').should('exist')
  236. })
  237. })
  238. })
  239. describe('with Group SSO enabled', function () {
  240. beforeEach(function () {
  241. cy.window().then(win => {
  242. win.metaAttributesCache.set('ol-managedUsersActive', false)
  243. win.metaAttributesCache.set('ol-groupSSOActive', true)
  244. })
  245. })
  246. describe('for a pending user (has not joined group)', function () {
  247. const user: User = {
  248. _id: 'some-user',
  249. email: 'some.user@example.com',
  250. first_name: 'Some',
  251. last_name: 'User',
  252. invite: true,
  253. last_active_at: new Date(),
  254. enrollment: {},
  255. isEntityAdmin: undefined,
  256. }
  257. beforeEach(function () {
  258. cy.window().then(win => {
  259. win.metaAttributesCache.set('ol-users', [user])
  260. })
  261. mountDropDownComponent(user, subscriptionId)
  262. })
  263. it('should render dropdown button', function () {
  264. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  265. 'exist'
  266. )
  267. cy.findByRole('button', { name: /actions/i })
  268. })
  269. it('should show the correct menu when dropdown button is clicked', function () {
  270. cy.findByRole('button', { name: /actions/i }).click()
  271. cy.findByTestId('resend-group-invite-action').should('be.visible')
  272. cy.findByTestId('remove-user-action').should('be.visible')
  273. cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
  274. cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
  275. cy.findByTestId('unlink-user-action').should('not.exist')
  276. cy.findByTestId('no-actions-available').should('not.exist')
  277. })
  278. })
  279. describe('for a group member not linked with SSO yet', function () {
  280. const user: User = {
  281. _id: 'some-user',
  282. email: 'some.user@example.com',
  283. first_name: 'Some',
  284. last_name: 'User',
  285. invite: false,
  286. last_active_at: new Date(),
  287. enrollment: {},
  288. isEntityAdmin: undefined,
  289. }
  290. beforeEach(function () {
  291. cy.window().then(win => {
  292. win.metaAttributesCache.set('ol-users', [user])
  293. })
  294. })
  295. it('should show resend invite when user is admin', function () {
  296. mountDropDownComponent({ ...user, isEntityAdmin: true }, '123abc')
  297. cy.findByRole('button', { name: /actions/i }).click()
  298. cy.findByTestId('resend-sso-link-invite-action').should('exist')
  299. })
  300. it('should not show resend invite when SSO is disabled', function () {
  301. cy.window().then(win => {
  302. win.metaAttributesCache.set('ol-groupSSOActive', false)
  303. })
  304. mountDropDownComponent(user, '123abc')
  305. cy.findByRole('button', { name: /actions/i }).click()
  306. cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
  307. })
  308. it('should show the resend SSO invite option when dropdown button is clicked', function () {
  309. cy.window().then(win => {
  310. win.metaAttributesCache.set('ol-groupSSOActive', true)
  311. })
  312. mountDropDownComponent(user, '123abc')
  313. cy.findByRole('button', { name: /actions/i }).click()
  314. cy.findByTestId('resend-sso-link-invite-action').should('be.visible')
  315. })
  316. it('should make the correct post request when resend SSO invite is clicked ', function () {
  317. cy.window().then(win => {
  318. win.metaAttributesCache.set('ol-groupSSOActive', true)
  319. })
  320. cy.intercept(
  321. 'POST',
  322. '/manage/groups/123abc/resendSSOLinkInvite/some-user',
  323. { success: true }
  324. ).as('resendInviteRequest')
  325. mountDropDownComponent(user, '123abc')
  326. cy.findByRole('button', { name: /actions/i }).click()
  327. cy.findByTestId('resend-sso-link-invite-action')
  328. .should('exist')
  329. .as('resendInvite')
  330. cy.get('@resendInvite').click()
  331. cy.wait('@resendInviteRequest')
  332. })
  333. })
  334. })
  335. describe('with Managed Users and Group SSO enabled', function () {
  336. beforeEach(function () {
  337. cy.window().then(win => {
  338. win.metaAttributesCache.set('ol-managedUsersActive', true)
  339. win.metaAttributesCache.set('ol-groupSSOActive', true)
  340. })
  341. })
  342. describe('for a pending user (has not joined group)', function () {
  343. const user: User = {
  344. _id: 'some-user',
  345. email: 'some.user@example.com',
  346. first_name: 'Some',
  347. last_name: 'User',
  348. invite: true,
  349. last_active_at: new Date(),
  350. enrollment: {},
  351. isEntityAdmin: undefined,
  352. }
  353. beforeEach(function () {
  354. cy.window().then(win => {
  355. win.metaAttributesCache.set('ol-users', [user])
  356. })
  357. mountDropDownComponent(user, subscriptionId)
  358. })
  359. it('should render dropdown button', function () {
  360. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  361. 'exist'
  362. )
  363. cy.findByRole('button', { name: /actions/i })
  364. })
  365. it('should show the correct menu when dropdown button is clicked', function () {
  366. cy.findByRole('button', { name: /actions/i }).click()
  367. cy.findByTestId('resend-group-invite-action').should('be.visible')
  368. cy.findByTestId('remove-user-action').should('be.visible')
  369. cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
  370. cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
  371. cy.findByTestId('unlink-user-action').should('not.exist')
  372. cy.findByTestId('no-actions-available').should('not.exist')
  373. })
  374. })
  375. describe('for a non-managed group member with SSO linked', function () {
  376. const user: User = {
  377. _id: 'some-user',
  378. email: 'some.user@example.com',
  379. first_name: 'Some',
  380. last_name: 'User',
  381. invite: false,
  382. last_active_at: new Date(),
  383. enrollment: {
  384. sso: [
  385. {
  386. groupId: subscriptionId,
  387. linkedAt: new Date(),
  388. primary: true,
  389. },
  390. ],
  391. },
  392. isEntityAdmin: undefined,
  393. }
  394. beforeEach(function () {
  395. cy.window().then(win => {
  396. win.metaAttributesCache.set('ol-users', [user])
  397. })
  398. mountDropDownComponent(user, subscriptionId)
  399. })
  400. it('should render dropdown button', function () {
  401. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  402. 'exist'
  403. )
  404. cy.findByRole('button', { name: /actions/i })
  405. })
  406. it('should show the correct menu when dropdown button is clicked', function () {
  407. cy.findByRole('button', { name: /actions/i }).click()
  408. cy.findByTestId('resend-managed-user-invite-action').should(
  409. 'be.visible'
  410. )
  411. cy.findByTestId('remove-user-action').should('be.visible')
  412. cy.findByTestId('unlink-user-action').should('be.visible')
  413. cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
  414. })
  415. })
  416. describe('for a non-managed group member with SSO not linked', function () {
  417. const user: User = {
  418. _id: 'some-user',
  419. email: 'some.user@example.com',
  420. first_name: 'Some',
  421. last_name: 'User',
  422. invite: false,
  423. last_active_at: new Date(),
  424. enrollment: {
  425. sso: [],
  426. },
  427. isEntityAdmin: undefined,
  428. }
  429. beforeEach(function () {
  430. cy.window().then(win => {
  431. win.metaAttributesCache.set('ol-users', [user])
  432. })
  433. mountDropDownComponent(user, subscriptionId)
  434. })
  435. it('should render dropdown button', function () {
  436. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  437. 'exist'
  438. )
  439. cy.findByRole('button', { name: /actions/i })
  440. })
  441. it('should show the correct menu when dropdown button is clicked', function () {
  442. cy.findByRole('button', { name: /actions/i }).click()
  443. cy.findByTestId('resend-managed-user-invite-action').should(
  444. 'be.visible'
  445. )
  446. cy.findByTestId('remove-user-action').should('be.visible')
  447. cy.findByTestId('resend-sso-link-invite-action').should('be.visible')
  448. cy.findByTestId('no-actions-available').should('not.exist')
  449. cy.findByTestId('unlink-user-action').should('not.exist')
  450. })
  451. })
  452. describe('for a non-managed group admin with SSO linked', function () {
  453. const user: User = {
  454. _id: 'some-user',
  455. email: 'some.user@example.com',
  456. first_name: 'Some',
  457. last_name: 'User',
  458. invite: false,
  459. last_active_at: new Date(),
  460. enrollment: {
  461. sso: [
  462. {
  463. groupId: subscriptionId,
  464. linkedAt: new Date(),
  465. primary: true,
  466. },
  467. ],
  468. },
  469. isEntityAdmin: true,
  470. }
  471. beforeEach(function () {
  472. cy.window().then(win => {
  473. win.metaAttributesCache.set('ol-users', [user])
  474. })
  475. mountDropDownComponent(user, subscriptionId)
  476. })
  477. it('should render dropdown button', function () {
  478. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  479. 'exist'
  480. )
  481. cy.findByRole('button', { name: /actions/i })
  482. })
  483. it('should show the correct menu when dropdown button is clicked', function () {
  484. cy.findByRole('button', { name: /actions/i }).click()
  485. cy.findByTestId('resend-managed-user-invite-action').should(
  486. 'be.visible'
  487. )
  488. cy.findByTestId('remove-user-action').should('be.visible')
  489. cy.findByTestId('unlink-user-action').should('be.visible')
  490. cy.findByTestId('delete-user-action').should('not.exist')
  491. cy.findByTestId('release-user-action').should('not.exist')
  492. cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
  493. cy.findByTestId('no-actions-available').should('not.exist')
  494. })
  495. })
  496. describe('for a non-managed group admin with SSO not linked', function () {
  497. const user: User = {
  498. _id: 'some-user',
  499. email: 'some.user@example.com',
  500. first_name: 'Some',
  501. last_name: 'User',
  502. invite: false,
  503. last_active_at: new Date(),
  504. enrollment: {
  505. sso: [],
  506. },
  507. isEntityAdmin: true,
  508. }
  509. beforeEach(function () {
  510. cy.window().then(win => {
  511. win.metaAttributesCache.set('ol-users', [user])
  512. })
  513. mountDropDownComponent(user, subscriptionId)
  514. })
  515. it('should render dropdown button', function () {
  516. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  517. 'exist'
  518. )
  519. cy.findByRole('button', { name: /actions/i })
  520. })
  521. it('should show the correct menu when dropdown button is clicked', function () {
  522. cy.findByRole('button', { name: /actions/i }).click()
  523. cy.findByTestId('resend-managed-user-invite-action').should(
  524. 'be.visible'
  525. )
  526. cy.findByTestId('remove-user-action').should('be.visible')
  527. cy.findByTestId('delete-user-action').should('not.exist')
  528. cy.findByTestId('release-user-action').should('not.exist')
  529. cy.findByTestId('resend-sso-link-invite-action').should('exist')
  530. cy.findByTestId('no-actions-available').should('not.exist')
  531. })
  532. })
  533. describe('for a managed group member with SSO not linked', function () {
  534. const user: User = {
  535. _id: 'some-user',
  536. email: 'some.user@example.com',
  537. first_name: 'Some',
  538. last_name: 'User',
  539. invite: false,
  540. last_active_at: new Date(),
  541. enrollment: {
  542. managedBy: subscriptionId,
  543. enrolledAt: new Date(),
  544. sso: [],
  545. },
  546. isEntityAdmin: undefined,
  547. }
  548. beforeEach(function () {
  549. cy.window().then(win => {
  550. win.metaAttributesCache.set('ol-users', [user])
  551. win.metaAttributesCache.set('ol-isUserGroupManager', true)
  552. })
  553. mountDropDownComponent(user, subscriptionId)
  554. })
  555. it('should render the dropdown button', function () {
  556. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  557. 'exist'
  558. )
  559. cy.findByRole('button', { name: /actions/i })
  560. })
  561. it('should show the correct menu when dropdown button is clicked', function () {
  562. cy.findByRole('button', { name: /actions/i }).click()
  563. cy.findByTestId('delete-user-action').should('be.visible')
  564. cy.findByTestId('release-user-action')
  565. cy.findByTestId('remove-user-action').should('not.exist')
  566. cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
  567. cy.findByTestId('resend-sso-link-invite-action').should('exist')
  568. cy.findByTestId('no-actions-available').should('not.exist')
  569. })
  570. })
  571. describe('for a managed group member with SSO linked', function () {
  572. const user: User = {
  573. _id: 'some-user',
  574. email: 'some.user@example.com',
  575. first_name: 'Some',
  576. last_name: 'User',
  577. invite: false,
  578. last_active_at: new Date(),
  579. enrollment: {
  580. managedBy: subscriptionId,
  581. enrolledAt: new Date(),
  582. sso: [
  583. {
  584. groupId: subscriptionId,
  585. linkedAt: new Date(),
  586. primary: true,
  587. },
  588. ],
  589. },
  590. isEntityAdmin: undefined,
  591. }
  592. beforeEach(function () {
  593. cy.window().then(win => {
  594. win.metaAttributesCache.set('ol-users', [user])
  595. win.metaAttributesCache.set('ol-isUserGroupManager', true)
  596. })
  597. mountDropDownComponent(user, subscriptionId)
  598. })
  599. it('should render the dropdown button', function () {
  600. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  601. 'exist'
  602. )
  603. cy.findByRole('button', { name: /actions/i })
  604. })
  605. it('should show the correct menu when dropdown button is clicked', function () {
  606. cy.findByRole('button', { name: /actions/i }).click()
  607. cy.findByTestId('delete-user-action').should('be.visible')
  608. cy.findByTestId('release-user-action')
  609. cy.findByTestId('remove-user-action').should('not.exist')
  610. cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
  611. cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
  612. cy.findByTestId('no-actions-available').should('not.exist')
  613. })
  614. })
  615. describe('for a managed group admin with SSO not linked', function () {
  616. const user: User = {
  617. _id: 'some-user',
  618. email: 'some.user@example.com',
  619. first_name: 'Some',
  620. last_name: 'User',
  621. invite: false,
  622. last_active_at: new Date(),
  623. enrollment: {
  624. managedBy: subscriptionId,
  625. enrolledAt: new Date(),
  626. sso: [],
  627. },
  628. isEntityAdmin: true,
  629. }
  630. beforeEach(function () {
  631. cy.window().then(win => {
  632. win.metaAttributesCache.set('ol-users', [user])
  633. })
  634. mountDropDownComponent(user, subscriptionId)
  635. })
  636. it('should render the button', function () {
  637. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  638. 'exist'
  639. )
  640. cy.findByRole('button', { name: /actions/i })
  641. })
  642. it('should show the correct menu when dropdown button is clicked', function () {
  643. cy.findByRole('button', { name: /actions/i }).click()
  644. cy.findByTestId('resend-sso-link-invite-action').should('exist')
  645. cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
  646. cy.findByTestId('remove-user-action').should('not.exist')
  647. cy.findByTestId('delete-user-action').should('not.exist')
  648. cy.findByTestId('release-user-action').should('not.exist')
  649. cy.findByTestId('no-actions-available').should('not.exist')
  650. })
  651. })
  652. describe('for a managed group admin with SSO linked', function () {
  653. const user: User = {
  654. _id: 'some-user',
  655. email: 'some.user@example.com',
  656. first_name: 'Some',
  657. last_name: 'User',
  658. invite: false,
  659. last_active_at: new Date(),
  660. enrollment: {
  661. managedBy: subscriptionId,
  662. enrolledAt: new Date(),
  663. sso: [
  664. {
  665. groupId: subscriptionId,
  666. linkedAt: new Date(),
  667. primary: true,
  668. },
  669. ],
  670. },
  671. isEntityAdmin: true,
  672. }
  673. beforeEach(function () {
  674. cy.window().then(win => {
  675. win.metaAttributesCache.set('ol-users', [user])
  676. })
  677. mountDropDownComponent(user, subscriptionId)
  678. })
  679. it('should render the button', function () {
  680. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  681. 'exist'
  682. )
  683. cy.findByRole('button', { name: /actions/i })
  684. })
  685. it('should show no actions except to unlink when dropdown button is clicked', function () {
  686. cy.findByRole('button', { name: /actions/i }).click()
  687. cy.findByTestId('unlink-user-action').should('exist')
  688. cy.findByTestId('no-actions-available').should('not.exist')
  689. cy.findByTestId('delete-user-action').should('not.exist')
  690. cy.findByTestId('release-user-action').should('not.exist')
  691. cy.findByTestId('remove-user-action').should('not.exist')
  692. cy.findByTestId('resend-managed-user-invite-action').should('not.exist')
  693. cy.findByTestId('resend-sso-link-invite-action').should('not.exist')
  694. })
  695. })
  696. })
  697. })