dropdown-button.spec.tsx 25 KB

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