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 DonorsMenuBuilder from "~/services/layout/menuBuilder/donorsMenuBuilder";
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: DonorsMenuBuilder

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

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

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: 'donors', icon: {name: 'fas fa-handshake'}, to: 'https://mydomain.com/donors/list/', type: MENU_LINK_TYPE.V1, active: false
        })
    })

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