import { newSpecPage } from "@stencil/core/testing";
import { BpSdkVehiclePanelContent } from "./bp-sdk-vehicle-panel-content";
describe('bp-sdk-vehicle-panel-content', () => {
    const setupPage = async () => {
        return await newSpecPage({
            html: '<bp-sdk-vehicle-panel-content></bp-sdk-vehicle-panel-content>',
            components: [BpSdkVehiclePanelContent],
        });
    };
    const setupInstance = (page) => {
        const instance = page.rootInstance;
        instance.additionalAnswers = [
            {
                id: 'abc',
            },
        ];
        return instance;
    };
    it('renders', async () => {
        const page = await setupPage();
        setupInstance(page);
        await page.waitForChanges();
        const element = page.root.querySelector('bp-sdk-dynamic-input-redux-container');
        const groupElement = page.root.querySelector('bp-sdk-question-group-container');
        expect(element).toBeTruthy();
        expect(groupElement).toBeFalsy();
        expect(page.root.querySelector('bp-sdk-external-vehicle-panel-content')).toBeFalsy();
    });
    it('renders a group', async () => {
        const page = await setupPage();
        const instance = setupInstance(page);
        instance.questionGroup = {
            nestedGroupsWithAnswers: new Map([[instance.additionalAnswers[0].id, {}]]),
        };
        await page.waitForChanges();
        const groupElement = page.root.querySelector('bp-sdk-question-group-container');
        expect(groupElement).toBeTruthy();
    });
    it('renders nothing when there are no additional answers', async () => {
        const page = await setupPage();
        const instance = setupInstance(page);
        instance.additionalAnswers = [];
        await page.waitForChanges();
        const groupElement = page.root.querySelector('bp-sdk-question-group-container');
        const reduxElement = page.root.querySelector('bp-sdk-dynamic-input-redux-container');
        expect(groupElement).toBeFalsy();
        expect(reduxElement).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-vehicle-panel-content')).toBeTruthy();
        whenDefinedMock.mockRestore();
    });
    describe('shouldRenderQuestionGroup', () => {
        it('should return true when answer is in questionGroups map', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            const questionGroupMap = new Map();
            questionGroupMap.set('abc123', {});
            expect(instance.shouldRenderQuestionGroup(questionGroupMap, { id: 'abc123' })).toBeTruthy();
        });
        it('should return false when answer is in questionGroups map', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            const questionGroupMap = new Map();
            questionGroupMap.set('not_abc123', {});
            expect(instance.shouldRenderQuestionGroup(questionGroupMap, { id: 'abc123' })).toBeFalsy();
        });
    });
    describe('renderAnswer', () => {
        it('should return null when there is no answer passed', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            expect(instance.renderAnswer(undefined)).toBeNull();
        });
    });
});
