group-users.spec.tsx 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  1. import GroupUsers from '@/features/group-management/components/group-users'
  2. import { GroupMembersProvider } from '@/features/group-management/context/group-members-context'
  3. import { User } from '../../../../../types/group-management/user'
  4. const GROUP_ID = '777fff777fff'
  5. describe('GroupUsers', function () {
  6. function mountGroupUsersProvider() {
  7. cy.mount(
  8. <GroupMembersProvider>
  9. <GroupUsers />
  10. </GroupMembersProvider>
  11. )
  12. }
  13. describe('renders the user management page', function () {
  14. // Admin user who is also a Member (has a license allocated)
  15. const JOHN_DOE: User = {
  16. _id: 'abc123def456',
  17. first_name: 'John',
  18. last_name: 'Doe',
  19. email: 'john.doe@test.com',
  20. last_active_at: new Date('2023-01-15'),
  21. invite: false,
  22. isEntityMember: true,
  23. isEntityAdmin: true,
  24. }
  25. // Manager who is not a Member (does not have a license allocated)
  26. const BOBBY_LAPOINTE: User = {
  27. _id: 'bcd234efa567',
  28. first_name: 'Bobby',
  29. last_name: 'Lapointe',
  30. email: 'bobby.lapointe@test.com',
  31. last_active_at: new Date('2023-01-02'),
  32. invite: false,
  33. isEntityManager: true,
  34. }
  35. // User with a pending invite
  36. const CLAIRE_JENNINGS: User = {
  37. _id: 'defabc231453',
  38. first_name: 'Claire',
  39. last_name: 'Jennings',
  40. email: 'claire.jennings@test.com',
  41. last_active_at: new Date('2023-01-03'),
  42. invite: true,
  43. }
  44. // User in the Members list
  45. const DAVID_JONES: User = {
  46. _id: 'badcab391832',
  47. first_name: 'David',
  48. last_name: 'Jones',
  49. email: 'david.jones@test.com',
  50. last_active_at: new Date('2023-01-04'),
  51. invite: false,
  52. isEntityMember: true,
  53. }
  54. beforeEach(function () {
  55. cy.window().then(win => {
  56. win.metaAttributesCache.set('ol-groupId', GROUP_ID)
  57. win.metaAttributesCache.set('ol-groupName', 'My Awesome Team')
  58. win.metaAttributesCache.set('ol-groupSize', 10)
  59. win.metaAttributesCache.set('ol-users', [
  60. JOHN_DOE,
  61. BOBBY_LAPOINTE,
  62. CLAIRE_JENNINGS,
  63. DAVID_JONES,
  64. ])
  65. win.metaAttributesCache.set('ol-hasWriteAccess', true)
  66. })
  67. mountGroupUsersProvider()
  68. })
  69. it('displays license information correctly', function () {
  70. cy.get('.license-info').contains(
  71. 'You have allocated 2 licenses and your plan supports up to 10'
  72. )
  73. })
  74. it('displays correct user information', function () {
  75. cy.get('table tbody').within(() => {
  76. cy.get('tr:nth-child(1)').within(() => {
  77. cy.contains('john.doe@test.com')
  78. cy.contains('John Doe')
  79. cy.contains('15th Jan 2023')
  80. cy.findByRole('combobox', { name: 'Select user role' }).should(
  81. 'have.value',
  82. 'admin'
  83. )
  84. cy.contains('License allocated')
  85. })
  86. cy.get('tr:nth-child(2)').within(() => {
  87. cy.contains('bobby.lapointe@test.com')
  88. cy.contains('Bobby Lapointe')
  89. cy.contains('2nd Jan 2023')
  90. cy.findByRole('combobox', { name: 'Select user role' }).should(
  91. 'have.value',
  92. 'manager'
  93. )
  94. cy.contains('License not allocated')
  95. })
  96. cy.get('tr:nth-child(3)').within(() => {
  97. cy.contains('claire.jennings@test.com')
  98. cy.contains('Claire Jennings')
  99. cy.contains('Pending invite')
  100. cy.findByRole('combobox', { name: 'Select user role' }).should(
  101. 'have.value',
  102. 'member'
  103. )
  104. cy.contains('License not allocated')
  105. })
  106. cy.get('tr:nth-child(4)').within(() => {
  107. cy.contains('david.jones@test.com')
  108. cy.contains('David Jones')
  109. cy.contains('4th Jan 2023')
  110. cy.findByRole('combobox', { name: 'Select user role' }).should(
  111. 'have.value',
  112. 'member'
  113. )
  114. cy.contains('License allocated')
  115. })
  116. })
  117. })
  118. })
  119. describe('with flexible group licensing enabled', function () {
  120. beforeEach(function () {
  121. this.JOHN_DOE = {
  122. _id: 'abc123def456',
  123. first_name: 'John',
  124. last_name: 'Doe',
  125. email: 'john.doe@test.com',
  126. last_active_at: new Date('2023-01-15'),
  127. invite: false,
  128. isEntityMember: true,
  129. }
  130. cy.window().then(win => {
  131. win.metaAttributesCache.set('ol-groupId', GROUP_ID)
  132. win.metaAttributesCache.set('ol-groupName', 'My Awesome Team')
  133. win.metaAttributesCache.set('ol-canUseAddSeatsFeature', true)
  134. win.metaAttributesCache.set('ol-hasWriteAccess', true)
  135. win.metaAttributesCache.set('ol-users', [this.JOHN_DOE])
  136. })
  137. })
  138. it('shows buy more licenses link when not at group capacity', function () {
  139. cy.window().then(win => {
  140. win.metaAttributesCache.set('ol-groupSize', 10)
  141. })
  142. mountGroupUsersProvider()
  143. cy.findByRole('link', { name: 'Buy more licenses' })
  144. .should('exist')
  145. .should('not.have.class', 'btn')
  146. })
  147. it('shows buy more licenses as a premium button when at group capacity', function () {
  148. cy.window().then(win => {
  149. win.metaAttributesCache.set('ol-groupSize', 1)
  150. })
  151. mountGroupUsersProvider()
  152. cy.findByRole('link', { name: 'Buy more licenses' })
  153. .should('exist')
  154. .should('have.class', 'btn')
  155. })
  156. })
  157. describe('with Group SSO enabled', function () {
  158. const JOHN_DOE: User = {
  159. _id: 'abc123def456',
  160. first_name: 'John',
  161. last_name: 'Doe',
  162. email: 'john.doe@test.com',
  163. last_active_at: new Date('2023-01-15'),
  164. invite: false,
  165. isEntityMember: true,
  166. }
  167. const SSO_USER: User = {
  168. _id: 'bcd234efa567',
  169. first_name: 'SSO',
  170. last_name: 'User',
  171. email: 'sso.user@test.com',
  172. last_active_at: new Date('2023-01-02'),
  173. invite: false,
  174. isEntityMember: true,
  175. enrollment: {
  176. managedBy: GROUP_ID,
  177. enrolledAt: new Date('2023-01-02'),
  178. sso: [
  179. {
  180. groupId: GROUP_ID,
  181. linkedAt: new Date(),
  182. primary: true,
  183. },
  184. ],
  185. },
  186. }
  187. beforeEach(function () {
  188. cy.window().then(win => {
  189. win.metaAttributesCache.set('ol-users', [JOHN_DOE, SSO_USER])
  190. win.metaAttributesCache.set('ol-groupId', GROUP_ID)
  191. win.metaAttributesCache.set('ol-groupName', 'My Awesome Team')
  192. win.metaAttributesCache.set('ol-groupSize', 10)
  193. win.metaAttributesCache.set('ol-groupSSOActive', true)
  194. win.metaAttributesCache.set('ol-hasWriteAccess', true)
  195. })
  196. mountGroupUsersProvider()
  197. })
  198. it('displays the SSO column', function () {
  199. cy.get('table thead').within(() => {
  200. cy.contains('SSO')
  201. })
  202. })
  203. it('shows SSO status correctly', function () {
  204. cy.get('table tbody').within(() => {
  205. cy.get('tr:nth-child(1)').within(() => {
  206. cy.contains('john.doe@test.com')
  207. cy.contains('SSO not active')
  208. })
  209. cy.get('tr:nth-child(2)').within(() => {
  210. cy.contains('sso.user@test.com')
  211. cy.contains('SSO active')
  212. })
  213. })
  214. })
  215. })
  216. describe('with Managed Users enabled', function () {
  217. const JOHN_DOE: User = {
  218. _id: 'abc123def456',
  219. first_name: 'John',
  220. last_name: 'Doe',
  221. email: 'john.doe@test.com',
  222. last_active_at: new Date('2023-01-15'),
  223. invite: false,
  224. isEntityMember: true,
  225. }
  226. const MANAGED_USER: User = {
  227. _id: 'bcd234efa567',
  228. first_name: 'Managed',
  229. last_name: 'User',
  230. email: 'managed.user@test.com',
  231. last_active_at: new Date('2023-01-02'),
  232. invite: false,
  233. isEntityMember: true,
  234. enrollment: {
  235. managedBy: GROUP_ID,
  236. enrolledAt: new Date('2023-01-02'),
  237. sso: [
  238. {
  239. groupId: GROUP_ID,
  240. linkedAt: new Date(),
  241. primary: true,
  242. },
  243. ],
  244. },
  245. }
  246. beforeEach(function () {
  247. cy.window().then(win => {
  248. win.metaAttributesCache.set('ol-users', [JOHN_DOE, MANAGED_USER])
  249. win.metaAttributesCache.set('ol-groupId', GROUP_ID)
  250. win.metaAttributesCache.set('ol-groupName', 'My Awesome Team')
  251. win.metaAttributesCache.set('ol-groupSize', 10)
  252. win.metaAttributesCache.set('ol-managedUsersActive', true)
  253. win.metaAttributesCache.set('ol-hasWriteAccess', true)
  254. })
  255. mountGroupUsersProvider()
  256. })
  257. it('displays the Managed column', function () {
  258. cy.get('table thead').within(() => {
  259. cy.contains('Managed')
  260. })
  261. })
  262. it('shows managed status correctly', function () {
  263. cy.get('table tbody').within(() => {
  264. cy.get('tr:nth-child(1)').within(() => {
  265. cy.contains('john.doe@test.com')
  266. cy.contains('Not managed')
  267. })
  268. cy.get('tr:nth-child(2)').within(() => {
  269. cy.contains('managed.user@test.com')
  270. cy.contains('Managed')
  271. })
  272. })
  273. })
  274. })
  275. describe('pagination', function () {
  276. beforeEach(function () {
  277. // Create 25 users to test pagination
  278. const users = Array(25)
  279. .fill({})
  280. .map((_, i) => ({
  281. _id: `user${i}`,
  282. first_name: `User${i}`,
  283. last_name: `Test${i}`,
  284. email: `user${i}@test.com`,
  285. last_active_at: new Date('2023-01-15'),
  286. invite: false,
  287. isEntityMember: true,
  288. }))
  289. cy.window().then(win => {
  290. win.metaAttributesCache.set('ol-groupId', GROUP_ID)
  291. win.metaAttributesCache.set('ol-groupName', 'My Awesome Team')
  292. win.metaAttributesCache.set('ol-groupSize', 30)
  293. win.metaAttributesCache.set('ol-users', users)
  294. win.metaAttributesCache.set('ol-hasWriteAccess', true)
  295. })
  296. mountGroupUsersProvider()
  297. })
  298. it('displays the first page correctly', function () {
  299. cy.contains('Showing 10 out of 25 users')
  300. cy.contains('Page 1 of 3')
  301. cy.contains('User0 Test0')
  302. cy.get('table tbody tr').should('have.length', 10)
  303. })
  304. it('first page and previous buttons are disabled on first page', function () {
  305. cy.findByRole('button', { name: 'Go to first page' }).should(
  306. 'be.disabled'
  307. )
  308. cy.findByRole('button', { name: 'Go to previous page' }).should(
  309. 'be.disabled'
  310. )
  311. })
  312. it('navigates to next page', function () {
  313. cy.findByRole('button', { name: 'Go to next page' }).click()
  314. cy.contains('Page 2 of 3')
  315. cy.contains('User10 Test10')
  316. cy.findByText('User0 Test0').should('not.exist')
  317. cy.get('table tbody tr').should('have.length', 10)
  318. })
  319. it('navigates to last page', function () {
  320. cy.findByRole('button', { name: 'Go to last page' }).click()
  321. cy.contains('Page 3 of 3')
  322. cy.contains('Showing 5 out of 25 users')
  323. cy.contains('User20 Test20')
  324. cy.findByText('User0 Test0').should('not.exist')
  325. cy.get('table tbody tr').should('have.length', 5)
  326. })
  327. it('last page and next buttons are disabled on last page', function () {
  328. cy.findByRole('button', { name: 'Go to last page' }).click()
  329. cy.findByRole('button', { name: 'Go to last page' }).should('be.disabled')
  330. cy.findByRole('button', { name: 'Go to next page' }).should('be.disabled')
  331. })
  332. it('navigates to first page', function () {
  333. // Navigate to last page so first page button works
  334. cy.findByRole('button', { name: 'Go to last page' }).click()
  335. cy.findByRole('button', { name: 'Go to first page' }).click()
  336. cy.contains('Page 1 of 3')
  337. })
  338. it('navigates to previous page', function () {
  339. // Navigate to last page so previous page button works
  340. cy.findByRole('button', { name: 'Go to last page' }).click()
  341. cy.findByRole('button', { name: 'Go to previous page' }).click()
  342. cy.contains('Page 2 of 3')
  343. })
  344. })
  345. })