| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- import { describe, test, it, expect } from 'vitest'
- import type { RuntimeConfig } from '@nuxt/schema'
- import type { AnyAbility } from '@casl/ability/dist/types'
- import type { AccessProfile, organizationState } from '~/types/interfaces'
- import WebsiteAdminMenuBuilder from '~/services/layout/menuBuilder/websiteAdminMenuBuilder'
- 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: WebsiteAdminMenuBuilder
- 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 WebsiteAdminMenuBuilder(
- runtimeConfig,
- ability,
- organizationProfile,
- accessProfile,
- )
- })
- describe('getMenuName', () => {
- test('validate name', () => {
- expect(menuBuilder.getMenuName()).toEqual('WebsiteAdmin')
- })
- })
- describe('build', () => {
- test('without website', () => {
- organizationProfile.website = null
- expect(menuBuilder.build()).toEqual(null)
- })
- test('without admin access', () => {
- organizationProfile.website = 'https://some-website.com'
- accessProfile.isAdminAccess = false
- expect(menuBuilder.build()).toEqual(null)
- })
- test('with website and admin access', () => {
- organizationProfile.website = 'https://some-website.com'
- accessProfile.isAdminAccess = true
- expect(menuBuilder.build()).toEqual({
- label: 'advanced_modification',
- icon: { name: 'fas fa-globe-americas' },
- to: 'https://some-website.com/typo3',
- type: MENU_LINK_TYPE.EXTERNAL,
- active: false,
- })
- })
- })
|