import { newSpecPage } from "@stencil/core/testing";
import { BpSdkBusinessClassificationSelectorList } from "../bp-sdk-business-classification-selector-list/bp-sdk-business-classification-selector-list";
import { BpSdkBusinessClassificationSelectorListContainer } from "./bp-sdk-business-classification-selector-list-container";
const setupPage = async () => {
    return await newSpecPage({
        html: '<bp-sdk-business-classification-selector-list-container></bp-sdk-business-classification-selector-list-container>',
        components: [BpSdkBusinessClassificationSelectorListContainer, BpSdkBusinessClassificationSelectorList],
    });
};
const setupInstance = (page) => {
    const instance = page.rootInstance;
    instance.groupedChoicesConfig = { maxResults: 10 };
    return instance;
};
describe('bp-sdk-business-classification-selector-list-container', () => {
    it('renders', async () => {
        const page = await setupPage();
        setupInstance(page);
        await page.waitForChanges();
        const element = page.root.querySelector('bp-sdk-business-classification-selector-list');
        expect(element).toBeTruthy();
        expect(page.root.querySelector('bp-sdk-external-business-classification-selector-list-container')).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-container')).toBeTruthy();
        whenDefinedMock.mockRestore();
    });
    describe('connectedCallback', () => {
        it('makes expected call if root available', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.handleSubscriptions = jest.fn();
            jest.spyOn(instance.el, 'querySelector').mockImplementationOnce(() => ({
                componentOnReady: () => Promise.resolve(true),
            }));
            instance.connectedCallback();
            expect(instance.handleSubscriptions).toBeCalledTimes(1);
        });
    });
    describe('disconnectedCallback', () => {
        it('makes expected calls', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.storeUnsubscribe = jest.fn();
            instance.disconnectedCallback();
            expect(instance.storeUnsubscribe).toBeCalledTimes(1);
        });
    });
});
