import { describe, test, it, expect } from 'vitest'
import {RuntimeConfig} from "@nuxt/schema";
import {AnyAbility} from "@casl/ability/dist/types";
import {AccessProfile, organizationState} from "~/types/interfaces";
import WebsiteAdminMenuBuilder from "~/services/layout/menuBuilder/websiteAdminMenuBuilder";
import {MenuGroup} from "~/types/layout";
import {MENU_LINK_TYPE} from "~/types/enum/layout";

let runtimeConfig: RuntimeConfig
let ability: AnyAbility
let organizationProfile: organizationState
let accessProfile: AccessProfile
let menuBuilder: WebsiteAdminMenuBuilder

beforeEach(()=> {
    runtimeConfig = vi.fn() as any as RuntimeConfig
    ability = vi.fn() as any as AnyAbility
    organizationProfile = vi.fn() as any as organizationState
    accessProfile = vi.fn() as any as AccessProfile

    runtimeConfig.baseUrlAdminLegacy = 'https://mydomain.com/'

    menuBuilder = new WebsiteAdminMenuBuilder(runtimeConfig, ability, organizationProfile, accessProfile)
})

describe('getMenuName', () => {
    test('validate name', () => {
        expect(menuBuilder.getMenuName()).toEqual("WebsiteAdmin")
    })
})

describe('build', () => {
    test('without website', () => {
        organizationProfile.website = null
        expect(menuBuilder.build()).toEqual(null)
    })
    test('without admin access', () => {
        organizationProfile.website = 'https://some-website.com'
        accessProfile.isAdminAccess = false
        expect(menuBuilder.build()).toEqual(null)
    })
    test('with website and admin access', () => {
        organizationProfile.website = 'https://some-website.com'
        accessProfile.isAdminAccess = true
        expect(menuBuilder.build()).toEqual(
            {
                label: 'advanced_modification',
                icon: {name: 'fas fa-globe-americas'},
                to: 'https://some-website.com/typo3',
                type: MENU_LINK_TYPE.EXTERNAL,
                active: false
        })
    })
})

