| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- import { describe, test, it, expect } from 'vitest'
- import {RuntimeConfig} from "@nuxt/schema";
- import {AnyAbility} from "@casl/ability/dist/types";
- import {AccessProfile, organizationState} from "~/types/interfaces";
- import MyAccessesMenuBuilder from "~/services/layout/menuBuilder/myAccessesMenuBuilder";
- import {MenuGroup, MenuItem} 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: MyAccessesMenuBuilder
- 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
- runtimeConfig.baseUrlAdminLegacy = 'https://mydomain.com/'
- menuBuilder = new MyAccessesMenuBuilder(runtimeConfig, ability, organizationProfile, accessProfile)
- })
- describe('getMenuName', () => {
- test('validate name', () => {
- expect(menuBuilder.getMenuName()).toEqual("MyAccesses")
- })
- })
- describe('build', () => {
- test('default : has no items, even with rights', () => {
- ability.can = vi.fn(() => true)
- expect(menuBuilder.build()).toEqual(null)
- })
- test('with enabled multi accesses', () => {
- accessProfile.multiAccesses = [
- { id: 1, name: 'Bob' },
- { id: 2, name: 'Séraphin' },
- { id: 3, name: 'Lilou' },
- ]
- const result = menuBuilder.build() as MenuGroup
- expect(result.label).toEqual('multiAccesses')
- expect(result.icon).toEqual({name: 'fas fa-building'})
- expect(result.children).toEqual([
- { label: 'Bob', icon: undefined, to: 'https://mydomain.com/#/switch/1', type: MENU_LINK_TYPE.V1, active: false },
- { label: 'Séraphin', icon: undefined, to: 'https://mydomain.com/#/switch/2', type: MENU_LINK_TYPE.V1, active: false },
- { label: 'Lilou', icon: undefined, to: 'https://mydomain.com/#/switch/3', type: MENU_LINK_TYPE.V1, active: false }
- ])
- })
- })
|