managed-user-dropdown-button.spec.tsx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. import type { PropsWithChildren } from 'react'
  2. import sinon from 'sinon'
  3. import ManagedUserDropdownButton from '../../../../../../frontend/js/features/group-management/components/managed-users/managed-user-dropdown-button'
  4. import { GroupMembersProvider } from '../../../../../../frontend/js/features/group-management/context/group-members-context'
  5. function Wrapper({ children }: PropsWithChildren<Record<string, unknown>>) {
  6. return (
  7. <ul className="managed-users-list">
  8. <span
  9. className="managed-users-actions"
  10. style={{ display: 'flex', width: '100%', justifyContent: 'flex-end' }}
  11. >
  12. <GroupMembersProvider>{children}</GroupMembersProvider>
  13. </span>
  14. </ul>
  15. )
  16. }
  17. describe('ManagedUserDropdownButton', function () {
  18. const subscriptionId = '123abc'
  19. describe('with managed user', function () {
  20. const user = {
  21. _id: 'some-user',
  22. email: 'some.user@example.com',
  23. first_name: 'Some',
  24. last_name: 'User',
  25. invite: false,
  26. last_active_at: new Date(),
  27. enrollment: {
  28. managedBy: 'some-group',
  29. enrolledAt: new Date(),
  30. },
  31. isEntityAdmin: undefined,
  32. }
  33. beforeEach(function () {
  34. cy.window().then(win => {
  35. win.metaAttributesCache.set('ol-users', [user])
  36. })
  37. cy.mount(
  38. <Wrapper>
  39. <ManagedUserDropdownButton
  40. user={user}
  41. openOffboardingModalForUser={sinon.stub()}
  42. groupId={subscriptionId}
  43. setManagedUserAlert={sinon.stub()}
  44. />
  45. </Wrapper>
  46. )
  47. })
  48. it('should render dropdown button', function () {
  49. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  50. 'exist'
  51. )
  52. cy.get(`.action-btn`).should('exist')
  53. })
  54. it('should show the correct menu when dropdown button is clicked', function () {
  55. cy.get('.action-btn').click()
  56. cy.findByTestId('delete-user-action').should('exist')
  57. cy.findByTestId('delete-user-action').then($el => {
  58. Cypress.dom.isVisible($el)
  59. })
  60. })
  61. })
  62. describe('with non-managed user (have joined group)', function () {
  63. const user = {
  64. _id: 'some-user',
  65. email: 'some.user@example.com',
  66. first_name: 'Some',
  67. last_name: 'User',
  68. invite: false,
  69. last_active_at: new Date(),
  70. enrollment: {},
  71. isEntityAdmin: undefined,
  72. }
  73. beforeEach(function () {
  74. cy.window().then(win => {
  75. win.metaAttributesCache.set('ol-users', [user])
  76. })
  77. cy.mount(
  78. <Wrapper>
  79. <ManagedUserDropdownButton
  80. user={user}
  81. openOffboardingModalForUser={sinon.stub()}
  82. groupId={subscriptionId}
  83. setManagedUserAlert={sinon.stub()}
  84. />
  85. </Wrapper>
  86. )
  87. })
  88. it('should render dropdown button', function () {
  89. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  90. 'exist'
  91. )
  92. cy.get(`.action-btn`).should('exist')
  93. })
  94. it('should show the correct menu when dropdown button is clicked', function () {
  95. cy.get('.action-btn').click()
  96. cy.findByTestId('resend-managed-user-invite-action').should('exist')
  97. cy.findByTestId('resend-managed-user-invite-action').then($el => {
  98. Cypress.dom.isVisible($el)
  99. })
  100. cy.findByTestId('remove-user-action').should('exist')
  101. cy.findByTestId('remove-user-action').then($el => {
  102. Cypress.dom.isVisible($el)
  103. })
  104. })
  105. })
  106. describe('with pending user (have not joined group)', function () {
  107. const user = {
  108. _id: 'some-user',
  109. email: 'some.user@example.com',
  110. first_name: 'Some',
  111. last_name: 'User',
  112. invite: true,
  113. last_active_at: new Date(),
  114. enrollment: {},
  115. isEntityAdmin: undefined,
  116. }
  117. beforeEach(function () {
  118. cy.window().then(win => {
  119. win.metaAttributesCache.set('ol-users', [user])
  120. })
  121. cy.mount(
  122. <Wrapper>
  123. <ManagedUserDropdownButton
  124. user={user}
  125. openOffboardingModalForUser={sinon.stub()}
  126. groupId={subscriptionId}
  127. setManagedUserAlert={sinon.stub()}
  128. />
  129. </Wrapper>
  130. )
  131. })
  132. it('should render dropdown button', function () {
  133. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  134. 'exist'
  135. )
  136. cy.get(`.action-btn`).should('exist')
  137. })
  138. it('should show the correct menu when dropdown button is clicked', function () {
  139. cy.get('.action-btn').click()
  140. cy.findByTestId('resend-group-invite-action').should('exist')
  141. cy.findByTestId('resend-group-invite-action').then($el => {
  142. Cypress.dom.isVisible($el)
  143. })
  144. cy.findByTestId('remove-user-action').should('exist')
  145. cy.findByTestId('remove-user-action').then($el => {
  146. Cypress.dom.isVisible($el)
  147. })
  148. })
  149. })
  150. describe('with group admin user', function () {
  151. const user = {
  152. _id: 'some-user',
  153. email: 'some.user@example.com',
  154. first_name: 'Some',
  155. last_name: 'User',
  156. invite: false,
  157. last_active_at: new Date(),
  158. enrollment: {},
  159. isEntityAdmin: true,
  160. }
  161. beforeEach(function () {
  162. cy.window().then(win => {
  163. win.metaAttributesCache.set('ol-users', [user])
  164. })
  165. cy.mount(
  166. <Wrapper>
  167. <ManagedUserDropdownButton
  168. user={user}
  169. openOffboardingModalForUser={sinon.stub()}
  170. groupId={subscriptionId}
  171. setManagedUserAlert={sinon.stub()}
  172. />
  173. </Wrapper>
  174. )
  175. })
  176. it('should render dropdown button', function () {
  177. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  178. 'exist'
  179. )
  180. cy.get(`.action-btn`).should('exist')
  181. })
  182. it('should show the (empty) menu when dropdown button is clicked', function () {
  183. cy.get('.action-btn').click()
  184. cy.findByTestId('no-actions-available').should('exist')
  185. })
  186. })
  187. describe('with managed group admin user', function () {
  188. const user = {
  189. _id: 'some-user',
  190. email: 'some.user@example.com',
  191. first_name: 'Some',
  192. last_name: 'User',
  193. invite: false,
  194. last_active_at: new Date(),
  195. enrollment: {
  196. managedBy: 'some-group',
  197. enrolledAt: new Date(),
  198. },
  199. isEntityAdmin: true,
  200. }
  201. beforeEach(function () {
  202. cy.window().then(win => {
  203. win.metaAttributesCache.set('ol-users', [user])
  204. })
  205. cy.mount(
  206. <Wrapper>
  207. <ManagedUserDropdownButton
  208. user={user}
  209. openOffboardingModalForUser={sinon.stub()}
  210. groupId={subscriptionId}
  211. setManagedUserAlert={sinon.stub()}
  212. />
  213. </Wrapper>
  214. )
  215. })
  216. it('should render the button', function () {
  217. cy.get('#managed-user-dropdown-some\\.user\\@example\\.com').should(
  218. 'exist'
  219. )
  220. cy.get(`.action-btn`).should('exist')
  221. })
  222. it('should show the (empty) menu when the button is clicked', function () {
  223. cy.get('.action-btn').click()
  224. cy.findByTestId('no-actions-available').should('exist')
  225. })
  226. })
  227. })