educationalMenuBuilder.test.ts 4.4 KB

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