Browse Source

add websiteListMenuBuilder.test.ts and websiteAdminMenuBuilder.test.ts

Olivier Massot 2 years ago
parent
commit
c0682d268b

+ 1 - 1
services/menuBuilder/websiteAdminMenuBuilder.ts

@@ -14,7 +14,7 @@ export default class WebsiteAdminMenuBuilder extends AbstractMenuBuilder {
   build(): MenuItem | null {
   build(): MenuItem | null {
     if (this.organizationProfile.website && this.accessProfile.isAdminAccess) {
     if (this.organizationProfile.website && this.accessProfile.isAdminAccess) {
       const url = this.organizationProfile.website + '/typo3'
       const url = this.organizationProfile.website + '/typo3'
-      return this.createItem('advanced_modification', {name: 'fas fa-globe-americas'}, url, MENU_LINK_TYPE.V1)
+      return this.createItem('advanced_modification', {name: 'fas fa-globe-americas'}, url, MENU_LINK_TYPE.EXTERNAL)
     }
     }
 
 
     return null
     return null

+ 4 - 3
services/menuBuilder/websiteListMenuBuilder.ts

@@ -15,9 +15,10 @@ export default class WebsiteListMenuBuilder extends AbstractMenuBuilder {
   build(): MenuGroup | null {
   build(): MenuGroup | null {
     const children: MenuItems = []
     const children: MenuItems = []
 
 
-    const url = this.organizationProfile.website + '/typo3'
-    children.push(this.createItem(this.organizationProfile.name as string, undefined, url, MENU_LINK_TYPE.V1))
-
+    if (this.organizationProfile.website) {
+      const url = this.organizationProfile.website + '/typo3'
+      children.push(this.createItem(this.organizationProfile.name as string, undefined, url, MENU_LINK_TYPE.EXTERNAL))
+    }
     _.each(this.organizationProfile.parents, (parent:any) => {
     _.each(this.organizationProfile.parents, (parent:any) => {
       if(parent.id != this.runtimeConfig.OPENTALENT_MANAGER_ID){
       if(parent.id != this.runtimeConfig.OPENTALENT_MANAGER_ID){
         children.push(this.createItem(parent.name, undefined, parent.website, MENU_LINK_TYPE.EXTERNAL))
         children.push(this.createItem(parent.name, undefined, parent.website, MENU_LINK_TYPE.EXTERNAL))

+ 55 - 0
tests/units/services/menuBuilder/websiteAdminMenuBuilder.test.ts

@@ -0,0 +1,55 @@
+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 WebsiteAdminMenuBuilder from "~/services/menuBuilder/websiteAdminMenuBuilder";
+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: 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
+        })
+    })
+})
+

+ 97 - 0
tests/units/services/menuBuilder/websiteListMenuBuilder.test.ts

@@ -0,0 +1,97 @@
+
+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 WebsiteListMenuBuilder from "~/services/menuBuilder/websiteListMenuBuilder";
+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: WebsiteListMenuBuilder
+
+beforeEach(()=> {
+    runtimeConfig = vi.fn() as any as RuntimeConfig
+    ability = vi.fn() as any as AnyAbility
+    organizationProfile = {} as any as organizationState
+    accessProfile = vi.fn() as any as AccessProfile
+
+    runtimeConfig.baseUrlAdminLegacy = 'https://mydomain.com/'
+
+    menuBuilder = new WebsiteListMenuBuilder(runtimeConfig, ability, organizationProfile, accessProfile)
+})
+
+
+describe('getMenuName', () => {
+    test('validate name', () => {
+        expect(menuBuilder.getMenuName()).toEqual("WebsiteList")
+    })
+})
+
+describe('build', () => {
+    test('without website and parents', () => {
+        organizationProfile.website = null
+        organizationProfile.parents = []
+        expect(menuBuilder.build()).toEqual(null)
+    })
+
+    test('with website but no parents', () => {
+        organizationProfile.name = 'MyOrganization'
+        organizationProfile.website = 'https://some-website.com'
+        organizationProfile.parents = []
+
+        const result = menuBuilder.build() as MenuGroup
+
+        expect(result.children).toEqual([
+            {
+                label: 'MyOrganization',
+                icon: undefined,
+                to: 'https://some-website.com/typo3',
+                type: MENU_LINK_TYPE.EXTERNAL,
+                active: false
+            }
+        ])
+    })
+
+    test('with parents but no website', () => {
+        organizationProfile.name = 'MyOrganization'
+        organizationProfile.website = ''
+        organizationProfile.parents = [
+            {id: 1, name: 'parent1', website: 'https://parent1.net'},
+            {id: 2, name: 'parent2', website: 'https://parent2.net'},
+            {id: 3, name: 'parent3', website: 'https://parent3.net'},
+        ]
+
+        const result = menuBuilder.build() as MenuGroup
+
+        expect(result.children).toEqual([
+            { label: 'parent1', icon: undefined, to: 'https://parent1.net', type: MENU_LINK_TYPE.EXTERNAL, active: false },
+            { label: 'parent2', icon: undefined, to: 'https://parent2.net', type: MENU_LINK_TYPE.EXTERNAL, active: false },
+            { label: 'parent3', icon: undefined, to: 'https://parent3.net', type: MENU_LINK_TYPE.EXTERNAL, active: false },
+        ])
+    })
+
+    test('with parents and website, opentalent is excluded from parents', () => {
+        organizationProfile.name = 'MyOrganization'
+        organizationProfile.website = 'https://some-website.com'
+        organizationProfile.parents = [
+            {id: 1, name: 'parent1', website: 'https://parent1.net'},
+            {id: 2, name: 'parent2', website: 'https://parent2.net'},
+            {id: 3, name: 'parent3', website: 'https://parent3.net'},
+        ]
+
+        runtimeConfig.OPENTALENT_MANAGER_ID = 3
+
+        const result = menuBuilder.build() as MenuGroup
+
+        expect(result.children).toEqual([
+            { label: 'MyOrganization', icon: undefined, to: 'https://some-website.com/typo3', type: MENU_LINK_TYPE.EXTERNAL, active: false },
+            { label: 'parent1', icon: undefined, to: 'https://parent1.net', type: MENU_LINK_TYPE.EXTERNAL, active: false },
+            { label: 'parent2', icon: undefined, to: 'https://parent2.net', type: MENU_LINK_TYPE.EXTERNAL, active: false },
+        ])
+    })
+})
+