websiteAdminMenuBuilder.test.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 WebsiteAdminMenuBuilder from '~/services/layout/menuBuilder/websiteAdminMenuBuilder'
  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: WebsiteAdminMenuBuilder
  13. beforeEach(() => {
  14. runtimeConfig = vi.fn() as any as RuntimeConfig
  15. ability = vi.fn() as any as AnyAbility
  16. organizationProfile = vi.fn() as any as organizationState
  17. accessProfile = vi.fn() as any as AccessProfile
  18. runtimeConfig.baseUrlAdminLegacy = 'https://mydomain.com/'
  19. menuBuilder = new WebsiteAdminMenuBuilder(
  20. runtimeConfig,
  21. ability,
  22. organizationProfile,
  23. accessProfile,
  24. )
  25. })
  26. describe('getMenuName', () => {
  27. test('validate name', () => {
  28. expect(menuBuilder.getMenuName()).toEqual('WebsiteAdmin')
  29. })
  30. })
  31. describe('build', () => {
  32. test('without website', () => {
  33. organizationProfile.website = null
  34. expect(menuBuilder.build()).toEqual(null)
  35. })
  36. test('without admin access', () => {
  37. organizationProfile.website = 'https://some-website.com'
  38. accessProfile.isAdminAccess = false
  39. expect(menuBuilder.build()).toEqual(null)
  40. })
  41. test('with website and admin access', () => {
  42. organizationProfile.website = 'https://some-website.com'
  43. accessProfile.isAdminAccess = true
  44. expect(menuBuilder.build()).toEqual({
  45. label: 'advanced_modification',
  46. icon: { name: 'fas fa-globe-americas' },
  47. to: 'https://some-website.com/typo3',
  48. type: MENU_LINK_TYPE.EXTERNAL,
  49. active: false,
  50. })
  51. })
  52. })