import { newSpecPage } from "@stencil/core/testing";
import { mockAnswer } from "../../mocks/answer";
import { BpSdkDynamicInputList } from "./bp-sdk-dynamic-input-list";
describe('bp-sdk-dynamic-input-list', () => {
    it('renders', async () => {
        const page = await newSpecPage({
            html: '<bp-sdk-dynamic-input-list></bp-sdk-dynamic-input-list>',
            components: [BpSdkDynamicInputList],
        });
        await page.waitForChanges();
        const element = page.root.querySelector('div');
        expect(element).toBeTruthy();
        expect(page.root.querySelector('bp-sdk-external-dynamic-input-list')).toBeFalsy();
    });
    it('renders answers', async () => {
        const page = await newSpecPage({
            html: '<bp-sdk-dynamic-input-list></bp-sdk-dynamic-input-list>',
            components: [BpSdkDynamicInputList],
        });
        const instance = page.rootInstance;
        instance.answers = [mockAnswer, mockAnswer];
        await page.waitForChanges();
        expect(page.root.querySelectorAll('bp-sdk-dynamic-input-redux-container').length).toEqual(2);
    });
    it('handles no answers', async () => {
        const page = await newSpecPage({
            html: '<bp-sdk-dynamic-input-list></bp-sdk-dynamic-input-list>',
            components: [BpSdkDynamicInputList],
        });
        const instance = page.rootInstance;
        instance.answers = undefined;
        await page.waitForChanges();
        expect(page.root.querySelectorAll('bp-sdk-dynamic-input-redux-container').length).toEqual(0);
    });
    it('renders external component if defined', async () => {
        const whenDefinedMock = jest.spyOn(customElements, 'whenDefined').mockResolvedValueOnce({});
        const page = await newSpecPage({
            html: '<bp-sdk-dynamic-input-list></bp-sdk-dynamic-input-list>',
            components: [BpSdkDynamicInputList],
        });
        await page.waitForChanges();
        expect(page.root.querySelector('bp-sdk-external-dynamic-input-list')).toBeTruthy();
        whenDefinedMock.mockRestore();
    });
});
