dropdown-button.spec.tsx 25 KB

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