
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 EquipmentMenuBuilder from "~/services/layout/menuBuilder/equipmentMenuBuilder";
import {MenuGroup, MenuItem} 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: EquipmentMenuBuilder

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 EquipmentMenuBuilder(runtimeConfig, ability, organizationProfile, accessProfile)
})


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

describe('build', () => {
    test('has all items', () => {
        ability.can = vi.fn(() => true)

        // Should return a MenuItem
        const result = menuBuilder.build() as MenuItem

        expect(result).toEqual({
            label: 'equipment', icon: {name: 'fas fa-cube'}, to: 'https://mydomain.com/equipment/list/', type: MENU_LINK_TYPE.V1, active: false
        })
    })

    test('has no items', () => {
        ability.can = vi.fn(() => false)
        expect(menuBuilder.build()).toEqual(null)
    })
})
