educationalMenuBuilder.test.ts 4.3 KB

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