| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- 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 StatsMenuBuilder from '~/services/layout/menuBuilder/statsMenuBuilder'
- 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: StatsMenuBuilder
- 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 StatsMenuBuilder(
- runtimeConfig,
- ability,
- organizationProfile,
- accessProfile,
- router,
- )
- })
- describe('getMenuName', () => {
- test('validate name', () => {
- expect(menuBuilder.getMenuName()).toEqual('Stats')
- })
- })
- 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('stats')
- expect(result.icon).toEqual({ name: 'fas fa-chart-bar' })
- // @ts-ignore
- expect(result.children.length).toEqual(4)
- })
- test('has no items', () => {
- ability.can = vi.fn(() => false)
- expect(menuBuilder.build()).toEqual(null)
- })
- test('has only rights for menu report_activity', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'report_activity_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'report_activity',
- icon: { name: 'fas fa-chart-bar' },
- to: 'https://mydomain.com/#/report_activity',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu educations_quotas_by_education and accesses_quotas_courses_hebdos', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'education_quotas_page',
- )
- const group = menuBuilder.build() as MenuGroup
- expect(group.children).toEqual([
- {
- label: 'educations_quotas_by_education',
- icon: { name: 'fas fa-user-circle' },
- to: 'https://mydomain.com/#/educations_quotas_by_education_year/list/',
- type: MENU_LINK_TYPE.V1,
- active: false,
- },
- {
- label: 'accesses_quotas_courses_hebdos',
- icon: { name: 'fas fa-user-circle' },
- to: 'https://mydomain.com/#/accesses_quotas_courses_hebdos/list/',
- type: MENU_LINK_TYPE.V1,
- active: false,
- },
- ])
- })
- test('has only rights for menu fede_stats', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'fede_stats_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'fede_stats',
- icon: { name: 'fas fa-chart-bar' },
- to: 'https://mydomain.com/#/statistic/membersfedeonly',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- })
|