import { newSpecPage } from "@stencil/core/testing";
import { BpSdkBusinessClassificationSelectorList } from "./bp-sdk-business-classification-selector-list";
const setupPage = async () => {
    return await newSpecPage({
        html: '<bp-sdk-business-classification-selector-list></bp-sdk-business-classification-selector-list>',
        components: [BpSdkBusinessClassificationSelectorList],
    });
};
const setupInstance = (page) => {
    const instance = page.rootInstance;
    instance.groupedChoicesConfig = { maxResults: 7 };
    return instance;
};
describe('bp-sdk-business-classification-selector-list', () => {
    it('renders', async () => {
        const page = await setupPage();
        setupInstance(page);
        await page.waitForChanges();
        const element = page.root.querySelector('div');
        expect(element).toBeTruthy();
        expect(page.root.querySelector('bp-sdk-external-business-classification-selector-list')).toBeFalsy();
    });
    it('renders choices', async () => {
        const page = await setupPage();
        const instance = setupInstance(page);
        instance.choices = [
            {
                id: 'some choice',
            },
        ];
        await page.waitForChanges();
        const elements = page.root.querySelectorAll('bp-sdk-business-classification-selector-naics-group');
        expect(elements.length).toEqual(1);
        expect(page.root.querySelector('bp-sdk-external-business-classification-selector-list')).toBeFalsy();
    });
    it('renders external component if defined', async () => {
        const whenDefinedMock = jest.spyOn(customElements, 'whenDefined').mockResolvedValueOnce({});
        const page = await setupPage();
        await page.waitForChanges();
        expect(page.root.querySelector('bp-sdk-external-business-classification-selector-list')).toBeTruthy();
        whenDefinedMock.mockRestore();
    });
    describe('calculateGroupedChoices', () => {
        it('sets instance.groupedChoices', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            const choices = [
                { alias: 'alias1', score: 123 },
                { alias: 'alias2', score: 321 },
            ];
            instance.calculateGroupedChoices(choices);
            await page.waitForChanges();
            expect(instance.groupedChoices).toHaveLength(2);
        });
        it('sets instance.highestChoiceScore', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            const choices = [
                { alias: 'alias1', score: 123 },
                { alias: 'alias2', score: 321 },
            ];
            instance.calculateGroupedChoices(choices);
            await page.waitForChanges();
            expect(instance.highestChoiceScore).toEqual(321);
        });
    });
});
