|
|
@@ -0,0 +1,85 @@
|
|
|
+import { describe, test, expect, vi, beforeEach } from 'vitest'
|
|
|
+import type { RuntimeConfig } from '@nuxt/schema'
|
|
|
+import type { AnyAbility } from '@casl/ability'
|
|
|
+import type { Router } from 'vue-router'
|
|
|
+import type { AccessProfile, organizationState } from '~/types/interfaces'
|
|
|
+import BasicomptaMenuBuilder from '~/services/layout/menuBuilder/basicomptaMenuBuilder'
|
|
|
+import { MENU_LINK_TYPE } from '~/types/enum/layout'
|
|
|
+
|
|
|
+let runtimeConfig: RuntimeConfig
|
|
|
+let ability: AnyAbility
|
|
|
+let organizationProfile: organizationState
|
|
|
+let accessProfile: AccessProfile
|
|
|
+let menuBuilder: BasicomptaMenuBuilder
|
|
|
+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
|
|
|
+
|
|
|
+ menuBuilder = new BasicomptaMenuBuilder(
|
|
|
+ runtimeConfig,
|
|
|
+ ability,
|
|
|
+ organizationProfile,
|
|
|
+ accessProfile,
|
|
|
+ router,
|
|
|
+ )
|
|
|
+})
|
|
|
+
|
|
|
+describe('getMenuName', () => {
|
|
|
+ test('validate name', () => {
|
|
|
+ expect(menuBuilder.getMenuName()).toEqual('Basicompta')
|
|
|
+ })
|
|
|
+})
|
|
|
+
|
|
|
+describe('build', () => {
|
|
|
+ test('without admin, administratif, or financial manager access', () => {
|
|
|
+ accessProfile.isAdminAccess = false
|
|
|
+ accessProfile.isAdministratifManager = false
|
|
|
+ accessProfile.isFinancialManager = false
|
|
|
+ expect(menuBuilder.build()).toEqual(null)
|
|
|
+ })
|
|
|
+
|
|
|
+ test('with admin access', () => {
|
|
|
+ accessProfile.isAdminAccess = true
|
|
|
+ expect(menuBuilder.build()).toEqual({
|
|
|
+ label: 'basicompta_admin',
|
|
|
+ icon: { name: 'fas fa-suitcase' },
|
|
|
+ to: 'https://app.basicompta.fr/',
|
|
|
+ type: MENU_LINK_TYPE.EXTERNAL,
|
|
|
+ active: false,
|
|
|
+ target: '_blank',
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ test('with administratif manager access', () => {
|
|
|
+ accessProfile.isAdminAccess = false
|
|
|
+ accessProfile.isAdministratifManager = true
|
|
|
+ expect(menuBuilder.build()).toEqual({
|
|
|
+ label: 'basicompta_admin',
|
|
|
+ icon: { name: 'fas fa-suitcase' },
|
|
|
+ to: 'https://app.basicompta.fr/',
|
|
|
+ type: MENU_LINK_TYPE.EXTERNAL,
|
|
|
+ active: false,
|
|
|
+ target: '_blank',
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ test('with financial manager access', () => {
|
|
|
+ accessProfile.isAdminAccess = false
|
|
|
+ accessProfile.isAdministratifManager = false
|
|
|
+ accessProfile.isFinancialManager = true
|
|
|
+ expect(menuBuilder.build()).toEqual({
|
|
|
+ label: 'basicompta_admin',
|
|
|
+ icon: { name: 'fas fa-suitcase' },
|
|
|
+ to: 'https://app.basicompta.fr/',
|
|
|
+ type: MENU_LINK_TYPE.EXTERNAL,
|
|
|
+ active: false,
|
|
|
+ target: '_blank',
|
|
|
+ })
|
|
|
+ })
|
|
|
+})
|