| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- import { describe, test, expect, vi, beforeEach } from 'vitest'
- import type { RuntimeConfig } from '@nuxt/schema'
- import type { AnyAbility } from '@casl/ability/dist/types'
- import type { Router } from 'vue-router'
- import type { AccessProfile, organizationState } from '~/types/interfaces'
- import EducationalMenuBuilder from '~/services/layout/menuBuilder/educationalMenuBuilder'
- import type { MenuGroup } from '~/types/layout'
- import { MENU_LINK_TYPE } from '~/types/enum/layout'
- let runtimeConfig: RuntimeConfig
- let ability: AnyAbility
- let organizationProfile: organizationState
- let accessProfile: AccessProfile
- let menuBuilder: EducationalMenuBuilder
- let router: Router
- beforeEach(() => {
- runtimeConfig = vi.fn() as any as RuntimeConfig
- ability = vi.fn() as any as AnyAbility
- organizationProfile = vi.fn() as any as organizationState
- accessProfile = vi.fn() as any as AccessProfile
- // @ts-ignore
- router = vi.fn() as Router
- runtimeConfig.baseUrlAdminLegacy = 'https://mydomain.com/'
- menuBuilder = new EducationalMenuBuilder(
- runtimeConfig,
- ability,
- organizationProfile,
- accessProfile,
- router,
- )
- })
- describe('getMenuName', () => {
- test('validate name', () => {
- expect(menuBuilder.getMenuName()).toEqual('Educational')
- })
- })
- describe('build', () => {
- test('has all items', () => {
- ability.can = vi.fn(() => true)
- // Should return a MenuGroup
- const result = menuBuilder.build() as MenuGroup
- expect(result.label).toEqual('education_state')
- expect(result.icon).toEqual({ name: 'fas fa-graduation-cap' })
- // @ts-ignore
- expect(result.children.length).toEqual(7)
- })
- test('has no items', () => {
- ability.can = vi.fn(() => false)
- expect(menuBuilder.build()).toEqual(null)
- })
- test('has only rights for menu criteria_notations', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'criteria_notations_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'criteria_notations',
- icon: { name: 'fas fa-bars' },
- to: 'https://mydomain.com/#/criteria_notations/list/',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu seizure_period', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'seizure_period_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'seizure_period',
- icon: { name: 'fas fa-calendar-alt' },
- to: 'https://mydomain.com/#/education_teachers/list/',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu test_seizure', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'test_seizure_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'test_seizure',
- icon: { name: 'fas fa-pencil-alt' },
- to: 'https://mydomain.com/#/education_input/list/',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu test_validation', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'test_validation_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'test_validation',
- icon: { name: 'fas fa-check' },
- to: 'https://mydomain.com/#/education_notations/list/',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu examen_results', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'examen_results_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'examen_results',
- icon: { name: 'fas fa-graduation-cap' },
- to: 'https://mydomain.com/#/examen_convocations/list/',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu education_by_student_validation', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' &&
- subject === 'education_by_student_validation_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'education_by_student_validation',
- icon: { name: 'fas fa-check-square' },
- to: 'https://mydomain.com/#/education_by_student/list/',
- target: '_self',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- })
|