educationalMenuBuilder.test.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import { describe, test, expect, vi, beforeEach } from 'vitest'
  2. import type { RuntimeConfig } from '@nuxt/schema'
  3. //@ts-expect-error problème de typage sans conséquence
  4. import type { AnyAbility } from '@casl/ability/dist/types'
  5. import type { Router } from 'vue-router'
  6. import type { AccessProfile, organizationState } from '~/types/interfaces'
  7. import EducationalMenuBuilder from '~/services/layout/menuBuilder/educationalMenuBuilder'
  8. import type { MenuGroup } from '~/types/layout'
  9. import { MENU_LINK_TYPE } from '~/types/enum/layout'
  10. let runtimeConfig: RuntimeConfig
  11. let ability: AnyAbility
  12. let organizationProfile: organizationState
  13. let accessProfile: AccessProfile
  14. let menuBuilder: EducationalMenuBuilder
  15. let router: Router
  16. beforeEach(() => {
  17. runtimeConfig = vi.fn() as any as RuntimeConfig
  18. ability = vi.fn() as any as AnyAbility
  19. organizationProfile = vi.fn() as any as organizationState
  20. accessProfile = vi.fn() as any as AccessProfile
  21. // @ts-ignore
  22. router = vi.fn() as Router
  23. runtimeConfig.baseUrlAdminLegacy = 'https://mydomain.com/'
  24. menuBuilder = new EducationalMenuBuilder(
  25. runtimeConfig,
  26. ability,
  27. organizationProfile,
  28. accessProfile,
  29. router,
  30. )
  31. })
  32. describe('getMenuName', () => {
  33. test('validate name', () => {
  34. expect(menuBuilder.getMenuName()).toEqual('Educational')
  35. })
  36. })
  37. describe('build', () => {
  38. test('has all items', () => {
  39. ability.can = vi.fn(() => true)
  40. // Should return a MenuGroup
  41. const result = menuBuilder.build() as MenuGroup
  42. expect(result.label).toEqual('education_state')
  43. expect(result.icon).toEqual({ name: 'fas fa-graduation-cap' })
  44. // @ts-ignore
  45. expect(result.children.length).toEqual(7)
  46. })
  47. test('has no items', () => {
  48. ability.can = vi.fn(() => false)
  49. expect(menuBuilder.build()).toEqual(null)
  50. })
  51. test('has only rights for menu criteria_notations', () => {
  52. ability.can = vi.fn(
  53. (action: string, subject: string) =>
  54. action === 'display' && subject === 'criteria_notations_page',
  55. )
  56. expect(menuBuilder.build()).toEqual({
  57. label: 'criteria_notations',
  58. icon: { name: 'fas fa-bars' },
  59. to: 'https://mydomain.com/#/criteria_notations/list/',
  60. target: '_self',
  61. type: MENU_LINK_TYPE.V1,
  62. active: false,
  63. endOfSubsection: false,
  64. })
  65. })
  66. test('has only rights for menu seizure_period', () => {
  67. ability.can = vi.fn(
  68. (action: string, subject: string) =>
  69. action === 'display' && subject === 'seizure_period_page',
  70. )
  71. expect(menuBuilder.build()).toEqual({
  72. label: 'seizure_period',
  73. icon: { name: 'fas fa-calendar-alt' },
  74. to: 'https://mydomain.com/#/education_teachers/list/',
  75. target: '_self',
  76. type: MENU_LINK_TYPE.V1,
  77. active: false,
  78. endOfSubsection: false,
  79. })
  80. })
  81. test('has only rights for menu test_seizure', () => {
  82. ability.can = vi.fn(
  83. (action: string, subject: string) =>
  84. action === 'display' && subject === 'test_seizure_page',
  85. )
  86. expect(menuBuilder.build()).toEqual({
  87. label: 'test_seizure',
  88. icon: { name: 'fas fa-pencil-alt' },
  89. to: 'https://mydomain.com/#/education_input/list/',
  90. target: '_self',
  91. type: MENU_LINK_TYPE.V1,
  92. active: false,
  93. endOfSubsection: false,
  94. })
  95. })
  96. test('has only rights for menu test_validation', () => {
  97. ability.can = vi.fn(
  98. (action: string, subject: string) =>
  99. action === 'display' && subject === 'test_validation_page',
  100. )
  101. expect(menuBuilder.build()).toEqual({
  102. label: 'test_validation',
  103. icon: { name: 'fas fa-check' },
  104. to: 'https://mydomain.com/#/education_notations/list/',
  105. target: '_self',
  106. type: MENU_LINK_TYPE.V1,
  107. active: false,
  108. endOfSubsection: false,
  109. })
  110. })
  111. test('has only rights for menu examen_results', () => {
  112. ability.can = vi.fn(
  113. (action: string, subject: string) =>
  114. action === 'display' && subject === 'examen_results_page',
  115. )
  116. expect(menuBuilder.build()).toEqual({
  117. label: 'examen_results',
  118. icon: { name: 'fas fa-graduation-cap' },
  119. to: 'https://mydomain.com/#/examen_convocations/list/',
  120. target: '_self',
  121. type: MENU_LINK_TYPE.V1,
  122. active: false,
  123. endOfSubsection: false,
  124. })
  125. })
  126. test('has only rights for menu education_by_student_validation', () => {
  127. ability.can = vi.fn(
  128. (action: string, subject: string) =>
  129. action === 'display' &&
  130. subject === 'education_by_student_validation_page',
  131. )
  132. expect(menuBuilder.build()).toEqual({
  133. label: 'education_by_student_validation',
  134. icon: { name: 'fas fa-check-square' },
  135. to: 'https://mydomain.com/#/education_by_student/list/',
  136. target: '_self',
  137. type: MENU_LINK_TYPE.V1,
  138. active: false,
  139. endOfSubsection: false,
  140. })
  141. })
  142. })