websiteListMenuBuilder.test.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import { describe, test, it, expect } from 'vitest'
  2. import type { RuntimeConfig } from '@nuxt/schema'
  3. import type { AnyAbility } from '@casl/ability/dist/types'
  4. import type { AccessProfile, organizationState } from '~/types/interfaces'
  5. import WebsiteListMenuBuilder from '~/services/layout/menuBuilder/websiteListMenuBuilder'
  6. import type { 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(
  20. runtimeConfig,
  21. ability,
  22. organizationProfile,
  23. accessProfile,
  24. )
  25. })
  26. describe('getMenuName', () => {
  27. test('validate name', () => {
  28. expect(menuBuilder.getMenuName()).toEqual('WebsiteList')
  29. })
  30. })
  31. describe('build', () => {
  32. test('without website and parents', () => {
  33. organizationProfile.website = null
  34. organizationProfile.parents = []
  35. expect(menuBuilder.build()).toEqual(null)
  36. })
  37. test('with website but no parents', () => {
  38. organizationProfile.name = 'MyOrganization'
  39. organizationProfile.website = 'https://some-website.com'
  40. organizationProfile.parents = []
  41. const result = menuBuilder.build() as MenuGroup
  42. expect(result.children).toEqual([
  43. {
  44. label: 'MyOrganization',
  45. icon: undefined,
  46. to: 'https://some-website.com',
  47. type: MENU_LINK_TYPE.EXTERNAL,
  48. active: false,
  49. },
  50. ])
  51. })
  52. test('with parents but no website', () => {
  53. organizationProfile.name = 'MyOrganization'
  54. organizationProfile.website = ''
  55. organizationProfile.parents = [
  56. { id: 1, name: 'parent1', website: 'https://parent1.net' },
  57. { id: 2, name: 'parent2', website: 'https://parent2.net' },
  58. { id: 3, name: 'parent3', website: 'https://parent3.net' },
  59. ]
  60. const result = menuBuilder.build() as MenuGroup
  61. expect(result.children).toEqual([
  62. {
  63. label: 'parent1',
  64. icon: undefined,
  65. to: 'https://parent1.net',
  66. type: MENU_LINK_TYPE.EXTERNAL,
  67. active: false,
  68. },
  69. {
  70. label: 'parent2',
  71. icon: undefined,
  72. to: 'https://parent2.net',
  73. type: MENU_LINK_TYPE.EXTERNAL,
  74. active: false,
  75. },
  76. {
  77. label: 'parent3',
  78. icon: undefined,
  79. to: 'https://parent3.net',
  80. type: MENU_LINK_TYPE.EXTERNAL,
  81. active: false,
  82. },
  83. ])
  84. })
  85. test('with parents and website, opentalent is excluded from parents', () => {
  86. organizationProfile.name = 'MyOrganization'
  87. organizationProfile.website = 'https://some-website.com'
  88. organizationProfile.parents = [
  89. { id: 1, name: 'parent1', website: 'https://parent1.net' },
  90. { id: 2, name: 'parent2', website: 'https://parent2.net' },
  91. { id: 3, name: 'parent3', website: 'https://parent3.net' },
  92. ]
  93. runtimeConfig.OPENTALENT_MANAGER_ID = 3
  94. const result = menuBuilder.build() as MenuGroup
  95. expect(result.children).toEqual([
  96. {
  97. label: 'MyOrganization',
  98. icon: undefined,
  99. to: 'https://some-website.com',
  100. type: MENU_LINK_TYPE.EXTERNAL,
  101. active: false,
  102. },
  103. {
  104. label: 'parent1',
  105. icon: undefined,
  106. to: 'https://parent1.net',
  107. type: MENU_LINK_TYPE.EXTERNAL,
  108. active: false,
  109. },
  110. {
  111. label: 'parent2',
  112. icon: undefined,
  113. to: 'https://parent2.net',
  114. type: MENU_LINK_TYPE.EXTERNAL,
  115. active: false,
  116. },
  117. ])
  118. })
  119. })