|
@@ -0,0 +1,104 @@
|
|
|
|
|
+
|
|
|
|
|
+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 ParametersMenuBuilder from "~/services/menuBuilder/parametersMenuBuilder";
|
|
|
|
|
+import {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: ParametersMenuBuilder
|
|
|
|
|
+
|
|
|
|
|
+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 ParametersMenuBuilder(runtimeConfig, ability, organizationProfile, accessProfile)
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+describe('getMenuName', () => {
|
|
|
|
|
+ test('validate name', () => {
|
|
|
|
|
+ expect(menuBuilder.getMenuName()).toEqual("Parameters")
|
|
|
|
|
+ })
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+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('parameters')
|
|
|
|
|
+ expect(result.icon).toEqual(undefined)
|
|
|
|
|
+ // @ts-ignore
|
|
|
|
|
+ expect(result.children.length).toEqual(6)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ test('has no items', () => {
|
|
|
|
|
+ ability.can = vi.fn(() => false)
|
|
|
|
|
+ expect(menuBuilder.build()).toEqual(null)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ test('has only rights for menu general_params', () => {
|
|
|
|
|
+ ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'parameters_page')
|
|
|
|
|
+
|
|
|
|
|
+ // @ts-ignore
|
|
|
|
|
+ expect(menuBuilder.build().children[0]).toEqual(
|
|
|
|
|
+ {label: 'general_params', icon: {name: 'fas fa-cogs'}, to: 'https://mydomain.com/parameters', type: MENU_LINK_TYPE.V1, active: false}
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ test('has only rights for menu communication_params', () => {
|
|
|
|
|
+ ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'parameters_communication_page')
|
|
|
|
|
+
|
|
|
|
|
+ // @ts-ignore
|
|
|
|
|
+ expect(menuBuilder.build().children[0]).toEqual(
|
|
|
|
|
+ {label: 'communication_params', icon: {name: 'fas fa-comments'}, to: 'https://mydomain.com/parameters/communication', type: MENU_LINK_TYPE.V1, active: false}
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ test('has only rights for menu students_params', () => {
|
|
|
|
|
+ ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'parameters_student_page')
|
|
|
|
|
+
|
|
|
|
|
+ // @ts-ignore
|
|
|
|
|
+ expect(menuBuilder.build().children[0]).toEqual(
|
|
|
|
|
+ {label: 'students_params', icon: {name: 'fas fa-users'}, to: 'https://mydomain.com/parameters/student', type: MENU_LINK_TYPE.V1, active: false}
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ test('has only rights for menu education_params', () => {
|
|
|
|
|
+ ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'parameters_education_page')
|
|
|
|
|
+
|
|
|
|
|
+ // @ts-ignore
|
|
|
|
|
+ expect(menuBuilder.build().children[0]).toEqual(
|
|
|
|
|
+ {label: 'education_params', icon: {name: 'fas fa-graduation-cap'}, to: 'https://mydomain.com/parameters/education', type: MENU_LINK_TYPE.V1, active: false}
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ test('has only rights for menu bills_params', () => {
|
|
|
|
|
+ ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'parameters_bills_page')
|
|
|
|
|
+
|
|
|
|
|
+ // @ts-ignore
|
|
|
|
|
+ expect(menuBuilder.build().children[0]).toEqual(
|
|
|
|
|
+ {label: 'bills_params', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/parameters/billing', type: MENU_LINK_TYPE.V1, active: false}
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ test('has only rights for menu secure_params', () => {
|
|
|
|
|
+ ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'parameters_secure_page')
|
|
|
|
|
+
|
|
|
|
|
+ // @ts-ignore
|
|
|
|
|
+ expect(menuBuilder.build().children[0]).toEqual(
|
|
|
|
|
+ {label: 'secure_params', icon: {name: 'fas fa-lock'}, to: 'https://mydomain.com/parameters/secure', type: MENU_LINK_TYPE.V1, active: false}
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+})
|