| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- import { describe, test, vi, expect, 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 ConfigurationMenuBuilder from '~/services/layout/menuBuilder/configurationMenuBuilder'
- 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: ConfigurationMenuBuilder
- 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 ConfigurationMenuBuilder(
- runtimeConfig,
- ability,
- organizationProfile,
- accessProfile,
- router,
- )
- })
- describe('getMenuName', () => {
- test('validate name', () => {
- expect(menuBuilder.getMenuName()).toEqual('Configuration')
- })
- })
- 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('configuration')
- expect(result.icon).toEqual({ name: 'fas fa-cogs' })
- // @ts-ignore
- expect(result.children.length).toEqual(13)
- })
- test('has no items', () => {
- ability.can = vi.fn(() => false)
- expect(menuBuilder.build()).toEqual(null)
- })
- test('has only rights for menu organization_page', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'organization_page',
- )
- organizationProfile.id = 123
- expect(menuBuilder.build()).toEqual({
- label: 'organization_page',
- icon: undefined,
- to: 'https://mydomain.com/#/main/organizations/123/dashboard',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu cmf_licence_generate', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'cmf_licence_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'cmf_licence_generate',
- icon: undefined,
- to: 'https://mydomain.com/#/licence_cmf/organization',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- //
- // expect(menuBuilder.build()).toEqual({
- // label: 'cmf_licence_generate',
- // icon: undefined,
- // to: '/cmf_licence_structure',
- // type: MENU_LINK_TYPE.INTERNAL,
- // active: false,
- // })
- })
- test('has only rights for menu parameters', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'parameters_page',
- )
- menuBuilder.organizationProfile.id = 123
- expect(menuBuilder.build()).toEqual({
- label: 'parameters',
- icon: undefined,
- to: 'https://mydomain.com/#/main/edit/parameters/123',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- // expect(menuBuilder.build()).toEqual({
- // label: 'parameters',
- // icon: undefined,
- // to: '/parameters',
- // type: MENU_LINK_TYPE.INTERNAL,
- // active: false,
- // })
- })
- test('has only rights for menu place', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'place_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'places',
- icon: undefined,
- to: 'https://mydomain.com/#/places/list/',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu education', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'education_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'education',
- icon: undefined,
- to: 'https://mydomain.com/#/educations/list/',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu tag', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'tag_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'tags',
- icon: undefined,
- to: 'https://mydomain.com/#/taggs/list/',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu activities', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'activities_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'activities',
- icon: undefined,
- to: 'https://mydomain.com/#/activities/list/',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu course_duplication', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'course_duplication_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'course_duplication',
- icon: undefined,
- to: 'https://mydomain.com/#/duplicate_courses',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- test('has only rights for menu import', () => {
- ability.can = vi.fn(
- (action: string, subject: string) =>
- action === 'display' && subject === 'import_page',
- )
- expect(menuBuilder.build()).toEqual({
- label: 'import',
- icon: undefined,
- to: 'https://mydomain.com/#/import/all',
- type: MENU_LINK_TYPE.V1,
- active: false,
- })
- })
- })
|