import { newSpecPage } from "@stencil/core/testing";
import { BpSdkCoverageGroup } from "./bp-sdk-coverage-group";
import { mockAnswer } from "../../mocks/answer";
const setupPage = async () => {
    return await newSpecPage({
        html: '<bp-sdk-coverage-group></bp-sdk-coverage-group>',
        components: [BpSdkCoverageGroup],
    });
};
const setupInstance = (page) => {
    const instance = page.rootInstance;
    return instance;
};
const mockGroup = () => ({
    answers: [mockAnswer],
    groupId: '123',
    group_type: 'accordion',
    label: '',
    nestedGroupsWithAnswers: new Map(),
    order: 0,
    parentQuestionAnswer: Object.assign(Object.assign({}, mockAnswer), { value: 'Parent', question: Object.assign(Object.assign({}, mockAnswer.question), { text: 'Parent Text' }) }),
    poolId: '123',
});
describe('bp-sdk-coverage-group', () => {
    it('renders', async () => {
        const page = await setupPage();
        await page.waitForChanges();
        const element = page.root.querySelector('div');
        expect(element).toBeTruthy();
        expect(page.root.querySelector('bp-sdk-external-coverage-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-coverage-group')).toBeTruthy();
        whenDefinedMock.mockRestore();
    });
    it('renders nested question group if defined', async () => {
        const page = await setupPage();
        const instance = setupInstance(page);
        instance.questionGroup = Object.assign(Object.assign({}, mockGroup()), { nestedGroupsWithAnswers: { get: () => true, answers: [mockAnswer], group_type: 'not-recognized' } });
        await page.waitForChanges();
        const element = page.root.querySelector('bp-sdk-question-group-container');
        expect(element).toBeTruthy();
    });
});
