import { newSpecPage } from "@stencil/core/testing";
import { BpSdkBusinessClassificationSelectorNaicsGroup } from "./bp-sdk-business-classification-selector-naics-group";
const setupPage = async () => {
    return await newSpecPage({
        html: '<bp-sdk-business-classification-selector-naics-group></bp-sdk-business-classification-selector-naics-group>',
        components: [BpSdkBusinessClassificationSelectorNaicsGroup],
    });
};
const setupInstance = (page) => {
    const instance = page.rootInstance;
    return instance;
};
describe('bp-sdk-business-classification-selector-naics-group', () => {
    it('renders', async () => {
        const page = await setupPage();
        await page.waitForChanges();
        const element = page.root.querySelector('.bp-sdk-business-classification-selector-naics-group__container');
        expect(element).toBeTruthy();
        expect(page.root.querySelector('bp-sdk-external-business-classification-selector-naics-group')).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-naics-group')).toBeTruthy();
        whenDefinedMock.mockRestore();
    });
    describe('naics group header', () => {
        it('renders header', async () => {
            const page = await setupPage();
            setupInstance(page);
            await page.waitForChanges();
            const element = page.root.querySelector('bp-sdk-business-classification-selector-naics-group-header');
            expect(element).toBeTruthy();
        });
        it('passes naicsCode to header when showNaicsCode is true', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.showNaicsCode = true;
            instance.naicsCode = 'testCode';
            await page.waitForChanges();
            const element = page.root.querySelector('bp-sdk-business-classification-selector-naics-group-header');
            expect(element.getAttribute('naicsCode')).toEqual(instance.naicsCode);
        });
        it('passes undefined to header when showNaicsCode is false', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.showNaicsCode = false;
            instance.naicsCode = 'testCode';
            await page.waitForChanges();
            const element = page.root.querySelector('bp-sdk-business-classification-selector-naics-group-header');
            expect(element.getAttribute('naicsCode')).toBeNull();
        });
        it('passes naics explanation to header', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.naicsExplanation = 'test explanation';
            await page.waitForChanges();
            const element = page.root.querySelector('bp-sdk-business-classification-selector-naics-group-header');
            expect(element.getAttribute('naicsExplanation')).toEqual(instance.naicsExplanation);
        });
        it('passes naics description to header', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.naicsDescription = 'test description';
            await page.waitForChanges();
            const element = page.root.querySelector('bp-sdk-business-classification-selector-naics-group-header');
            expect(element.getAttribute('naicsDescription')).toEqual(instance.naicsDescription);
        });
    });
    describe('choices', () => {
        it('renders a list-item-container for each choice', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.choices = [
                {
                    alias: 'testAlias',
                    id: 'testId',
                    confidence: 100,
                    showExplanation: false,
                },
                {
                    alias: 'testAlias2',
                    id: 'testId2',
                    confidence: 100,
                    showExplanation: false,
                },
            ];
            await page.waitForChanges();
            const elements = page.root.querySelectorAll('bp-sdk-business-classification-selector-list-item-container');
            expect(elements).toHaveLength(2);
        });
    });
});
