Browse Source

add configurationMenuBuilder.test.ts and cotisationsMenuBuilder.test.ts

Olivier Massot 2 years ago
parent
commit
428b730996

+ 124 - 0
tests/units/services/menuBuilder/configurationMenuBuilder.test.ts

@@ -0,0 +1,124 @@
+
+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 ConfigurationMenuBuilder from "~/services/menuBuilder/configurationMenuBuilder";
+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: ConfigurationMenuBuilder
+
+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 ConfigurationMenuBuilder(runtimeConfig, ability, organizationProfile, accessProfile)
+})
+
+
+describe('getMenuName', () => {
+    test('validate name', () => {
+        expect(menuBuilder.getMenuName()).toEqual("Configuration")
+    })
+})
+
+
+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('configuration')
+        expect(result.icon).toEqual({name: 'fas fa-cogs'})
+        // @ts-ignore
+        expect(result.children.length).toEqual(13)
+    })
+
+    test('has no items', () => {
+        ability.can = vi.fn(() => false)
+        expect(menuBuilder.build()).toEqual(null)
+    })
+
+    test('has only rights for menu organization_page', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'organization_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'organization_page', icon: undefined, to: 'https://mydomain.com/organization', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu cmf_licence_generate', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'cmf_licence_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'cmf_licence_generate', icon: undefined, to: 'https://mydomain.com/cmf_licence/organization', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu place', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'place_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'place', icon: undefined, to: 'https://mydomain.com/places/list/', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu education', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'education_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'education', icon: undefined, to: 'https://mydomain.com/educations/list/', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu tag', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'tag_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'tag', icon: undefined, to: 'https://mydomain.com/taggs/list/', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu activities', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'activities_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'activities', icon: undefined, to: 'https://mydomain.com/activities/list/', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu transition_next_year', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'transition_next_year_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'transition_next_year', icon: undefined, to: 'https://mydomain.com/transition_next_year', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu course_duplication', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'course_duplication_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'course_duplication', icon: undefined, to: 'https://mydomain.com/duplicate_courses', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu import', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'import_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'import', icon: undefined, to: 'https://mydomain.com/import/all', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+})

+ 188 - 0
tests/units/services/menuBuilder/cotisationsMenuBuilder.test.ts

@@ -0,0 +1,188 @@
+
+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 CotisationsMenuBuilder from "~/services/menuBuilder/cotisationsMenuBuilder";
+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: CotisationsMenuBuilder
+
+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 CotisationsMenuBuilder(runtimeConfig, ability, organizationProfile, accessProfile)
+})
+
+
+describe('getMenuName', () => {
+    test('validate name', () => {
+        expect(menuBuilder.getMenuName()).toEqual("Cotisation")
+    })
+})
+
+
+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('cotisations')
+        expect(result.icon).toEqual({name: 'fas fa-money-bill'})
+        // @ts-ignore
+        expect(result.children.length).toEqual(17)
+    })
+
+    test('has no items', () => {
+        ability.can = vi.fn(() => false)
+        expect(menuBuilder.build()).toEqual(null)
+    })
+
+    test('has only rights for menu rate_cotisation', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'rate_cotisation_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'rate_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/cotisation/rate', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu parameters_cotisation', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'parameters_cotisation_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'parameters_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/cotisation/parameter', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu send_cotisation', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'send_cotisation_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'send_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/cotisation/send', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu state_cotisation', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'state_cotisation_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'state_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/cotisation/state', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu pay_cotisation', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'pay_cotisation_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'pay_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/cotisation/pay', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu check_cotisation', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'check_cotisation_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'check_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/cotisation/check', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu ledger_cotisation', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'ledger_cotisation_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'ledger_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/cotisation/ledger', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu magazine_cotisation', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'magazine_cotisation_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'magazine_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/cotisation/magazine', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu ventilated_cotisation', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'ventilated_cotisation_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'ventilated_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/cotisation/ventilated', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu pay_erase_cotisation', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'pay_erase_cotisation_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'pay_erase_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/cotisation/payerase', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu resume_cotisation', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'resume_cotisation_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'resume_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/cotisation/resume', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu history_cotisation', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'history_cotisation_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'history_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/cotisation/history', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu call_cotisation', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'call_cotisation_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'call_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/cotisation/call', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu history_structure_cotisation', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'history_structure_cotisation_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'history_structure_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/cotisation/historystructure', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu insurance_cotisation', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'insurance_cotisation_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'insurance_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/cotisation/insurance', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu resume_all_cotisation', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'resume_all_cotisation_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'resume_all_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/cotisation/resumeall', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+
+    test('has only rights for menu resume_pay_cotisation', () => {
+        ability.can = vi.fn((action: string, subject: string) => action === 'display' && subject === 'resume_pay_cotisation_page')
+
+        expect(menuBuilder.build()).toEqual(
+            {label: 'resume_pay_cotisation', icon: {name: 'fas fa-euro-sign'}, to: 'https://mydomain.com/cotisation/resumepay', type: MENU_LINK_TYPE.V1, active: false}
+        )
+    })
+})