websiteAdminMenuBuilder.test.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. type: MENU_LINK_TYPE.EXTERNAL,
  53. active: false,
  54. })
  55. })
  56. })