import { newSpecPage } from "@stencil/core/testing";
import { mockAnswer } from "../../mocks/answer";
import { mockMapQuestionGroupAnswer } from "../../mocks/mockMappedQuestionGroupAnswers";
import { BpSdkStepperGroup } from "./bp-sdk-stepper-group";
const setupPage = async () => {
    return await newSpecPage({
        html: '<bp-sdk-stepper-group></bp-sdk-stepper-group>',
        components: [BpSdkStepperGroup],
    });
};
const setupInstance = (page) => {
    const instance = page.rootInstance;
    instance.questionGroup = mockMapQuestionGroupAnswer;
    return instance;
};
describe('bp-sdk-stepper-group', () => {
    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-stepper-group')).toBeFalsy();
    });
    it('should add the sdk-dynamic-input-redux-container if answer does not render as group', async () => {
        const page = await setupPage();
        const instance = setupInstance(page);
        instance.questionGroup.answers = [mockAnswer];
        instance.questionGroup.nestedGroupsWithAnswers.has = (id) => false;
        await page.waitForChanges();
        const dynamicElement = page.root.querySelector('bp-sdk-dynamic-input-redux-container');
        expect(dynamicElement).not.toBeNull();
    });
    it('recursively adds bp-sdk-stepper-group', async () => {
        const page = await setupPage();
        const instance = setupInstance(page);
        instance.questionGroup.answers = [mockAnswer];
        instance.questionGroup.nestedGroupsWithAnswers.has = (id) => true;
        const nestedAnswers = Object.assign(Object.assign({}, mockAnswer), { id: '123' });
        instance.questionGroup.nestedGroupsWithAnswers.get = (id) => ({ answers: [nestedAnswers], nestedGroupsWithAnswers: { has: (id) => false } });
        await page.waitForChanges();
        const stepperGroupElement = page.root.querySelector('bp-sdk-stepper-group');
        expect(stepperGroupElement).not.toBeNull();
    });
    it('renders external component if defined', async () => {
        jest.spyOn(customElements, 'whenDefined').mockReturnValueOnce(Promise.resolve());
        const page = await setupPage();
        await page.waitForChanges();
        expect(page.root.querySelector('bp-sdk-external-stepper-group')).toBeTruthy();
    });
});
