dropdown-button.spec.tsx 24 KB

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