| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- import { describe, expect, test, 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 MyFamilyMenuBuilder from '~/services/layout/menuBuilder/myFamilyMenuBuilder'
- import { GENDER } from '~/types/enum/enums'
- import { MENU_LINK_TYPE } from '~/types/enum/layout'
- import type { MenuGroup } from '~/types/layout'
- let runtimeConfig: RuntimeConfig
- let ability: AnyAbility
- let organizationProfile: organizationState
- let accessProfile: AccessProfile
- let menuBuilder: MyFamilyMenuBuilder
- 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 MyFamilyMenuBuilder(
- runtimeConfig,
- ability,
- organizationProfile,
- accessProfile,
- router,
- )
- })
- describe('getMenuName', () => {
- test('validate name', () => {
- expect(menuBuilder.getMenuName()).toEqual('MyFamily')
- })
- })
- describe('build', () => {
- test('no item by default', () => {
- ability.can = vi.fn(() => true)
- expect(menuBuilder.build()).toEqual(null)
- })
- test('with family accesses', () => {
- ability.can = vi.fn(() => true)
- organizationProfile.id = 100
- accessProfile.id = 1
- accessProfile.familyAccesses = [
- {
- id: 1,
- name: 'Bob',
- givenName: 'Dupont',
- gender: GENDER.MISTER,
- avatarId: 1,
- },
- {
- id: 2,
- name: 'Séraphin',
- givenName: 'Dupuis',
- gender: GENDER.MISTER,
- avatarId: 2,
- },
- {
- id: 3,
- name: 'Lilou',
- givenName: 'Dubois',
- gender: GENDER.MISS,
- avatarId: 3,
- },
- ]
- accessProfile.originalAccess = {
- id: 4,
- name: 'Tony',
- givenName: 'Soprano',
- gender: GENDER.MISTER,
- avatarId: 4,
- isSuperAdminAccess: false,
- organization: { id: 100, name: 'my_organization' },
- }
- const result = menuBuilder.build() as MenuGroup
- expect(result.children).toEqual([
- {
- label: 'Dupont Bob',
- icon: { avatarId: 1, avatarByDefault: '/images/default/men-1.png' },
- to: 'https://mydomain.com/#/switch_user/100/1/1',
- type: MENU_LINK_TYPE.V1,
- active: false,
- },
- {
- label: 'Dupuis Séraphin',
- icon: { avatarId: 2, avatarByDefault: '/images/default/men-1.png' },
- to: 'https://mydomain.com/#/switch_user/100/1/2',
- type: MENU_LINK_TYPE.V1,
- active: false,
- },
- {
- label: 'Dubois Lilou',
- icon: { avatarId: 3, avatarByDefault: '/images/default/women-1.png' },
- to: 'https://mydomain.com/#/switch_user/100/1/3',
- type: MENU_LINK_TYPE.V1,
- active: false,
- },
- {
- label: 'Soprano Tony',
- icon: undefined,
- to: 'https://mydomain.com/#/switch_user/100/4/exit',
- type: MENU_LINK_TYPE.V1,
- active: false,
- },
- ])
- })
- })
|