websiteListMenuBuilder.test.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { describe, test, it, expect } from 'vitest'
  2. import {RuntimeConfig} from "@nuxt/schema";
  3. import {AnyAbility} from "@casl/ability/dist/types";
  4. import {AccessProfile, organizationState} from "~/types/interfaces";
  5. import WebsiteListMenuBuilder from "~/services/layout/menuBuilder/websiteListMenuBuilder";
  6. import {MenuGroup} from "~/types/layout";
  7. import {MENU_LINK_TYPE} from "~/types/enum/layout";
  8. let runtimeConfig: RuntimeConfig
  9. let ability: AnyAbility
  10. let organizationProfile: organizationState
  11. let accessProfile: AccessProfile
  12. let menuBuilder: WebsiteListMenuBuilder
  13. beforeEach(()=> {
  14. runtimeConfig = vi.fn() as any as RuntimeConfig
  15. ability = vi.fn() as any as AnyAbility
  16. organizationProfile = {} as any as organizationState
  17. accessProfile = vi.fn() as any as AccessProfile
  18. runtimeConfig.baseUrlAdminLegacy = 'https://mydomain.com/'
  19. menuBuilder = new WebsiteListMenuBuilder(runtimeConfig, ability, organizationProfile, accessProfile)
  20. })
  21. describe('getMenuName', () => {
  22. test('validate name', () => {
  23. expect(menuBuilder.getMenuName()).toEqual("WebsiteList")
  24. })
  25. })
  26. describe('build', () => {
  27. test('without website and parents', () => {
  28. organizationProfile.website = null
  29. organizationProfile.parents = []
  30. expect(menuBuilder.build()).toEqual(null)
  31. })
  32. test('with website but no parents', () => {
  33. organizationProfile.name = 'MyOrganization'
  34. organizationProfile.website = 'https://some-website.com'
  35. organizationProfile.parents = []
  36. const result = menuBuilder.build() as MenuGroup
  37. expect(result.children).toEqual([
  38. {
  39. label: 'MyOrganization',
  40. icon: undefined,
  41. to: 'https://some-website.com/typo3',
  42. type: MENU_LINK_TYPE.EXTERNAL,
  43. active: false
  44. }
  45. ])
  46. })
  47. test('with parents but no website', () => {
  48. organizationProfile.name = 'MyOrganization'
  49. organizationProfile.website = ''
  50. organizationProfile.parents = [
  51. {id: 1, name: 'parent1', website: 'https://parent1.net'},
  52. {id: 2, name: 'parent2', website: 'https://parent2.net'},
  53. {id: 3, name: 'parent3', website: 'https://parent3.net'},
  54. ]
  55. const result = menuBuilder.build() as MenuGroup
  56. expect(result.children).toEqual([
  57. { label: 'parent1', icon: undefined, to: 'https://parent1.net', type: MENU_LINK_TYPE.EXTERNAL, active: false },
  58. { label: 'parent2', icon: undefined, to: 'https://parent2.net', type: MENU_LINK_TYPE.EXTERNAL, active: false },
  59. { label: 'parent3', icon: undefined, to: 'https://parent3.net', type: MENU_LINK_TYPE.EXTERNAL, active: false },
  60. ])
  61. })
  62. test('with parents and website, opentalent is excluded from parents', () => {
  63. organizationProfile.name = 'MyOrganization'
  64. organizationProfile.website = 'https://some-website.com'
  65. organizationProfile.parents = [
  66. {id: 1, name: 'parent1', website: 'https://parent1.net'},
  67. {id: 2, name: 'parent2', website: 'https://parent2.net'},
  68. {id: 3, name: 'parent3', website: 'https://parent3.net'},
  69. ]
  70. runtimeConfig.OPENTALENT_MANAGER_ID = 3
  71. const result = menuBuilder.build() as MenuGroup
  72. expect(result.children).toEqual([
  73. { label: 'MyOrganization', icon: undefined, to: 'https://some-website.com/typo3', type: MENU_LINK_TYPE.EXTERNAL, active: false },
  74. { label: 'parent1', icon: undefined, to: 'https://parent1.net', type: MENU_LINK_TYPE.EXTERNAL, active: false },
  75. { label: 'parent2', icon: undefined, to: 'https://parent2.net', type: MENU_LINK_TYPE.EXTERNAL, active: false },
  76. ])
  77. })
  78. })