websiteAdminMenuBuilder.test.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. import { describe, test, expect, vi, beforeEach } from 'vitest'
  2. import type { RuntimeConfig } from '@nuxt/schema'
  3. import type { AnyAbility } from '@casl/ability/dist/types'
  4. import type { Router } from 'vue-router'
  5. import type { AccessProfile, organizationState } from '~/types/interfaces'
  6. import WebsiteAdminMenuBuilder from '~/services/layout/menuBuilder/websiteAdminMenuBuilder'
  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: WebsiteAdminMenuBuilder
  13. let router: Router
  14. beforeEach(() => {
  15. runtimeConfig = vi.fn() as any as RuntimeConfig
  16. ability = vi.fn() as any as AnyAbility
  17. organizationProfile = vi.fn() as any as organizationState
  18. accessProfile = vi.fn() as any as AccessProfile
  19. // @ts-ignore
  20. router = vi.fn() as Router
  21. runtimeConfig.baseUrlAdminLegacy = 'https://mydomain.com/'
  22. menuBuilder = new WebsiteAdminMenuBuilder(
  23. runtimeConfig,
  24. ability,
  25. organizationProfile,
  26. accessProfile,
  27. router,
  28. )
  29. })
  30. describe('getMenuName', () => {
  31. test('validate name', () => {
  32. expect(menuBuilder.getMenuName()).toEqual('WebsiteAdmin')
  33. })
  34. })
  35. describe('build', () => {
  36. test('without website', () => {
  37. organizationProfile.website = null
  38. expect(menuBuilder.build()).toEqual(null)
  39. })
  40. test('without admin access', () => {
  41. organizationProfile.website = 'https://some-website.com'
  42. accessProfile.isAdminAccess = false
  43. expect(menuBuilder.build()).toEqual(null)
  44. })
  45. test('with website and admin access', () => {
  46. organizationProfile.website = 'https://some-website.com'
  47. accessProfile.isAdminAccess = true
  48. expect(menuBuilder.build()).toEqual({
  49. label: 'advanced_modification',
  50. icon: { name: 'fas fa-globe-americas' },
  51. to: 'https://some-website.com/typo3',
  52. target: '_self',
  53. type: MENU_LINK_TYPE.EXTERNAL,
  54. active: false,
  55. })
  56. })
  57. })