import { BpSdkDeleteQuestionPoolItem } from "../bp-sdk-delete-question-pool-item/bp-sdk-delete-question-pool-item";
import { newSpecPage } from "@stencil/core/testing";
import { MockAnswer } from "../../mocks/answer";
import { BpSdkAddItemContainer } from "../bp-sdk-add-item-container/bp-sdk-add-item-container";
import { BpSdkAddQuestionPoolItemContainer } from "../bp-sdk-add-question-pool-item-container/bp-sdk-add-question-pool-item-container";
import { BpSdkAutocompleteNaicsContainer } from "../bp-sdk-autocomplete-naics-container/bp-sdk-autocomplete-naics-container";
import { BpSdkBusinessClassificationSelectorContainer } from "../bp-sdk-business-classification-selector-container/bp-sdk-business-classification-selector-container";
import { BpSdkCheckboxInput } from "../bp-sdk-checkbox-input/bp-sdk-checkbox-input";
import { BpSdkDateInputContainer } from "../bp-sdk-date-input-container/bp-sdk-date-input-container";
import { BpSdkDeleteButton } from "../bp-sdk-delete-button/bp-sdk-delete-button";
import { BpSdkDeleteQuestionPoolItemContainer } from "../bp-sdk-delete-question-pool-item-container/bp-sdk-delete-question-pool-item-container";
import { BpSdkDriverInputContainer } from "../bp-sdk-driver-input-container/bp-sdk-driver-input-container";
import { BpSdkIncrementInput } from "../bp-sdk-increment-input/bp-sdk-increment-input";
import { BpSdkMaskedInputContainer } from "../bp-sdk-masked-input-container/bp-sdk-masked-input-container";
import { BpSdkMaskedInput } from "../bp-sdk-masked-input/bp-sdk-masked-input";
import { BpSdkProductListContainer } from "../bp-sdk-product-list-container/bp-sdk-product-list-container";
import { BpSdkProductList } from "../bp-sdk-product-list/bp-sdk-product-list";
import { BpSdkRadioInput } from "../bp-sdk-radio-input/bp-sdk-radio-input";
import { BpSdkSelectInputContainer } from "../bp-sdk-select-input-container/bp-sdk-select-input-container";
import { BpSdkSelectInput } from "../bp-sdk-select-input/bp-sdk-select-input";
import { BpSdkTextInput } from "../bp-sdk-text-input/bp-sdk-text-input";
import { BpSdkAutocompleteInput } from "./../bp-sdk-autocomplete-input/bp-sdk-autocomplete-input";
import { BpSdkBusinessClassificationSelector } from "./../bp-sdk-business-classification-selector/bp-sdk-business-classification-selector";
import { BpSdkDateInput } from "./../bp-sdk-date-input/bp-sdk-date-input";
import { BpSdkDialog } from "./../bp-sdk-dialog/bp-sdk-dialog";
import { BpSdkGooglePlacesAutocompleteContainer } from "./../bp-sdk-google-places-autocomplete-container/bp-sdk-google-places-autocomplete-container";
import { BpSdkGooglePlacesAutocomplete } from "./../bp-sdk-google-places-autocomplete/bp-sdk-google-places-autocomplete";
import { BpSdkLabel } from "./../bp-sdk-label/bp-sdk-label";
import { BpSdkRadioDialog } from "./../bp-sdk-radio-dialog/bp-sdk-radio-dialog";
import { BpSdkTextInputContainer } from "./../bp-sdk-text-input-container/bp-sdk-text-input-container";
import { BpSdkDynamicInput } from "./bp-sdk-dynamic-input";
jest.mock('inputmask');
const setupPage = async (additionalComponents = []) => {
    return await newSpecPage({
        html: '<bp-sdk-dynamic-input></bp-sdk-dynamic-input>',
        components: [BpSdkDynamicInput, ...additionalComponents],
    });
};
function setupInstance(instance) {
    const answer = new MockAnswer();
    instance.answerId = answer.id;
    instance.applicationFormId = answer.application_form_id;
    instance.choiceId = answer.choice_id;
    instance.choiceIds = answer.choice_ids;
    instance.choices = answer.question.choices;
    instance.code = answer.question.code;
    instance.displayType = answer.display_type;
    instance.errorText = answer.question.error_text;
    instance.errors = ['required'];
    instance.helpText = answer.question.help_text;
    instance.isAutocomplete = true;
    instance.isCompleted = true;
    instance.isCoverageType = true;
    instance.isLabelledField = true;
    instance.isMultiple = true;
    instance.isRequired = true;
    instance.isSensitive = true;
    instance.isTrackable = true;
    instance.label = answer.question.text;
    instance.labelledBy = 'groupId';
    instance.labelId = 'some id';
    instance.fieldType = 'text';
    instance.maxDate = answer.question.max_date;
    instance.maxValue = answer.question.max_value;
    instance.minDate = answer.question.min_date;
    instance.minValue = answer.question.min_value;
    instance.order = answer.question.order;
    instance.pattern = answer.question.pattern;
    instance.placeholder = answer.question.placeholder;
    instance.questionId = answer.question.id;
    instance.questionGroupId = answer.question.question_group_id;
    instance.questionSetId = answer.question.question_set_id;
    instance.referenceType = instance.referenceType;
    instance.shouldShowInput = true;
    instance.text = answer.question.text;
    instance.useSelectAlias = true;
}
describe('bp-sdk-dynamic-input', () => {
    it('renders', async () => {
        const page = await setupPage();
        await page.waitForChanges();
        expect(page.root.querySelector('div')).toBeTruthy();
        expect(page.root.querySelector('bp-sdk-external-dynamic-input')).toBeFalsy();
    });
    it('hides', async () => {
        const page = await setupPage();
        const instance = page.rootInstance;
        instance.shouldShowInput = false;
        await page.waitForChanges();
        expect(page.root.querySelector('div')).toBeFalsy();
        expect(page.root.querySelector('bp-sdk-external-dynamic-input')).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-dynamic-input')).toBeTruthy();
        whenDefinedMock.mockRestore();
    });
    describe('presentational decisions', () => {
        it('label', async () => {
            const page = await setupPage([BpSdkLabel]);
            const instance = page.rootInstance;
            instance.text = 'bob';
            instance.fieldType = 'label';
            await page.waitForChanges();
            expect(page.root.querySelector('bp-sdk-label')).toBeTruthy();
            expect(page.root.querySelector('bp-sdk-label').label).toEqual(instance.text);
            expect(page.root.querySelector('bp-sdk-label').helpText).toEqual(instance.helpText);
        });
        describe('labelled', () => {
            it('missing', async () => {
                const page = await setupPage([BpSdkLabel]);
                const instance = page.rootInstance;
                instance.isLabelledField = true;
                instance.inputComponentType = 'missing type';
                instance.code = 'some code';
                jest.spyOn(instance.componentMissing, 'emit').mockImplementation((() => { }));
                await page.waitForChanges();
                expect(instance.componentMissing.emit).toHaveBeenCalledWith(`Missing question type: ${instance.fieldType} - ${instance.code}`);
            });
            describe('text', () => {
                it('google-autocomplete', async () => {
                    const page = await setupPage([BpSdkGooglePlacesAutocompleteContainer, BpSdkGooglePlacesAutocomplete]);
                    const instance = page.rootInstance;
                    instance.isLabelledField = true;
                    instance.inputComponentType = 'text';
                    instance.referenceType = 'street_1';
                    setupInstance(instance);
                    await page.waitForChanges();
                    const input = page.root.querySelector('bp-sdk-google-places-autocomplete');
                    const container = page.root.querySelector('bp-sdk-google-places-autocomplete-container');
                    expect(input).toBeTruthy();
                    expect(input.answerId).toEqual(instance.answerId);
                    expect(input.code).toEqual(instance.code);
                    expect(input.errors).toEqual(instance.errors);
                    expect(input.errorText).toEqual(instance.errorText);
                    expect(input.fieldType).toEqual(instance.fieldType);
                    expect(input.helpText).toEqual(instance.helpText);
                    expect(input.filter).toEqual(instance.value);
                    expect(input.label).toEqual(instance.label);
                    expect(input.labelId).toEqual(instance.labelId);
                    expect(input.labelledBy).toEqual(instance.labelledBy);
                    expect(input.max).toEqual(instance.maxValue);
                    expect(input.min).toEqual(instance.minValue);
                    expect(input.placeholder).toEqual(instance.placeholder);
                    expect(input.pristine).toEqual(instance.pristine);
                    expect(input.questionId).toEqual(instance.questionId);
                    expect(input.required).toEqual(instance.isRequired);
                    expect(input.touched).toEqual(instance.touched);
                    expect(container.referenceType).toEqual(instance.referenceType);
                });
                it('increment', async () => {
                    const page = await setupPage([BpSdkIncrementInput, BpSdkTextInput, BpSdkTextInputContainer]);
                    const instance = page.rootInstance;
                    instance.isLabelledField = true;
                    instance.inputComponentType = 'text';
                    instance.referenceType = 'increment';
                    setupInstance(instance);
                    await page.waitForChanges();
                    expect(page.root.querySelector('bp-sdk-increment-input')).toBeTruthy();
                    const input = page.root.querySelector('bp-sdk-increment-input');
                    expect(input.answerId).toEqual(instance.answerId);
                    expect(input.code).toEqual(instance.code);
                    expect(input.errors).toEqual(instance.errors);
                    expect(input.errorText).toEqual(instance.errorText);
                    expect(input.fieldType).toEqual(instance.fieldType);
                    expect(input.helpText).toEqual(instance.helpText);
                    expect(input.isCompleted).toEqual(instance.isCompleted);
                    expect(input.label).toEqual(instance.label);
                    expect(input.labelId).toEqual(instance.labelId);
                    expect(input.labelledBy).toEqual(instance.labelledBy);
                    expect(input.max).toEqual(instance.maxValue);
                    expect(input.min).toEqual(instance.minValue);
                    expect(input.pattern).toEqual(instance.pattern);
                    expect(input.placeholder).toEqual(instance.placeholder);
                    expect(input.pristine).toEqual(instance.pristine);
                    expect(input.questionId).toEqual(instance.questionId);
                    expect(input.required).toEqual(instance.isRequired);
                    expect(input.text).toEqual(instance.value);
                    expect(input.touched).toEqual(instance.touched);
                });
                it('default', async () => {
                    const page = await setupPage([BpSdkTextInput, BpSdkTextInputContainer]);
                    const instance = page.rootInstance;
                    instance.isLabelledField = true;
                    instance.inputComponentType = 'text';
                    setupInstance(instance);
                    await page.waitForChanges();
                    expect(page.root.querySelector('bp-sdk-text-input')).toBeTruthy();
                    const input = page.root.querySelector('bp-sdk-text-input');
                    expect(input.answerId).toEqual(instance.answerId);
                    expect(input.code).toEqual(instance.code);
                    expect(input.errors).toEqual(instance.errors);
                    expect(input.errorText).toEqual(instance.errorText);
                    expect(input.fieldType).toEqual(instance.fieldType);
                    expect(input.helpText).toEqual(instance.helpText);
                    expect(input.isCompleted).toEqual(instance.isCompleted);
                    expect(input.label).toEqual(instance.label);
                    expect(input.labelId).toEqual(instance.labelId);
                    expect(input.labelledBy).toEqual(instance.labelledBy);
                    expect(input.max).toEqual(instance.maxValue);
                    expect(input.min).toEqual(instance.minValue);
                    expect(input.pattern).toEqual(instance.pattern);
                    expect(input.placeholder).toEqual(instance.placeholder);
                    expect(input.pristine).toEqual(instance.pristine);
                    expect(input.questionId).toEqual(instance.questionId);
                    expect(input.required).toEqual(instance.isRequired);
                    expect(input.text).toEqual(instance.value);
                    expect(input.touched).toEqual(instance.touched);
                });
            });
            it("driver's license", async () => {
                const page = await setupPage([BpSdkTextInput, BpSdkTextInputContainer, BpSdkDriverInputContainer]);
                const instance = page.rootInstance;
                instance.isLabelledField = true;
                instance.inputComponentType = 'drivers_license';
                setupInstance(instance);
                await page.waitForChanges();
                expect(page.root.querySelector('bp-sdk-text-input')).toBeTruthy();
                const input = page.root.querySelector('bp-sdk-text-input');
                expect(input.answerId).toEqual(instance.answerId);
                expect(input.code).toEqual(instance.code);
                expect(input.errors).toEqual(instance.errors);
                expect(input.errorText).toEqual(instance.errorText);
                expect(input.fieldType).toEqual(instance.fieldType);
                expect(input.helpText).toEqual(instance.helpText);
                expect(input.isCompleted).toEqual(instance.isCompleted);
                expect(input.label).toEqual(instance.label);
                expect(input.labelId).toEqual(instance.labelId);
                expect(input.labelledBy).toEqual(instance.labelledBy);
                expect(input.max).toEqual(instance.maxValue);
                expect(input.min).toEqual(instance.minValue);
                expect(input.pattern).toEqual(instance.pattern);
                expect(input.placeholder).toEqual(instance.placeholder);
                expect(input.pristine).toEqual(instance.pristine);
                expect(input.questionId).toEqual(instance.questionId);
                expect(input.required).toEqual(instance.isRequired);
                expect(input.text).toEqual(instance.value);
                expect(input.touched).toEqual(instance.touched);
                const container = page.root.querySelector('bp-sdk-driver-input-container');
                expect(container.answerId).toEqual(instance.answerId);
                expect(container.code).toEqual(instance.code);
                expect(container.errors).toEqual(instance.errors);
                expect(container.errorText).toEqual(instance.errorText);
                expect(container.fieldType).toEqual(instance.fieldType);
                expect(input.helpText).toEqual(instance.helpText);
                expect(container.isCompleted).toEqual(instance.isCompleted);
                expect(container.label).toEqual(instance.label);
                expect(container.labelId).toEqual(instance.labelId);
                expect(container.labelledBy).toEqual(instance.labelledBy);
                expect(container.max).toEqual(instance.maxValue);
                expect(container.min).toEqual(instance.minValue);
                expect(container.pattern).toEqual(instance.pattern);
                expect(container.placeholder).toEqual(instance.placeholder);
                expect(container.pristine).toEqual(instance.pristine);
                expect(container.questionGroupId).toEqual(instance.questionGroupId);
                expect(container.questionId).toEqual(instance.questionId);
                expect(container.questionPoolId).toEqual(instance.answerPoolId);
                expect(container.required).toEqual(instance.isRequired);
                expect(container.text).toEqual(instance.value);
                expect(container.touched).toEqual(instance.touched);
            });
            it('masked', async () => {
                const page = await setupPage([BpSdkMaskedInputContainer, BpSdkMaskedInput]);
                const instance = page.rootInstance;
                instance.isLabelledField = true;
                instance.inputComponentType = 'masked';
                setupInstance(instance);
                await page.waitForChanges();
                const input = page.root.querySelector('bp-sdk-masked-input');
                const container = page.root.querySelector('bp-sdk-masked-input-container');
                expect(container.referenceType).toEqual(instance.referenceType);
                expect(input).toBeTruthy();
                expect(input.answerId).toEqual(instance.answerId);
                expect(input.code).toEqual(instance.code);
                expect(input.errors).toEqual(instance.errors);
                expect(input.errorText).toEqual(instance.errorText);
                expect(input.fieldType).toEqual(instance.fieldType);
                expect(input.helpText).toEqual(instance.helpText);
                expect(input.isCompleted).toEqual(instance.isCompleted);
                expect(input.label).toEqual(instance.label);
                expect(input.labelId).toEqual(instance.labelId);
                expect(input.labelledBy).toEqual(instance.labelledBy);
                expect(input.max).toEqual(instance.maxValue);
                expect(input.maxDate).toEqual(instance.maxDate);
                expect(input.min).toEqual(instance.minValue);
                expect(input.minDate).toEqual(instance.minDate);
                expect(input.pattern).toEqual(instance.pattern);
                expect(input.placeholder).toEqual(instance.placeholder);
                expect(input.pristine).toEqual(instance.pristine);
                expect(input.questionId).toEqual(instance.questionId);
                expect(input.required).toEqual(instance.isRequired);
                expect(input.touched).toEqual(instance.touched);
                expect(input.value).toEqual(instance.value);
            });
            it('date', async () => {
                const page = await setupPage([BpSdkDateInputContainer, BpSdkDateInput]);
                const instance = page.rootInstance;
                setupInstance(instance);
                instance.isLabelledField = true;
                instance.isSensitive = false;
                instance.inputComponentType = 'date';
                await page.waitForChanges();
                const input = page.root.querySelector('bp-sdk-date-input');
                expect(input).toBeTruthy();
                expect(input.answerId).toEqual(instance.answerId);
                expect(input.code).toEqual(instance.code);
                expect(input.errors).toEqual(instance.errors);
                expect(input.errorText).toEqual(instance.errorText);
                expect(input.fieldType).toEqual(instance.fieldType);
                expect(input.helpText).toEqual(instance.helpText);
                expect(input.isCompleted).toEqual(instance.isCompleted);
                expect(input.isSensitive).toEqual(instance.isSensitive);
                expect(input.label).toEqual(instance.label);
                expect(input.labelId).toEqual(instance.labelId);
                expect(input.labelledBy).toEqual(instance.labelledBy);
                expect(input.maxDate).toEqual(instance.maxDate);
                expect(input.minDate).toEqual(instance.minDate);
                expect(input.pattern).toEqual(instance.pattern);
                expect(input.placeholder).toEqual(instance.placeholder);
                expect(input.pristine).toEqual(instance.pristine);
                expect(input.questionId).toEqual(instance.questionId);
                expect(input.required).toEqual(instance.isRequired);
                expect(input.text).toEqual(instance.text);
                expect(input.touched).toEqual(instance.touched);
                expect(input.value).toEqual(instance.value);
            });
            it('sensitive date', async () => {
                const page = await setupPage([BpSdkMaskedInputContainer, BpSdkMaskedInput]);
                const instance = page.rootInstance;
                instance.isLabelledField = true;
                instance.inputComponentType = 'date';
                instance.isSensitive = true;
                setupInstance(instance);
                await page.waitForChanges();
                const input = page.root.querySelector('bp-sdk-masked-input');
                const container = page.root.querySelector('bp-sdk-masked-input-container');
                expect(container.referenceType).toEqual(instance.referenceType);
                expect(input).toBeTruthy();
                expect(input.answerId).toEqual(instance.answerId);
                expect(input.code).toEqual(instance.code);
                expect(input.errors).toEqual(instance.errors);
                expect(input.errorText).toEqual(instance.errorText);
                expect(input.fieldType).toEqual(instance.fieldType);
                expect(input.helpText).toEqual(instance.helpText);
                expect(input.isCompleted).toEqual(instance.isCompleted);
                expect(input.label).toEqual(instance.label);
                expect(input.labelId).toEqual(instance.labelId);
                expect(input.labelledBy).toEqual(instance.labelledBy);
                expect(input.max).toEqual(instance.maxValue);
                expect(input.maxDate).toEqual(instance.maxDate);
                expect(input.min).toEqual(instance.minValue);
                expect(input.minDate).toEqual(instance.minDate);
                expect(input.pattern).toEqual(instance.pattern);
                expect(input.placeholder).toEqual(instance.placeholder);
                expect(input.pristine).toEqual(instance.pristine);
                expect(input.questionId).toEqual(instance.questionId);
                expect(input.required).toEqual(instance.isRequired);
                expect(input.touched).toEqual(instance.touched);
                expect(input.value).toEqual(instance.value);
            });
            describe('dropdown', () => {
                it('business classification selector', async () => {
                    const page = await setupPage([BpSdkBusinessClassificationSelectorContainer, BpSdkBusinessClassificationSelector]);
                    const instance = page.rootInstance;
                    instance.isLabelledField = true;
                    instance.inputComponentType = 'dropdown';
                    setupInstance(instance);
                    instance.referenceType = 'business_class';
                    instance.showBusinessClassificationSelector = true;
                    instance.isAutocomplete = true;
                    await page.waitForChanges();
                    const input = page.root.querySelector('bp-sdk-business-classification-selector-container');
                    expect(input).toBeTruthy();
                    expect(input.answerId).toEqual(instance.answerId);
                    expect(input.choiceId).toEqual(instance.choiceId);
                    expect(input.choices).toEqual(instance.choices);
                    expect(input.code).toEqual(instance.code);
                    expect(input.errors).toEqual(instance.errors);
                    expect(input.errorText).toEqual(instance.errorText);
                    expect(input.fieldType).toEqual(instance.fieldType);
                    expect(input.helpText).toEqual(instance.helpText);
                    expect(input.isCompleted).toEqual(instance.isCompleted);
                    expect(input.label).toEqual(instance.label);
                    expect(input.labelId).toEqual(instance.labelId);
                    expect(input.labelledBy).toEqual(instance.labelledBy);
                    expect(input.placeholder).toEqual(instance.placeholder);
                    expect(input.pristine).toEqual(instance.pristine);
                    expect(input.questionId).toEqual(instance.questionId);
                    expect(input.required).toEqual(instance.isRequired);
                    expect(input.touched).toEqual(instance.touched);
                });
                it('business classification selector - fallback autocomplete if not showBusinessClassificationSelector', async () => {
                    const page = await setupPage([BpSdkAutocompleteNaicsContainer, BpSdkAutocompleteInput]);
                    const instance = page.rootInstance;
                    setupInstance(instance);
                    instance.isLabelledField = true;
                    instance.referenceType = 'business_class';
                    instance.inputComponentType = 'dropdown';
                    instance.showBusinessClassificationSelector = false;
                    instance.isAutocomplete = true;
                    await page.waitForChanges();
                    const input = page.root.querySelector('bp-sdk-autocomplete-input');
                    expect(input).toBeTruthy();
                    expect(input.answerId).toEqual(instance.answerId);
                    expect(input.choiceId).toEqual(instance.choiceId);
                    expect(input.choices).toEqual(instance.choices);
                    expect(input.code).toEqual(instance.code);
                    expect(input.errors).toEqual(instance.errors);
                    expect(input.errorText).toEqual(instance.errorText);
                    expect(input.fieldType).toEqual(instance.fieldType);
                    expect(input.helpText).toEqual(instance.helpText);
                    expect(input.isCompleted).toEqual(instance.isCompleted);
                    expect(input.label).toEqual(instance.label);
                    expect(input.labelId).toEqual(instance.labelId);
                    expect(input.labelledBy).toEqual(instance.labelledBy);
                    expect(input.placeholder).toEqual(instance.placeholder);
                    expect(input.pristine).toEqual(instance.pristine);
                    expect(input.questionId).toEqual(instance.questionId);
                    expect(input.required).toEqual(instance.isRequired);
                    expect(input.touched).toEqual(instance.touched);
                });
                it('business classification selector fallback', async () => {
                    const page = await setupPage([BpSdkAutocompleteNaicsContainer, BpSdkAutocompleteInput]);
                    const instance = page.rootInstance;
                    setupInstance(instance);
                    instance.isLabelledField = true;
                    instance.referenceType = 'fallback';
                    instance.inputComponentType = 'dropdown';
                    instance.showBusinessClassificationSelector = true;
                    instance.isAutocomplete = true;
                    await page.waitForChanges();
                    const input = page.root.querySelector('bp-sdk-autocomplete-input');
                    expect(input).toBeTruthy();
                    expect(input.answerId).toEqual(instance.answerId);
                    expect(input.choiceId).toEqual(instance.choiceId);
                    expect(input.choices).toEqual(instance.choices);
                    expect(input.code).toEqual(instance.code);
                    expect(input.errors).toEqual(instance.errors);
                    expect(input.errorText).toEqual(instance.errorText);
                    expect(input.fieldType).toEqual(instance.fieldType);
                    expect(input.helpText).toEqual(instance.helpText);
                    expect(input.isCompleted).toEqual(instance.isCompleted);
                    expect(input.label).toEqual(instance.label);
                    expect(input.labelId).toEqual(instance.labelId);
                    expect(input.labelledBy).toEqual(instance.labelledBy);
                    expect(input.placeholder).toEqual(instance.placeholder);
                    expect(input.pristine).toEqual(instance.pristine);
                    expect(input.questionId).toEqual(instance.questionId);
                    expect(input.required).toEqual(instance.isRequired);
                    expect(input.touched).toEqual(instance.touched);
                });
                it('autocomplete-input', async () => {
                    const page = await setupPage([BpSdkAutocompleteNaicsContainer, BpSdkAutocompleteInput]);
                    const instance = page.rootInstance;
                    setupInstance(instance);
                    instance.isLabelledField = true;
                    instance.referenceType = 'business_class';
                    instance.inputComponentType = 'dropdown';
                    instance.showBusinessClassificationSelector = false;
                    instance.isAutocomplete = true;
                    await page.waitForChanges();
                    const input = page.root.querySelector('bp-sdk-autocomplete-input');
                    expect(input).toBeTruthy();
                    expect(input.answerId).toEqual(instance.answerId);
                    expect(input.choiceId).toEqual(instance.choiceId);
                    expect(input.choices).toEqual(instance.choices);
                    expect(input.code).toEqual(instance.code);
                    expect(input.errors).toEqual(instance.errors);
                    expect(input.errorText).toEqual(instance.errorText);
                    expect(input.fieldType).toEqual(instance.fieldType);
                    expect(input.helpText).toEqual(instance.helpText);
                    expect(input.isCompleted).toEqual(instance.isCompleted);
                    expect(input.label).toEqual(instance.label);
                    expect(input.labelId).toEqual(instance.labelId);
                    expect(input.labelledBy).toEqual(instance.labelledBy);
                    expect(input.placeholder).toEqual(instance.placeholder);
                    expect(input.pristine).toEqual(instance.pristine);
                    expect(input.questionId).toEqual(instance.questionId);
                    expect(input.required).toEqual(instance.isRequired);
                    expect(input.touched).toEqual(instance.touched);
                });
                it('autocomplete-input fallback', async () => {
                    const page = await setupPage([BpSdkAutocompleteNaicsContainer, BpSdkAutocompleteInput]);
                    const instance = page.rootInstance;
                    setupInstance(instance);
                    instance.isLabelledField = true;
                    instance.referenceType = 'something';
                    instance.inputComponentType = 'dropdown';
                    instance.showBusinessClassificationSelector = false;
                    instance.isAutocomplete = true;
                    await page.waitForChanges();
                    const input = page.root.querySelector('bp-sdk-autocomplete-input');
                    expect(input).toBeTruthy();
                    expect(input.answerId).toEqual(instance.answerId);
                    expect(input.choiceId).toEqual(instance.choiceId);
                    expect(input.choices).toEqual(instance.choices);
                    expect(input.code).toEqual(instance.code);
                    expect(input.errors).toEqual(instance.errors);
                    expect(input.errorText).toEqual(instance.errorText);
                    expect(input.fieldType).toEqual(instance.fieldType);
                    expect(input.helpText).toEqual(instance.helpText);
                    expect(input.isCompleted).toEqual(instance.isCompleted);
                    expect(input.label).toEqual(instance.label);
                    expect(input.labelId).toEqual(instance.labelId);
                    expect(input.labelledBy).toEqual(instance.labelledBy);
                    expect(input.placeholder).toEqual(instance.placeholder);
                    expect(input.pristine).toEqual(instance.pristine);
                    expect(input.questionId).toEqual(instance.questionId);
                    expect(input.required).toEqual(instance.isRequired);
                    expect(input.touched).toEqual(instance.touched);
                });
                it('coverage_type', async () => {
                    const page = await setupPage([BpSdkProductListContainer, BpSdkProductList]);
                    const instance = page.rootInstance;
                    setupInstance(instance);
                    instance.isLabelledField = false;
                    instance.inputComponentType = 'dropdown';
                    instance.referenceType = 'lines_of_business';
                    await page.waitForChanges();
                    const input = page.root.querySelector('bp-sdk-product-list');
                    expect(input).toBeTruthy();
                    expect(input.answerId).toEqual(instance.answerId);
                    expect(input.choiceId).toEqual(instance.choiceId);
                    expect(input.choiceIds).toEqual(instance.choiceIds);
                    expect(input.choices).toEqual(instance.choices);
                    expect(input.code).toEqual(instance.code);
                    expect(input.errorText).toEqual(instance.errorText);
                    expect(input.fieldType).toEqual(instance.fieldType);
                    expect(input.helpText).toEqual(instance.helpText);
                    expect(input.isMultiple).toEqual(instance.isMultiple);
                    expect(input.label).toEqual(instance.placeholder);
                    expect(input.labelledBy).toEqual(instance.labelledBy);
                    expect(input.pristine).toEqual(instance.pristine);
                    expect(input.questionId).toEqual(instance.questionId);
                    expect(input.touched).toEqual(instance.touched);
                });
                it('select', async () => {
                    const page = await setupPage([BpSdkSelectInput, BpSdkSelectInputContainer]);
                    const instance = page.rootInstance;
                    setupInstance(instance);
                    instance.isLabelledField = true;
                    instance.isAutocomplete = false;
                    instance.inputComponentType = 'dropdown';
                    instance.showBusinessClassificationSelector = false;
                    await page.waitForChanges();
                    const input = page.root.querySelector('bp-sdk-select-input');
                    const container = page.root.querySelector('bp-sdk-select-input-container');
                    expect(container.referenceType).toEqual(instance.referenceType);
                    expect(input).toBeTruthy();
                    expect(input.choiceId).toEqual(instance.choiceId);
                    expect(input.choiceIds).toEqual(instance.choiceIds);
                    expect(input.choices).toEqual(instance.choices);
                    expect(input.code).toEqual(instance.code);
                    expect(input.errors).toEqual(instance.errors);
                    expect(input.errorText).toEqual(instance.errorText);
                    expect(input.fieldType).toEqual(instance.fieldType);
                    expect(input.helpText).toEqual(instance.helpText);
                    expect(input.isCompleted).toEqual(instance.isCompleted);
                    expect(input.label).toEqual(instance.label);
                    expect(input.labelId).toEqual(instance.labelId);
                    expect(input.labelledBy).toEqual(instance.labelledBy);
                    expect(input.placeholder).toEqual(instance.placeholder);
                    expect(input.pristine).toEqual(instance.pristine);
                    expect(input.questionId).toEqual(instance.questionId);
                    expect(input.required).toEqual(instance.isRequired);
                    expect(input.touched).toEqual(instance.touched);
                });
                it('select if not isAutocomplete and showBusinessClassificationSelector', async () => {
                    const page = await setupPage([BpSdkSelectInput, BpSdkSelectInputContainer]);
                    const instance = page.rootInstance;
                    setupInstance(instance);
                    instance.isLabelledField = true;
                    instance.isAutocomplete = false;
                    instance.inputComponentType = 'dropdown';
                    instance.showBusinessClassificationSelector = true;
                    await page.waitForChanges();
                    const input = page.root.querySelector('bp-sdk-select-input');
                    const container = page.root.querySelector('bp-sdk-select-input-container');
                    expect(container.referenceType).toEqual(instance.referenceType);
                    expect(input).toBeTruthy();
                    expect(input.choiceId).toEqual(instance.choiceId);
                    expect(input.choiceIds).toEqual(instance.choiceIds);
                    expect(input.choices).toEqual(instance.choices);
                    expect(input.code).toEqual(instance.code);
                    expect(input.errors).toEqual(instance.errors);
                    expect(input.errorText).toEqual(instance.errorText);
                    expect(input.fieldType).toEqual(instance.fieldType);
                    expect(input.helpText).toEqual(instance.helpText);
                    expect(input.isCompleted).toEqual(instance.isCompleted);
                    expect(input.label).toEqual(instance.label);
                    expect(input.labelId).toEqual(instance.labelId);
                    expect(input.labelledBy).toEqual(instance.labelledBy);
                    expect(input.placeholder).toEqual(instance.placeholder);
                    expect(input.pristine).toEqual(instance.pristine);
                    expect(input.questionId).toEqual(instance.questionId);
                    expect(input.required).toEqual(instance.isRequired);
                    expect(input.touched).toEqual(instance.touched);
                });
            });
            it('radio-dialog', async () => {
                const page = await newSpecPage({
                    html: '<bp-sdk-dynamic-input></bp-sdk-dynamic-input>',
                    components: [BpSdkDynamicInput, BpSdkDialog, BpSdkRadioInput, BpSdkRadioDialog],
                });
                const instance = page.rootInstance;
                setupInstance(instance);
                instance.inputComponentType = 'dialog';
                await page.waitForChanges();
                const input = page.root.querySelector('bp-sdk-radio-dialog');
                expect(input).toBeTruthy();
                expect(input.answerId).toEqual(instance.answerId);
                expect(input.choiceId).toEqual(instance.choiceId);
                expect(input.choices).toEqual(instance.choices);
                expect(input.code).toEqual(instance.code);
                expect(input.errors).toEqual(instance.errors);
                expect(input.errorText).toEqual(instance.errorText);
                expect(input.fieldType).toEqual(instance.fieldType);
                expect(input.helpText).toEqual(instance.helpText);
                expect(input.isCompleted).toEqual(instance.isCompleted);
                expect(input.label).toEqual(instance.text);
                expect(input.labelledBy).toEqual(instance.labelledBy);
                expect(input.pristine).toEqual(instance.pristine);
                expect(input.questionId).toEqual(instance.questionId);
                expect(input.isRequired).toEqual(instance.isRequired);
                expect(input.touched).toEqual(instance.touched);
            });
        });
        describe('unlabelled', () => {
            it('missing', async () => {
                const page = await setupPage([BpSdkLabel]);
                const instance = page.rootInstance;
                instance.isLabelledField = false;
                instance.fieldType = 'missing type';
                instance.code = 'some code';
                jest.spyOn(instance.componentMissing, 'emit').mockImplementation((() => { }));
                await page.waitForChanges();
                expect(instance.componentMissing.emit).toHaveBeenCalledWith(`Missing question type: ${instance.fieldType} - ${instance.code}`);
            });
            it('checkbox', async () => {
                const page = await setupPage([BpSdkCheckboxInput]);
                const instance = page.rootInstance;
                setupInstance(instance);
                instance.isLabelledField = false;
                instance.inputComponentType = 'checkbox';
                await page.waitForChanges();
                const input = page.root.querySelector('bp-sdk-checkbox-input');
                expect(input).toBeTruthy();
                expect(input.answerId).toEqual(instance.answerId);
                expect(input.code).toEqual(instance.code);
                expect(input.errors).toEqual(instance.errors);
                expect(input.errorText).toEqual(instance.errorText);
                expect(input.fieldType).toEqual(instance.fieldType);
                expect(input.helpText).toEqual(instance.helpText);
                expect(input.isCompleted).toEqual(instance.isCompleted);
                expect(input.label).toEqual(instance.text);
                expect(input.labelledBy).toEqual(instance.labelledBy);
                expect(input.pristine).toEqual(instance.pristine);
                expect(input.questionId).toEqual(instance.questionId);
                expect(input.required).toEqual(instance.isRequired);
                expect(input.touched).toEqual(instance.touched);
                expect(input.value).toEqual(!!instance.value);
            });
            it('radio', async () => {
                const page = await setupPage([BpSdkRadioInput]);
                const instance = page.rootInstance;
                setupInstance(instance);
                instance.isLabelledField = false;
                instance.inputComponentType = 'radio';
                await page.waitForChanges();
                const input = page.root.querySelector('bp-sdk-radio-input');
                expect(input).toBeTruthy();
                expect(input.answerId).toEqual(instance.answerId);
                expect(input.choiceId).toEqual(instance.choiceId);
                expect(input.choices).toEqual(instance.choices);
                expect(input.code).toEqual(instance.code);
                expect(input.errors).toEqual(instance.errors);
                expect(input.errorText).toEqual(instance.errorText);
                expect(input.fieldType).toEqual(instance.fieldType);
                expect(input.helpText).toEqual(instance.helpText);
                expect(input.isCompleted).toEqual(instance.isCompleted);
                expect(input.label).toEqual(instance.text);
                expect(input.labelledBy).toEqual(instance.labelledBy);
                expect(input.pristine).toEqual(instance.pristine);
                expect(input.questionId).toEqual(instance.questionId);
                expect(input.required).toEqual(instance.isRequired);
                expect(input.touched).toEqual(instance.touched);
            });
            it('coverage_type', async () => {
                const page = await setupPage([BpSdkProductListContainer, BpSdkProductList]);
                const instance = page.rootInstance;
                setupInstance(instance);
                instance.isLabelledField = false;
                instance.inputComponentType = 'coverage_type';
                await page.waitForChanges();
                const input = page.root.querySelector('bp-sdk-product-list');
                expect(input).toBeTruthy();
                expect(input.answerId).toEqual(instance.answerId);
                expect(input.choiceId).toEqual(instance.choiceId);
                expect(input.choiceIds).toEqual(instance.choiceIds);
                expect(input.choices).toEqual(instance.choices);
                expect(input.code).toEqual(instance.code);
                expect(input.errorText).toEqual(instance.errorText);
                expect(input.fieldType).toEqual(instance.fieldType);
                expect(input.helpText).toEqual(instance.helpText);
                expect(input.isMultiple).toEqual(instance.isMultiple);
                expect(input.label).toEqual(instance.placeholder);
                expect(input.labelledBy).toEqual(instance.labelledBy);
                expect(input.pristine).toEqual(instance.pristine);
                expect(input.questionId).toEqual(instance.questionId);
                expect(input.touched).toEqual(instance.touched);
            });
        });
    });
    describe('anchor', () => {
        it('adds anchor', async () => {
            const page = await setupPage([BpSdkAddQuestionPoolItemContainer, BpSdkAddItemContainer]);
            const instance = page.rootInstance;
            setupInstance(instance);
            instance.inputComponentType = 'anchor';
            instance.code = 'add_vehicle';
            await page.waitForChanges();
            const container = page.root.querySelector('bp-sdk-add-question-pool-item-container');
            expect(container).toBeTruthy();
            expect(container.helpText).toEqual(instance.helpText);
            expect(container.questionId).toEqual(instance.questionId);
            expect(container.questionSetId).toEqual(instance.questionSetId);
            expect(container.text).toEqual(instance.text);
            const element = page.root.querySelector('bp-sdk-add-item-container');
            expect(element).toBeFalsy();
        });
    });
    describe('delete_pool', () => {
        it('delete_pool', async () => {
            const page = await setupPage([BpSdkDeleteQuestionPoolItemContainer, BpSdkDeleteQuestionPoolItem, BpSdkDeleteButton]);
            const instance = page.rootInstance;
            setupInstance(instance);
            instance.inputComponentType = 'delete_pool';
            await page.waitForChanges();
            const container = page.root.querySelector('bp-sdk-delete-question-pool-item-container');
            expect(container).toBeTruthy();
            expect(container.answerPoolId).toEqual(instance.answerPoolId);
            expect(container.text).toEqual(instance.text);
            // no question pool, can't render
            const element = page.root.querySelector('bp-sdk-delete-button');
            expect(element).toBeTruthy();
        });
    });
    describe('vehicle', () => {
        it('vehicle - years', async () => {
            const page = await setupPage([BpSdkAutocompleteNaicsContainer, BpSdkAutocompleteInput]);
            const instance = page.rootInstance;
            setupInstance(instance);
            instance.isLabelledField = true;
            instance.inputComponentType = 'vehicle';
            instance.referenceType = 'years';
            await page.waitForChanges();
            const input = page.root.querySelector('bp-sdk-autocomplete-input');
            expect(input).toBeTruthy();
            expect(input.allowFallthrough).toBeFalsy();
            expect(input.answerId).toEqual(instance.answerId);
            expect(input.choiceId).toEqual(instance.choiceId);
            expect(input.choices).toEqual(instance.choices);
            expect(input.code).toEqual(instance.code);
            expect(input.errors).toEqual(instance.errors);
            expect(input.errorText).toEqual(instance.errorText);
            expect(input.fieldType).toEqual(instance.fieldType);
            expect(input.helpText).toEqual(instance.helpText);
            expect(input.isCompleted).toEqual(instance.isCompleted);
            expect(input.label).toEqual(instance.label);
            expect(input.labelId).toEqual(instance.labelId);
            expect(input.labelledBy).toEqual(instance.labelledBy);
            expect(input.placeholder).toEqual(instance.placeholder);
            expect(input.pristine).toEqual(instance.pristine);
            expect(input.questionId).toEqual(instance.questionId);
            expect(input.required).toEqual(instance.isRequired);
            expect(input.showNoChoicesFallback).toBeFalsy();
            expect(input.touched).toEqual(instance.touched);
        });
        it('vehicle - makes', async () => {
            const page = await setupPage([BpSdkAutocompleteNaicsContainer, BpSdkAutocompleteInput]);
            const instance = page.rootInstance;
            setupInstance(instance);
            instance.isLabelledField = true;
            instance.inputComponentType = 'vehicle';
            instance.referenceType = 'makes';
            await page.waitForChanges();
            const input = page.root.querySelector('bp-sdk-autocomplete-input');
            expect(input).toBeTruthy();
            expect(input.allowFallthrough).toBeTruthy();
            expect(input.answerId).toEqual(instance.answerId);
            expect(input.choiceId).toEqual(instance.choiceId);
            expect(input.choices).toEqual(instance.choices);
            expect(input.code).toEqual(instance.code);
            expect(input.errors).toEqual(instance.errors);
            expect(input.errorText).toEqual(instance.errorText);
            expect(input.fieldType).toEqual(instance.fieldType);
            expect(input.helpText).toEqual(instance.helpText);
            expect(input.isCompleted).toEqual(instance.isCompleted);
            expect(input.label).toEqual(instance.label);
            expect(input.labelId).toEqual(instance.labelId);
            expect(input.labelledBy).toEqual(instance.labelledBy);
            expect(input.placeholder).toEqual(instance.placeholder);
            expect(input.pristine).toEqual(instance.pristine);
            expect(input.questionId).toEqual(instance.questionId);
            expect(input.required).toEqual(instance.isRequired);
            expect(input.showNoChoicesFallback).toBeFalsy();
            expect(input.touched).toEqual(instance.touched);
        });
        it('vehicle - models', async () => {
            const page = await setupPage([BpSdkAutocompleteNaicsContainer, BpSdkAutocompleteInput]);
            const instance = page.rootInstance;
            setupInstance(instance);
            instance.isLabelledField = true;
            instance.inputComponentType = 'vehicle';
            instance.referenceType = 'models';
            await page.waitForChanges();
            const input = page.root.querySelector('bp-sdk-autocomplete-input');
            expect(input).toBeTruthy();
            expect(input.allowFallthrough).toBeTruthy();
            expect(input.answerId).toEqual(instance.answerId);
            expect(input.choiceId).toEqual(instance.choiceId);
            expect(input.choices).toEqual(instance.choices);
            expect(input.code).toEqual(instance.code);
            expect(input.errors).toEqual(instance.errors);
            expect(input.errorText).toEqual(instance.errorText);
            expect(input.fieldType).toEqual(instance.fieldType);
            expect(input.helpText).toEqual(instance.helpText);
            expect(input.isCompleted).toEqual(instance.isCompleted);
            expect(input.label).toEqual(instance.label);
            expect(input.labelId).toEqual(instance.labelId);
            expect(input.labelledBy).toEqual(instance.labelledBy);
            expect(input.placeholder).toEqual(instance.placeholder);
            expect(input.pristine).toEqual(instance.pristine);
            expect(input.questionId).toEqual(instance.questionId);
            expect(input.required).toEqual(instance.isRequired);
            expect(input.showNoChoicesFallback).toBeFalsy();
            expect(input.touched).toEqual(instance.touched);
        });
    });
});
