parametersMenuBuilder.test.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // TODO: Supprimer l'extension off quand la composition du menu paramètres sera définitive
  2. import { describe, test, it, expect, beforeEach, vi } from 'vitest'
  3. import type {RuntimeConfig} from "@nuxt/schema";
  4. import type {AnyAbility} from "@casl/ability/dist/types";
  5. import type {AccessProfile, organizationState} from "~/types/interfaces";
  6. import ParametersMenuBuilder from "~/services/layout/menuBuilder/parametersMenuBuilder";
  7. import type {MenuGroup} from "~/types/layout";
  8. import {MENU_LINK_TYPE} from "~/types/enum/layout";
  9. let runtimeConfig: RuntimeConfig
  10. let ability: AnyAbility
  11. let organizationProfile: organizationState
  12. let accessProfile: AccessProfile
  13. let menuBuilder: ParametersMenuBuilder
  14. beforeEach(()=> {
  15. runtimeConfig = vi.fn() as any as RuntimeConfig
  16. ability = vi.fn() as any as AnyAbility
  17. organizationProfile = vi.fn() as any as organizationState
  18. accessProfile = vi.fn() as any as AccessProfile
  19. runtimeConfig.baseUrlAdminLegacy = 'https://mydomain.com/'
  20. menuBuilder = new ParametersMenuBuilder(runtimeConfig, ability, organizationProfile, accessProfile)
  21. })
  22. describe('getMenuName', () => {
  23. test('validate name', () => {
  24. expect(menuBuilder.getMenuName()).toEqual("Parameters")
  25. })
  26. })
  27. describe('build', () => {
  28. test('has all items', () => {
  29. ability.can = vi.fn(() => true)
  30. // Should return a MenuGroup
  31. const result = menuBuilder.build() as MenuGroup
  32. expect(result.label).toEqual('parameters')
  33. expect(result.icon).toEqual(undefined)
  34. // @ts-ignore
  35. expect(result.children.length).toEqual(6)
  36. })
  37. test('has no items', () => {
  38. ability.can = vi.fn(() => false)
  39. expect(menuBuilder.build()).toEqual(null)
  40. })
  41. test('has only rights for menu general_params', () => {
  42. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'parameters_page')
  43. // @ts-ignore
  44. expect(menuBuilder.build().children[0]).toEqual(
  45. {label: 'general_params', icon: {name: 'fas fa-cogs'}, to: 'https://mydomain.com/#/parameters', type: MENU_LINK_TYPE.V1, active: false}
  46. )
  47. })
  48. test('has only rights for menu communication_params', () => {
  49. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'parameters_communication_page')
  50. // @ts-ignore
  51. expect(menuBuilder.build().children[0]).toEqual(
  52. {label: 'communication_params', icon: {name: 'fas fa-comments'}, to: 'https://mydomain.com/#/parameters/communication', type: MENU_LINK_TYPE.V1, active: false}
  53. )
  54. })
  55. test('has only rights for menu students_params', () => {
  56. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'parameters_student_page')
  57. // @ts-ignore
  58. expect(menuBuilder.build().children[0]).toEqual(
  59. {label: 'students_params', icon: {name: 'fas fa-users'}, to: 'https://mydomain.com/#/parameters/student', type: MENU_LINK_TYPE.V1, active: false}
  60. )
  61. })
  62. test('has only rights for menu education_params', () => {
  63. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'parameters_education_page')
  64. // @ts-ignore
  65. expect(menuBuilder.build().children[0]).toEqual(
  66. {label: 'education_params', icon: {name: 'fas fa-graduation-cap'}, to: 'https://mydomain.com/#/parameters/education', type: MENU_LINK_TYPE.V1, active: false}
  67. )
  68. })
  69. test('has only rights for menu bills_params', () => {
  70. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'parameters_bills_page')
  71. // @ts-ignore
  72. expect(menuBuilder.build().children[0]).toEqual(
  73. {label: 'bills_params', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/#/parameters/billing', type: MENU_LINK_TYPE.V1, active: false}
  74. )
  75. })
  76. test('has only rights for menu secure_params', () => {
  77. ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'parameters_secure_page')
  78. // @ts-ignore
  79. expect(menuBuilder.build().children[0]).toEqual(
  80. {label: 'secure_params', icon: {name: 'fas fa-lock'}, to: 'https://mydomain.com/#/parameters/secure', type: MENU_LINK_TYPE.V1, active: false}
  81. )
  82. })
  83. })