import { newSpecPage } from "@stencil/core/testing";
import { BpSdkQuestionGroupContainer } from "./bp-sdk-question-group-container";
const setupPage = async () => {
    return await newSpecPage({
        html: '<bp-sdk-question-group-container></bp-sdk-question-group-container>',
        components: [BpSdkQuestionGroupContainer],
    });
};
const setupInstance = (page) => {
    const instance = page.rootInstance;
    return instance;
};
describe('bp-sdk-question-group-container', () => {
    it('renders', async () => {
        const page = await setupPage();
        const instance = setupInstance(page);
        await page.waitForChanges();
        expect(instance.classes).toEqual('bp-sdk-question-group-content');
        const element = page.root.querySelector('bp-sdk-question-group');
        expect(element).toBeTruthy();
        expect(page.root.querySelector('bp-sdk-external-question-group-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-question-group-container')).toBeTruthy();
        whenDefinedMock.mockRestore();
    });
    it('updates the classes on type change', async () => {
        const page = await setupPage();
        const instance = setupInstance(page);
        const spy = jest.spyOn(instance, 'updateClasses');
        instance.questionGroup = {
            answers: [],
            group_type: 'split_horizontal',
            label: '',
            nestedGroupWithAnswers: {},
            parentQuestionAnswer: {},
            groupId: '123',
            poolId: null,
        };
        expect(instance.classes).toEqual('bp-sdk-question-group-content bp-sdk-row bp-sdk-space-between');
        instance.questionGroup = Object.assign(Object.assign({}, instance.questionGroup), { group_type: 'split_vertical' });
        expect(instance.classes).toEqual('bp-sdk-question-group-content bp-sdk-column');
        instance.questionGroup = Object.assign(Object.assign({}, instance.questionGroup), { group_type: undefined });
        expect(instance.classes).toEqual('bp-sdk-question-group-content');
        expect(spy).toHaveBeenCalledTimes(3);
    });
});
