import { AnalyticsTrackingEventName, BpEnvironmentName, LoadingStates, ValidationStatus, } from "@boldpenguin/sdk-types";
import { getErrors, isValidAnswer } from "@boldpenguin/sdk-utility";
import { mockDocument, newSpecPage } from "@stencil/core/testing";
jest.mock('@boldpenguin/sdk-utility', () => {
    const originalModule = jest.requireActual('@boldpenguin/sdk-utility');
    return {
        getErrors,
        isValidAnswer,
        getParentAnchorAnswer: jest.fn(),
        calculateParentAnchorValue: jest.fn(),
        updateAnswerValue: jest.fn(),
        containsOnlyQuestionPoolAnchorQuestions: originalModule.containsOnlyQuestionPoolAnchorQuestions,
        focusErrors: jest.fn(),
        markElementDirty: jest.fn(),
        areAnswersValid: jest.fn(),
    };
});
import { getCurrentActiveQuestionSet, getPartnerEngineConfig } from "@boldpenguin/sdk-redux";
import { areAnswersValid, calculateParentAnchorValue, focusErrors, getParentAnchorAnswer } from "@boldpenguin/sdk-utility";
import { BpSdkNextButtonContainer } from "./bp-sdk-next-button-container";
let fakeStore;
const setupPage = async () => {
    return await newSpecPage({
        html: '<bp-sdk-next-button-container></bp-sdk-next-button-container>',
        components: [BpSdkNextButtonContainer],
    });
};
const setupInstance = (page) => {
    const instance = page.rootInstance;
    jest.spyOn(instance, 'handleNavigateNext').mockImplementation(jest.fn());
    instance.activeQuestionSet = getCurrentActiveQuestionSet(fakeStore);
    instance.config = getPartnerEngineConfig(fakeStore);
    instance.answersResourceState = fakeStore.status.remote.answers.state;
    instance.applicationFormResourceState = fakeStore.status.remote.application.form;
    instance.questionPoolResourceState = fakeStore.status.remote.questionPools.state;
    instance.questionSetResourceState = fakeStore.status.remote.questionSets.state;
    instance.isValidationTriggerOverridden = false;
    instance.addressValidationStatuses = { 1234567890: ValidationStatus.COMPLETED };
    instance.storeUnsubscribe = jest.fn();
    return instance;
};
const setupNavigateNextInstance = (page) => {
    const instance = page.rootInstance;
    instance.activeQuestionSet = getCurrentActiveQuestionSet(fakeStore);
    instance.config = getPartnerEngineConfig(fakeStore);
    instance.answersResourceState = fakeStore.status.remote.answers.state;
    instance.applicationFormResourceState = fakeStore.status.remote.application.form;
    instance.questionPoolResourceState = fakeStore.status.remote.questionPools.state;
    instance.questionSetResourceState = fakeStore.status.remote.questionSets.state;
    instance.addressIdsToBeValidated = [];
    instance.isValidationTriggerOverridden = false;
    instance.addressValidationStatuses = { 1234567890: ValidationStatus.COMPLETED };
    instance.storeUnsubscribe = jest.fn();
    return instance;
};
describe('bp-sdk-next-button-container', () => {
    beforeEach(() => {
        fakeStore = {
            application: {
                form: {
                    locked: false,
                },
                questionSets: {
                    list: [
                        {
                            id: '36b5a456-0375-4ef6-908b-177b772b93c3',
                            application_form_id: '3435c00d-801e-4d17-b5e3-098203fffce5',
                            order: 1,
                            question_set_id: '75f7b9c5-4297-4552-a3cc-5897875be1b9',
                            is_active: true,
                            is_completed: false,
                            completed_at: '2020-05-15T10:42:21.037-04:00',
                            created_at: '2020-05-15T10:38:55.706-04:00',
                            updated_at: '2020-05-15T10:42:21.071-04:00',
                            question_set: {
                                id: '75f7b9c5-4297-4552-a3cc-5897875be1b9',
                                tenant_id: 'tenant-uuid-9',
                                owner_id: 'ab85a58e-6c12-44a2-8f07-959dd6e30875',
                                name: 'Contact Information',
                                title: 'Contact Information',
                                code: 'mock_contact_info',
                                created_at: '2020-05-15T10:10:13.578-04:00',
                                question_ids: [
                                    '839c31c9-5da1-4d65-9847-88643216ba08',
                                    '5ea6e744-1413-4e92-85ff-e0f0680e8b36',
                                    '403841f5-0b2e-4ffc-a599-b80727f0e44c',
                                    '6783cc50-ec16-42e5-9313-c9c0445b632a',
                                    'd74470e7-9388-49a5-a93a-4159e87d6389',
                                    'dea9f45f-a6ed-4617-af28-882a27f89fd7',
                                    '23c00753-fdd6-4216-9eac-a8ce5c0b4863',
                                    'a2a69126-1909-4b6e-977c-97d21b4468b3',
                                    'abdfd092-376f-4c9c-a96e-a8e25a566a04',
                                    '6f3dab45-b53c-4f68-8ba5-84616ec999f4',
                                    'c4358cfc-b2b3-48a8-9e40-df6c0711a499',
                                    '82842893-0b7c-43b8-9b06-f18f935f58a5',
                                    '877caa6d-5990-4b3c-8f35-310938de91fb',
                                    'c06796c1-5664-4c1c-bcfd-fc17b6790565',
                                    '8abd3ff5-1b5b-4b29-9b07-ff42d4971b2a',
                                ],
                                updated_at: '2020-05-15T10:10:13.578-04:00',
                                question_groups: [
                                    {
                                        id: '4b914f71-eae3-4e14-bcf1-f45d7407a859',
                                        tenant_id: 'tenant-uuid-9',
                                        owner_id: 'ab85a58e-6c12-44a2-8f07-959dd6e30875',
                                        group_type: 'split_horizontal',
                                        parent_question_id: 'abdfd092-376f-4c9c-a96e-a8e25a566a04',
                                        label: null,
                                        question_ids: ['abdfd092-376f-4c9c-a96e-a8e25a566a04', '6f3dab45-b53c-4f68-8ba5-84616ec999f4'],
                                        created_at: '2020-05-15T10:12:31.221-04:00',
                                        updated_at: '2020-05-15T10:12:31.221-04:00',
                                    },
                                    {
                                        id: 'bc4d6d88-bb0e-4f3c-a43e-9932cfca6e2c',
                                        tenant_id: 'tenant-uuid-9',
                                        owner_id: 'ab85a58e-6c12-44a2-8f07-959dd6e30875',
                                        group_type: 'address',
                                        parent_question_id: 'a2a69126-1909-4b6e-977c-97d21b4468b3',
                                        label: 'Business Address',
                                        question_ids: [
                                            'a2a69126-1909-4b6e-977c-97d21b4468b3',
                                            'c4358cfc-b2b3-48a8-9e40-df6c0711a499',
                                            '82842893-0b7c-43b8-9b06-f18f935f58a5',
                                            '877caa6d-5990-4b3c-8f35-310938de91fb',
                                            'c06796c1-5664-4c1c-bcfd-fc17b6790565',
                                            '8abd3ff5-1b5b-4b29-9b07-ff42d4971b2a',
                                        ],
                                        created_at: '2020-05-15T10:12:31.264-04:00',
                                        updated_at: '2020-05-15T10:12:31.264-04:00',
                                    },
                                ],
                            },
                            answers: [
                                {
                                    id: 'a832db22-d3e2-4fb6-913c-f7594df2c93e',
                                    value: null,
                                    choice_id: null,
                                    choice_ids: [],
                                    active: true,
                                    version: 2,
                                    display_type: 'public',
                                    application_form_id: '3435c00d-801e-4d17-b5e3-098203fffce5',
                                    is_completed: true,
                                    created_at: '2020-05-15T10:38:55.409-04:00',
                                    updated_at: '2020-05-15T10:38:55.409-04:00',
                                    is_readonly: true,
                                    question: {
                                        id: '839c31c9-5da1-4d65-9847-88643216ba08',
                                        code: 'mock_describe_business_label',
                                        text: 'Describe Your Business',
                                        error_text: null,
                                        help_text: null,
                                        order: 1,
                                        question_set_id: '75f7b9c5-4297-4552-a3cc-5897875be1b9',
                                        field_type: 'label',
                                        multiple: false,
                                        autocomplete: false,
                                        min_value: null,
                                        max_value: null,
                                        min_date: null,
                                        max_date: null,
                                        pattern: '',
                                        is_hidden: false,
                                        is_active: false,
                                        is_sensitive: false,
                                        required: false,
                                        trackable: false,
                                        created_at: '2020-05-15T10:10:14.070-04:00',
                                        updated_at: '2020-05-15T10:10:14.070-04:00',
                                        question_group_id: null,
                                        reference_type: null,
                                        placeholder: null,
                                        deactivated: false,
                                        choices: [],
                                    },
                                },
                                {
                                    id: 'dc6b47e9-fe24-4f83-98e6-503c8645cde2',
                                    value: null,
                                    choice_id: '3aabecaf-188e-4f63-b7b1-6c100374153c',
                                    choice_ids: [],
                                    active: true,
                                    version: 3,
                                    display_type: 'public',
                                    application_form_id: '3435c00d-801e-4d17-b5e3-098203fffce5',
                                    is_completed: true,
                                    created_at: '2020-05-15T10:38:55.427-04:00',
                                    updated_at: '2020-05-15T10:41:49.891-04:00',
                                    is_readonly: false,
                                    question: {
                                        id: '5ea6e744-1413-4e92-85ff-e0f0680e8b36',
                                        code: 'mock_naics',
                                        text: "What's your main profession?",
                                        error_text: null,
                                        help_text: null,
                                        order: 2,
                                        question_set_id: '75f7b9c5-4297-4552-a3cc-5897875be1b9',
                                        field_type: 'dropdown',
                                        multiple: false,
                                        autocomplete: true,
                                        min_value: null,
                                        max_value: null,
                                        min_date: null,
                                        max_date: null,
                                        pattern: '',
                                        is_hidden: false,
                                        is_active: false,
                                        is_sensitive: false,
                                        required: true,
                                        trackable: false,
                                        created_at: '2020-05-15T10:10:20.331-04:00',
                                        updated_at: '2020-05-15T10:10:20.331-04:00',
                                        question_group_id: null,
                                        reference_type: 'business_class',
                                        placeholder: 'i.e. Trucking, Landscaping, Contractor, etc.',
                                        deactivated: false,
                                        choices: [
                                            {
                                                id: '3aabecaf-188e-4f63-b7b1-6c100374153c',
                                                value: 'Advertising agencies',
                                                alias: '541810',
                                                order: 3303,
                                                question_id: '5ea6e744-1413-4e92-85ff-e0f0680e8b36',
                                                created_at: '2020-05-15T10:10:30.045-04:00',
                                                updated_at: '2020-05-15T10:10:30.045-04:00',
                                            },
                                        ],
                                    },
                                },
                                {
                                    id: 'db8ff89b-053b-47c4-9813-9fd353fd1368',
                                    value: null,
                                    choice_id: null,
                                    choice_ids: [],
                                    active: true,
                                    version: 2,
                                    display_type: 'public',
                                    application_form_id: '3435c00d-801e-4d17-b5e3-098203fffce5',
                                    is_completed: true,
                                    created_at: '2020-05-15T10:38:55.440-04:00',
                                    updated_at: '2020-05-15T10:38:55.440-04:00',
                                    is_readonly: true,
                                    question: {
                                        id: '403841f5-0b2e-4ffc-a599-b80727f0e44c',
                                        code: 'mock_contact_information_label',
                                        text: 'Contact Information',
                                        error_text: null,
                                        help_text: null,
                                        order: 3,
                                        question_set_id: '75f7b9c5-4297-4552-a3cc-5897875be1b9',
                                        field_type: 'label',
                                        multiple: false,
                                        autocomplete: false,
                                        min_value: null,
                                        max_value: null,
                                        min_date: null,
                                        max_date: null,
                                        pattern: '',
                                        is_hidden: false,
                                        is_active: false,
                                        is_sensitive: false,
                                        required: false,
                                        trackable: false,
                                        created_at: '2020-05-15T10:12:11.660-04:00',
                                        updated_at: '2020-05-15T10:12:11.660-04:00',
                                        question_group_id: null,
                                        reference_type: null,
                                        placeholder: null,
                                        deactivated: false,
                                        choices: [],
                                    },
                                },
                                {
                                    id: 'd25774b8-9480-4aac-bbfb-84cc22d1aada',
                                    value: 'Michael',
                                    choice_id: null,
                                    choice_ids: [],
                                    active: true,
                                    version: 3,
                                    display_type: 'public',
                                    application_form_id: '3435c00d-801e-4d17-b5e3-098203fffce5',
                                    is_completed: true,
                                    created_at: '2020-05-15T10:38:55.551-04:00',
                                    updated_at: '2020-05-15T10:41:52.650-04:00',
                                    is_readonly: false,
                                    question: {
                                        id: 'abdfd092-376f-4c9c-a96e-a8e25a566a04',
                                        code: 'mock_first_name',
                                        text: "Business owner's first name",
                                        error_text: null,
                                        help_text: null,
                                        order: 4,
                                        question_set_id: '75f7b9c5-4297-4552-a3cc-5897875be1b9',
                                        field_type: 'text',
                                        multiple: false,
                                        autocomplete: false,
                                        min_value: null,
                                        max_value: null,
                                        min_date: null,
                                        max_date: null,
                                        pattern: '',
                                        is_hidden: false,
                                        is_active: false,
                                        is_sensitive: false,
                                        required: true,
                                        trackable: false,
                                        created_at: '2020-05-15T10:12:11.690-04:00',
                                        updated_at: '2020-05-15T10:12:31.226-04:00',
                                        question_group_id: '4b914f71-eae3-4e14-bcf1-f45d7407a859',
                                        reference_type: null,
                                        placeholder: 'First name',
                                        deactivated: false,
                                        choices: [],
                                    },
                                },
                                {
                                    id: 'ad3dc2df-3321-46af-936c-82811479dd6f',
                                    value: 'Varrieur',
                                    choice_id: null,
                                    choice_ids: [],
                                    active: true,
                                    version: 3,
                                    display_type: 'public',
                                    application_form_id: '3435c00d-801e-4d17-b5e3-098203fffce5',
                                    is_completed: true,
                                    created_at: '2020-05-15T10:38:55.563-04:00',
                                    updated_at: '2020-05-15T10:41:54.066-04:00',
                                    is_readonly: false,
                                    question: {
                                        id: '6f3dab45-b53c-4f68-8ba5-84616ec999f4',
                                        code: 'mock_last_name',
                                        text: 'Last name',
                                        error_text: null,
                                        help_text: null,
                                        order: 5,
                                        question_set_id: '75f7b9c5-4297-4552-a3cc-5897875be1b9',
                                        field_type: 'text',
                                        multiple: false,
                                        autocomplete: false,
                                        min_value: null,
                                        max_value: null,
                                        min_date: null,
                                        max_date: null,
                                        pattern: '',
                                        is_hidden: false,
                                        is_active: false,
                                        is_sensitive: false,
                                        required: true,
                                        trackable: false,
                                        created_at: '2020-05-15T10:12:11.759-04:00',
                                        updated_at: '2020-05-15T10:12:31.231-04:00',
                                        question_group_id: '4b914f71-eae3-4e14-bcf1-f45d7407a859',
                                        reference_type: null,
                                        placeholder: 'Last name',
                                        deactivated: false,
                                        choices: [],
                                    },
                                },
                                {
                                    id: '4d5b8376-7522-4add-9f2a-db61f1641844',
                                    value: 'mike@boldpenguin.com',
                                    choice_id: null,
                                    choice_ids: [],
                                    active: true,
                                    version: 3,
                                    display_type: 'public',
                                    application_form_id: '3435c00d-801e-4d17-b5e3-098203fffce5',
                                    is_completed: true,
                                    created_at: '2020-05-15T10:38:55.452-04:00',
                                    updated_at: '2020-05-15T10:41:57.673-04:00',
                                    is_readonly: false,
                                    question: {
                                        id: '6783cc50-ec16-42e5-9313-c9c0445b632a',
                                        code: 'mock_email',
                                        text: 'Email address',
                                        error_text: null,
                                        help_text: null,
                                        order: 6,
                                        question_set_id: '75f7b9c5-4297-4552-a3cc-5897875be1b9',
                                        field_type: 'email',
                                        multiple: false,
                                        autocomplete: false,
                                        min_value: null,
                                        max_value: null,
                                        min_date: null,
                                        max_date: null,
                                        pattern: '[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z0-9]{2,}',
                                        is_hidden: false,
                                        is_active: false,
                                        is_sensitive: false,
                                        required: true,
                                        trackable: false,
                                        created_at: '2020-05-15T10:12:11.860-04:00',
                                        updated_at: '2020-05-15T10:12:11.860-04:00',
                                        question_group_id: null,
                                        reference_type: null,
                                        placeholder: 'Email address',
                                        deactivated: false,
                                        choices: [],
                                    },
                                },
                                {
                                    id: '9ac47375-58ea-41f8-bd55-dc883c80bdae',
                                    value: '5085600124',
                                    choice_id: null,
                                    choice_ids: [],
                                    active: true,
                                    version: 3,
                                    display_type: 'public',
                                    application_form_id: '3435c00d-801e-4d17-b5e3-098203fffce5',
                                    is_completed: true,
                                    created_at: '2020-05-15T10:38:55.465-04:00',
                                    updated_at: '2020-05-15T10:41:59.842-04:00',
                                    is_readonly: false,
                                    question: {
                                        id: 'd74470e7-9388-49a5-a93a-4159e87d6389',
                                        code: 'mock_phone',
                                        text: 'Telephone number',
                                        error_text: null,
                                        help_text: null,
                                        order: 7,
                                        question_set_id: '75f7b9c5-4297-4552-a3cc-5897875be1b9',
                                        field_type: 'phone',
                                        multiple: false,
                                        autocomplete: false,
                                        min_value: 10,
                                        max_value: 10,
                                        min_date: null,
                                        max_date: null,
                                        pattern: '^[1-9][0-9]+$',
                                        is_hidden: false,
                                        is_active: false,
                                        is_sensitive: false,
                                        required: true,
                                        trackable: false,
                                        created_at: '2020-05-15T10:12:11.988-04:00',
                                        updated_at: '2020-05-15T10:12:11.988-04:00',
                                        question_group_id: null,
                                        reference_type: null,
                                        placeholder: '(555) 555-5555',
                                        deactivated: false,
                                        choices: [],
                                    },
                                },
                                {
                                    id: 'f4066c80-1201-4544-a7c6-ab81424d076d',
                                    value: '1',
                                    choice_id: null,
                                    choice_ids: [],
                                    active: true,
                                    version: 3,
                                    display_type: 'public',
                                    application_form_id: '3435c00d-801e-4d17-b5e3-098203fffce5',
                                    is_completed: true,
                                    created_at: '2020-05-15T10:38:55.478-04:00',
                                    updated_at: '2020-05-15T10:42:01.439-04:00',
                                    is_readonly: false,
                                    question: {
                                        id: 'dea9f45f-a6ed-4617-af28-882a27f89fd7',
                                        code: 'mock_tcpa_consent',
                                        text: 'I hereby authorize and provide express written consent to the mock Family of Companies and its agents, Bold Penguin Company, and other selected insurance carriers, brokers, and agents on the Bold Penguin Exchange to contact me for sales and marketing purposes using text messages, live operators, automated telephone dialing systems, or prerecorded messages. I understand that I am not required to consent as a condition of purchasing goods or services. I understand that I may revoke this consent at any time.',
                                        error_text: null,
                                        help_text: null,
                                        order: 8,
                                        question_set_id: '75f7b9c5-4297-4552-a3cc-5897875be1b9',
                                        field_type: 'checkbox',
                                        multiple: false,
                                        autocomplete: false,
                                        min_value: null,
                                        max_value: null,
                                        min_date: null,
                                        max_date: null,
                                        pattern: '',
                                        is_hidden: false,
                                        is_active: false,
                                        is_sensitive: false,
                                        required: false,
                                        trackable: false,
                                        created_at: '2020-05-15T10:12:12.075-04:00',
                                        updated_at: '2020-05-15T10:12:12.075-04:00',
                                        question_group_id: null,
                                        reference_type: null,
                                        placeholder: null,
                                        deactivated: false,
                                        choices: [],
                                    },
                                },
                                {
                                    id: 'dbb2b313-97af-45c7-acc5-33c1773c1e3f',
                                    value: 'Ads ads ads ads',
                                    choice_id: null,
                                    choice_ids: [],
                                    active: true,
                                    version: 5,
                                    display_type: 'public',
                                    application_form_id: '3435c00d-801e-4d17-b5e3-098203fffce5',
                                    is_completed: true,
                                    created_at: '2020-05-15T10:38:55.501-04:00',
                                    updated_at: '2020-05-15T10:42:07.161-04:00',
                                    is_readonly: false,
                                    question: {
                                        id: '23c00753-fdd6-4216-9eac-a8ce5c0b4863',
                                        code: 'mock_business_name',
                                        text: 'Business name',
                                        error_text: null,
                                        help_text: null,
                                        order: 9,
                                        question_set_id: '75f7b9c5-4297-4552-a3cc-5897875be1b9',
                                        field_type: 'text',
                                        multiple: false,
                                        autocomplete: false,
                                        min_value: null,
                                        max_value: 80,
                                        min_date: null,
                                        max_date: null,
                                        pattern: '',
                                        is_hidden: false,
                                        is_active: false,
                                        is_sensitive: false,
                                        required: true,
                                        trackable: false,
                                        created_at: '2020-05-15T10:12:12.184-04:00',
                                        updated_at: '2020-05-15T10:12:12.184-04:00',
                                        question_group_id: null,
                                        reference_type: null,
                                        placeholder: 'Business name',
                                        deactivated: false,
                                        choices: [],
                                    },
                                },
                                {
                                    id: '7524794d-8acb-4e12-9274-d2925958dd88',
                                    value: '100 E Broad St',
                                    choice_id: null,
                                    choice_ids: [],
                                    active: true,
                                    version: 4,
                                    display_type: 'public',
                                    application_form_id: '3435c00d-801e-4d17-b5e3-098203fffce5',
                                    is_completed: true,
                                    created_at: '2020-05-15T10:38:55.540-04:00',
                                    updated_at: '2020-05-15T10:42:17.235-04:00',
                                    is_readonly: false,
                                    question: {
                                        id: 'a2a69126-1909-4b6e-977c-97d21b4468b3',
                                        code: 'mock_address_1',
                                        text: 'Physical business address',
                                        error_text: null,
                                        help_text: null,
                                        order: 10,
                                        question_set_id: '75f7b9c5-4297-4552-a3cc-5897875be1b9',
                                        field_type: 'text',
                                        multiple: false,
                                        autocomplete: false,
                                        min_value: null,
                                        max_value: null,
                                        min_date: null,
                                        max_date: null,
                                        pattern: '',
                                        is_hidden: false,
                                        is_active: false,
                                        is_sensitive: false,
                                        required: true,
                                        trackable: false,
                                        created_at: '2020-05-15T10:12:12.272-04:00',
                                        updated_at: '2020-05-15T10:12:31.268-04:00',
                                        question_group_id: 'bc4d6d88-bb0e-4f3c-a43e-9932cfca6e2c',
                                        reference_type: 'street_1',
                                        placeholder: 'Business address',
                                        deactivated: false,
                                        choices: [],
                                    },
                                },
                                {
                                    id: 'a5e9b9a5-9043-4395-8451-f57c9e5e3296',
                                    value: null,
                                    choice_id: null,
                                    choice_ids: [],
                                    active: true,
                                    version: 2,
                                    display_type: 'public',
                                    application_form_id: '3435c00d-801e-4d17-b5e3-098203fffce5',
                                    is_completed: true,
                                    created_at: '2020-05-15T10:38:55.575-04:00',
                                    updated_at: '2020-05-15T10:38:55.575-04:00',
                                    is_readonly: false,
                                    question: {
                                        id: 'c4358cfc-b2b3-48a8-9e40-df6c0711a499',
                                        code: 'mock_address_2',
                                        text: 'Suite / Apt number',
                                        error_text: null,
                                        help_text: null,
                                        order: 11,
                                        question_set_id: '75f7b9c5-4297-4552-a3cc-5897875be1b9',
                                        field_type: 'text',
                                        multiple: false,
                                        autocomplete: false,
                                        min_value: null,
                                        max_value: null,
                                        min_date: null,
                                        max_date: null,
                                        pattern: '',
                                        is_hidden: false,
                                        is_active: false,
                                        is_sensitive: false,
                                        required: false,
                                        trackable: false,
                                        created_at: '2020-05-15T10:12:12.359-04:00',
                                        updated_at: '2020-05-15T10:12:31.273-04:00',
                                        question_group_id: 'bc4d6d88-bb0e-4f3c-a43e-9932cfca6e2c',
                                        reference_type: 'street_2',
                                        placeholder: 'Optional',
                                        deactivated: false,
                                        choices: [],
                                    },
                                },
                            ],
                        },
                    ],
                    active: '75f7b9c5-4297-4552-a3cc-5897875be1b9',
                },
                pendingProcesses: [],
            },
            status: {
                remote: {
                    application: {
                        form: LoadingStates.Loaded,
                    },
                    answers: {
                        state: LoadingStates.Loaded,
                    },
                    questionPools: {
                        state: LoadingStates.Loaded,
                    },
                    questionSets: {
                        state: LoadingStates.Loaded,
                    },
                },
            },
            ViewState: {
                addressValidation: {
                    shouldOverrideValidationTrigger: false,
                    validations: {},
                },
            },
            queues: {
                answers: [],
            },
            config: {
                uri: 'http://test.local',
                env: BpEnvironmentName.Alpha,
                options: { enableUserApplicationGuard: true },
            },
            auth: {
                token: 'test_token',
            },
        };
    });
    describe('render', () => {
        it('renders', async () => {
            const page = await setupPage();
            setupInstance(page);
            await page.waitForChanges();
            const element = page.root.querySelector('bp-sdk-next-button');
            expect(element).toBeTruthy();
            expect(page.root.querySelector('bp-sdk-external-next-button-container')).toBeFalsy();
        });
        it('renders external component if defined', async () => {
            const whenDefinedMock = jest.spyOn(customElements, 'whenDefined').mockResolvedValueOnce({});
            const page = await setupPage();
            setupInstance(page);
            await page.waitForChanges();
            expect(page.root.querySelector('bp-sdk-external-next-button-container')).toBeTruthy();
            whenDefinedMock.mockRestore();
        });
    });
    describe('handleSubscriptions', () => {
        it('subscribes if not subscribed', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.storeUnsubscribe = null;
            instance.handleSubscriptions();
            expect(instance.storeUnsubscribe).not.toBeNull();
        });
        it('resubscribes to mapStateToProps if already has storeUnsubscribe', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            const unsubscribe = jest.fn();
            instance.storeUnsubscribe = unsubscribe;
            instance.handleSubscriptions();
            expect(instance.storeUnsubscribe).not.toEqual(unsubscribe);
        });
    });
    describe('calculateResourcesReady', () => {
        it('should return false if no resources', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            expect(instance.calculateResourcesReady(null)).toBe(false);
        });
        it('should return false if undefined resources', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            expect(instance.calculateResourcesReady(undefined)).toBe(false);
        });
        it('should return false when form is loading', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.isReady = true;
            instance.applicationFormResourceState = LoadingStates.Loading;
            expect(instance.calculateResourcesReady({
                answers: LoadingStates.Loaded,
                applicationForm: LoadingStates.Loading,
                questionPools: LoadingStates.Loaded,
                questionSets: LoadingStates.Loaded,
            })).toBe(false);
        });
        it('should return false when question pool is loading', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.isReady = true;
            instance.questionPoolResourceState = LoadingStates.Loading;
            expect(instance.calculateResourcesReady({
                answers: LoadingStates.Loaded,
                applicationForm: LoadingStates.Loaded,
                questionPools: LoadingStates.Loading,
                questionSets: LoadingStates.Loaded,
            })).toBe(false);
        });
        it('should return false when question sets are loading', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.isReady = true;
            expect(instance.calculateResourcesReady({
                answers: LoadingStates.Loaded,
                applicationForm: LoadingStates.Loaded,
                questionPools: LoadingStates.Loaded,
                questionSets: LoadingStates.Loading,
            })).toBe(false);
        });
        it('should return false when answers are loading', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.isReady = true;
            instance.answersResourceState = LoadingStates.Loading;
            expect(instance.calculateResourcesReady({
                answers: LoadingStates.Loading,
                applicationForm: LoadingStates.Loaded,
                questionPools: LoadingStates.Loaded,
                questionSets: LoadingStates.Loaded,
            })).toBe(false);
        });
        it('should return true', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.isReady = false;
            await page.waitForChanges();
            expect(instance.calculateResourcesReady({
                answers: LoadingStates.Loaded,
                applicationForm: LoadingStates.Loaded,
                questionPools: LoadingStates.Loaded,
                questionSets: LoadingStates.Loaded,
            })).toBe(true);
        });
    });
    describe('updateOnDisableIfIncomplete', () => {
        it('should enabled if not flagged', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.updateOnDisableIfIncomplete(false, { answers: [{ is_completed: false, required: true }] });
            expect(instance.isDisabled).toBeFalsy();
        });
        it('should disable if flagged & required answers are incomplete', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.updateOnDisableIfIncomplete(true, { answers: [{ is_completed: false, required: true }] });
            expect(instance.isDisabled).toBeTruthy();
        });
        it('should disable if flagged & missing active question set', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.updateOnDisableIfIncomplete(true, undefined);
            expect(instance.isDisabled).toBeTruthy();
        });
        it('should enable if flagged & active question set missing answer', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.updateOnDisableIfIncomplete(true, {});
            expect(instance.isDisabled).toBeFalsy();
        });
        it('should enable if flagged & empty answers', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.updateOnDisableIfIncomplete(true, { answers: [] });
            expect(instance.isDisabled).toBeFalsy();
        });
        it('should enable if flagged & non-required answers are incomplete', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.updateOnDisableIfIncomplete(true, { answers: [{ is_completed: false, required: false }] });
            expect(instance.isDisabled).toBeFalsy();
        });
        it('should enable if flagged & required answers are complete', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.updateOnDisableIfIncomplete(true, { answers: [{ is_completed: true }] });
            expect(instance.isDisabled).toBeFalsy();
        });
    });
    describe('CA question set', () => {
        let instance;
        beforeEach(async () => {
            const page = await setupPage();
            instance = setupInstance(page);
        });
        it('should not update if shouldDisableIfIncomplete is false', () => {
            instance.activeQuestionSet = { id: '123' };
            instance.shouldDisableIfIncomplete = false;
            instance.disableIfCAQuestionSet(instance.shouldDisableIfIncomplete, instance.activeQuestionSet);
            expect(instance.caDisabled).toBeFalsy();
        });
        it('should be false if activeQuestion set has no question pools', () => {
            instance.caDisabled = true;
            instance.activeQuestionSet = { id: '123', question_set: { code: 'not vmqs', question_pools: [] } };
            instance.disableIfCAQuestionSet(true, instance.activeQuestionSet);
            expect(instance.caDisabled).toBeFalsy();
        });
        it('should be true if the only answers are the parent_question_id on the activeQuestionSet', () => {
            const activeQuestionSet = {
                id: '123',
                answers: [{ id: '123', question: { id: '456', code: 'mqs_add_vehicle' } }],
                question_set: {
                    code: 'vehicle_pool_master_question_set',
                    question_pools: [
                        { code: 'vehicles', parent_question_id: '456' },
                        { code: 'extra pool that is not counted', parent_question_id: '789798' },
                    ],
                },
            };
            instance.disableIfCAQuestionSet(true, activeQuestionSet);
            expect(instance.caDisabled).toBeTruthy();
        });
        it('should be true if only answers are the parent_question_id on driver_pool_master_question_set', () => {
            const activeQuestionSet = {
                id: '123',
                answers: [{ id: '123', question: { id: '456', code: 'mqs_add_vehicle' } }],
                question_set: {
                    code: 'driver_pool_master_question_set',
                    question_pools: [
                        { code: 'vehicles', parent_question_id: '456' },
                        { code: 'extra pool that is not counted', parent_question_id: '789798' },
                    ],
                },
            };
            instance.disableIfCAQuestionSet(true, activeQuestionSet);
            expect(instance.caDisabled).toBeTruthy();
        });
        it('should be false if there are other answers on the question set', () => {
            const activeQuestionSet = {
                id: '123',
                answers: [
                    { id: '456', question: { id: '456', code: 'mqs_add_vehicle' } },
                    { id: '78979', question: { id: '646848348' } },
                ],
                question_set: { code: 'vehicle_pool_master_question_set', question_pools: [{ parent_question_pool_id: '456' }] },
            };
            instance.disableIfCAQuestionSet(true, activeQuestionSet);
            expect(instance.caDisabled).toBeFalsy();
        });
    });
    describe('handleNavigateNext', () => {
        beforeEach(() => {
            jest.useFakeTimers({ legacyFakeTimers: true });
        });
        afterEach(() => {
            jest.useRealTimers();
        });
        it('should make expected calls', async () => {
            const page = await setupPage();
            const instance = setupNavigateNextInstance(page);
            instance.answersResourceState = LoadingStates.Loaded;
            instance.questionSetResourceState = LoadingStates.Loaded;
            instance.addressValidationStatuses = {};
            jest.spyOn(instance, 'removeActiveAnswerId').mockImplementation(jest.fn());
            jest.spyOn(instance, 'saveQuestionSet').mockImplementation(jest.fn());
            jest.spyOn(instance, 'switchActiveQuestionSet').mockImplementation(jest.fn());
            jest.spyOn(instance, 'updateErrors').mockImplementation(jest.fn());
            jest.spyOn(instance, 'pushAnswer').mockImplementation(jest.fn());
            const set = {
                answers: [],
                question_set_id: 'abc',
                question_set: {
                    code: 'xyz',
                },
            };
            instance.activeQuestionSet = set;
            instance.isLocked = false;
            const bpAnalyticsTrackSpy = jest.spyOn(instance.bpAnalyticsTrack, 'emit');
            await page.waitForChanges();
            instance.handleNavigateNext();
            expect(instance.saveQuestionSet).toHaveBeenCalledTimes(1);
            expect(instance.saveQuestionSet).toHaveBeenCalledWith({
                config: instance.config,
                appFormQuestionSet: set,
                navigationDirection: 'forward',
            });
            expect(bpAnalyticsTrackSpy).toHaveBeenCalledTimes(1);
            expect(bpAnalyticsTrackSpy).toHaveBeenCalledWith({
                eventName: AnalyticsTrackingEventName.QuestionSetSaved,
                eventPayload: { applicationFormQuestionSetId: set.id, questionSetId: set.question_set_id, questionSetCode: set.question_set.code },
            });
            expect(instance.updateErrors).toBeCalledTimes(0);
            expect(instance.switchActiveQuestionSet).toBeCalledTimes(0);
        });
        it('should make expected calls', async () => {
            const page = await setupPage();
            const instance = setupNavigateNextInstance(page);
            instance.answersResourceState = LoadingStates.Loaded;
            instance.questionSetResourceState = LoadingStates.Loaded;
            instance.addressValidationStatuses = {};
            jest.spyOn(instance, 'removeActiveAnswerId').mockImplementation(jest.fn());
            jest.spyOn(instance, 'saveQuestionSet').mockImplementation(jest.fn());
            jest.spyOn(instance, 'updateErrors').mockImplementation(jest.fn());
            jest.spyOn(instance, 'switchActiveQuestionSet').mockImplementation(jest.fn());
            jest.spyOn(instance, 'pushAnswer').mockImplementation(jest.fn());
            const set = {
                answers: [],
            };
            instance.activeQuestionSet = set;
            instance.isLocked = true;
            await page.waitForChanges();
            instance.handleNavigateNext();
            expect(instance.saveQuestionSet).toHaveBeenCalledTimes(0);
            expect(instance.updateErrors).toBeCalledTimes(0);
            expect(instance.switchActiveQuestionSet).toHaveBeenCalledTimes(1);
        });
        it('should ignore expected answers', async () => {
            const page = await setupPage();
            const instance = setupNavigateNextInstance(page);
            instance.answersResourceState = LoadingStates.Loaded;
            instance.questionSetResourceState = LoadingStates.Loaded;
            instance.addressValidationStatuses = {};
            jest.spyOn(instance, 'removeActiveAnswerId').mockImplementation(jest.fn());
            jest.spyOn(instance, 'saveQuestionSet').mockImplementation(jest.fn());
            jest.spyOn(instance, 'updateErrors').mockImplementation(jest.fn());
            jest.spyOn(instance, 'pushAnswer').mockImplementation(jest.fn());
            const set = {
                answers: [
                    {
                        active: false,
                    },
                    {
                        active: true,
                        is_completed: true,
                    },
                ],
                question_set: {
                    code: 'abc',
                },
            };
            instance.activeQuestionSet = set;
            instance.isLocked = false;
            const element = {
                scrollIntoView: jest.fn(),
                getAttributeNode: () => null,
            };
            mockDocument();
            jest.spyOn(document, 'querySelector').mockReturnValue(element);
            await page.waitForChanges();
            instance.handleNavigateNext();
            jest.advanceTimersByTime(100);
            expect(instance.saveQuestionSet).toHaveBeenCalledTimes(1);
            expect(instance.saveQuestionSet).toHaveBeenCalledWith({
                config: instance.config,
                appFormQuestionSet: set,
                navigationDirection: 'forward',
                parentQuestionSet: undefined,
            });
            expect(instance.updateErrors).toBeCalledTimes(0);
            expect(element.scrollIntoView).toHaveBeenCalledTimes(0);
        });
        it('handle errors as expected', async () => {
            const page = await setupPage();
            const instance = setupNavigateNextInstance(page);
            mockDocument();
            instance.answersResourceState = LoadingStates.Loaded;
            instance.questionSetResourceState = LoadingStates.Loaded;
            instance.addressValidationStatuses = {};
            jest.spyOn(instance, 'saveQuestionSet').mockImplementation(jest.fn());
            jest.spyOn(instance, 'updateErrors').mockImplementation(jest.fn());
            jest.spyOn(instance, 'pushAnswer').mockImplementation(jest.fn());
            const set = {
                answers: [
                    {
                        active: true,
                        is_completed: false,
                        required: true,
                        value: null,
                        question: {
                            field_type: 'text',
                            required: true,
                        },
                    },
                ],
            };
            instance.activeQuestionSet = set;
            instance.isLocked = false;
            jest.spyOn(document, 'querySelectorAll').mockImplementation(() => ['any', 'el']);
            jest.spyOn(document, 'querySelector').mockReturnValue(null);
            const bpAnalyticsTrackSpy = jest.spyOn(instance.bpAnalyticsTrack, 'emit');
            await page.waitForChanges();
            instance.handleNavigateNext();
            jest.advanceTimersByTime(1000);
            expect(instance.updateErrors).toBeCalledTimes(1);
            expect(instance.updateErrors).toHaveBeenCalledWith({
                answer: set.answers[0],
                errors: ['required'],
            });
            expect(instance.saveQuestionSet).toHaveBeenCalledTimes(0);
            expect(bpAnalyticsTrackSpy).toHaveBeenCalledTimes(0);
            expect(focusErrors).toHaveBeenCalled();
        });
        it('scrolls to first error if present', async () => {
            const page = await setupPage();
            const instance = setupNavigateNextInstance(page);
            mockDocument();
            instance.answersResourceState = LoadingStates.Loaded;
            instance.questionSetResourceState = LoadingStates.Loaded;
            instance.addressValidationStatuses = {};
            jest.spyOn(instance, 'saveQuestionSet').mockImplementation(jest.fn());
            jest.spyOn(instance, 'updateErrors').mockImplementation(jest.fn());
            jest.spyOn(instance, 'pushAnswer').mockImplementation(jest.fn());
            const set = {
                answers: [
                    {
                        active: true,
                        is_completed: false,
                        required: true,
                        value: null,
                        question: {
                            field_type: 'text',
                            required: true,
                        },
                    },
                ],
            };
            instance.activeQuestionSet = set;
            instance.isLocked = false;
            const element = {
                parentElement: { scrollIntoView: jest.fn(), getAttributeNode: () => null },
            };
            mockDocument();
            jest.spyOn(document, 'querySelectorAll').mockImplementation(() => ['any', 'el']);
            jest.spyOn(document, 'querySelector').mockImplementation(() => element);
            await page.waitForChanges();
            instance.handleNavigateNext();
            jest.advanceTimersByTime(1000);
            expect(instance.saveQuestionSet).toHaveBeenCalledTimes(0);
            expect(instance.updateErrors).toBeCalledTimes(1);
            expect(instance.updateErrors).toHaveBeenCalledWith({
                answer: set.answers[0],
                errors: ['required'],
            });
            expect(focusErrors).toHaveBeenCalled();
        });
        it('should call switchActiveQuestion set if application is locked', async () => {
            const page = await setupPage();
            const instance = setupNavigateNextInstance(page);
            instance.locked = true;
            instance.addressValidationStatuses = {};
            jest.spyOn(instance, 'saveQuestionSet').mockImplementation(jest.fn());
            jest.spyOn(instance, 'switchActiveQuestionSet').mockImplementation(jest.fn());
            await page.waitForChanges();
            instance.handleNavigateNext();
            expect(instance.saveQuestionSet).not.toHaveBeenCalled();
            expect(instance.switchActiveQuestionSet).toHaveBeenCalled();
        });
        it('should call switchActiveQuestion set if question set is completed', async () => {
            const page = await setupPage();
            const instance = setupNavigateNextInstance(page);
            instance.locked = false;
            instance.activeQuestionSet.is_completed = true;
            instance.addressValidationStatuses = {};
            jest.spyOn(instance, 'saveQuestionSet').mockImplementation(jest.fn());
            jest.spyOn(instance, 'switchActiveQuestionSet').mockImplementation(jest.fn());
            await page.waitForChanges();
            instance.handleNavigateNext();
            expect(instance.saveQuestionSet).not.toHaveBeenCalled();
            expect(instance.switchActiveQuestionSet).toHaveBeenCalled();
        });
        it('should not call saveQuestionSet if active question set is a child and there are more child question sets', async () => {
            const parentQuestionSet = {
                answers: [{ is_completed: true }, { is_completed: false }],
                is_completed: false,
                question_set_id: 'parent question set id',
                id: 'parentQuestionSet id',
            };
            const activeQuestionSet = {
                answers: [{ is_completed: true }],
                parentQuestionSetId: 'parentQuestionSet id',
                is_completed: false,
                question_set_id: 'active question set id',
                question_set: {
                    code: 'active question set code',
                },
            };
            const secondaryChildQS = {
                answers: [{ is_completed: false }],
                parentQuestionSetId: 'parentQuestionSet id',
                is_completed: false,
                question_set_id: 'secondary question set id',
                question_set: {
                    code: 'secondary question set code',
                },
            };
            const testState = {
                active: activeQuestionSet.question_set_id,
                list: [activeQuestionSet, secondaryChildQS],
                parentQuestionSets: [parentQuestionSet],
                pendingActiveAnswerUpdate: undefined,
            };
            const page = await setupPage();
            const instance = setupNavigateNextInstance(page);
            instance.activeQuestionSet = activeQuestionSet;
            instance.questionSetState = testState;
            instance.addressValidationStatuses = {};
            jest.spyOn(instance, 'saveQuestionSet').mockImplementation(jest.fn());
            jest.spyOn(instance, 'removeActiveAnswerId').mockImplementation(jest.fn());
            jest.spyOn(instance, 'switchActiveQuestionSet').mockImplementation(jest.fn());
            jest.spyOn(instance, 'getEligibilityResults').mockImplementation(jest.fn());
            jest.spyOn(instance, 'pushAnswer').mockImplementation(jest.fn());
            getParentAnchorAnswer.mockReturnValueOnce({});
            calculateParentAnchorValue.mockReturnValue(undefined);
            areAnswersValid.mockReturnValueOnce(true);
            areAnswersValid.mockReturnValueOnce(false);
            await page.waitForChanges();
            instance.handleNavigateNext();
            expect(instance.saveQuestionSet).not.toHaveBeenCalled();
            expect(instance.getEligibilityResults).toHaveBeenCalled();
            expect(instance.switchActiveQuestionSet).toHaveBeenCalledWith('forward');
            areAnswersValid.mockReturnValue(true);
            instance.handleNavigateNext();
            expect(instance.saveQuestionSet).toHaveBeenCalledWith({
                config: instance.config,
                appFormQuestionSet: activeQuestionSet,
                navigationDirection: 'forward',
                parentQuestionSet: parentQuestionSet,
            });
        });
        it('should not make save calls if button is disabled but should validate form', async () => {
            const page = await setupPage();
            const instance = setupNavigateNextInstance(page);
            jest.spyOn(instance, 'removeActiveAnswerId').mockImplementation(jest.fn());
            instance.answersResourceState = LoadingStates.Loaded;
            instance.questionSetResourceState = LoadingStates.Loaded;
            instance.addressValidationStatuses = {};
            jest.spyOn(instance, 'saveQuestionSet').mockImplementation(jest.fn());
            jest.spyOn(instance, 'switchActiveQuestionSet').mockImplementation(jest.fn());
            jest.spyOn(instance, 'updateErrors').mockImplementation(jest.fn());
            jest.spyOn(instance, 'pushAnswer').mockImplementation(jest.fn());
            const set = {
                answers: [
                    {
                        active: true,
                        is_completed: false,
                        required: true,
                        value: null,
                        question: {
                            field_type: 'text',
                            required: true,
                        },
                    },
                ],
            };
            instance.activeQuestionSet = set;
            instance.isLocked = false;
            instance.buttonDisabled = true;
            const bpAnalyticsTrackSpy = jest.spyOn(instance.bpAnalyticsTrack, 'emit');
            await page.waitForChanges();
            instance.handleNavigateNext();
            expect(instance.saveQuestionSet).not.toHaveBeenCalled();
            expect(bpAnalyticsTrackSpy).not.toHaveBeenCalled();
            expect(instance.updateErrors).toBeCalledTimes(1);
            expect(instance.switchActiveQuestionSet).not.toHaveBeenCalled();
        });
        it('should not switch active question set when shouldCallSaveQuestionSet is false and button is disabled', async () => {
            const page = await setupPage();
            const instance = setupNavigateNextInstance(page);
            instance.isLocked = true;
            instance.buttonDisabled = true;
            instance.addressValidationStatuses = {};
            jest.spyOn(instance, 'saveQuestionSet').mockImplementation(jest.fn());
            jest.spyOn(instance, 'updateErrors').mockImplementation(jest.fn());
            jest.spyOn(instance, 'switchActiveQuestionSet').mockImplementation(jest.fn());
            await page.waitForChanges();
            instance.handleNavigateNext();
            expect(instance.saveQuestionSet).not.toHaveBeenCalled();
            expect(instance.updateErrors).not.toHaveBeenCalled();
            expect(instance.switchActiveQuestionSet).not.toHaveBeenCalled();
        });
        it('should set validation status to ready to validate and not proceed next when an address is present that needs validated', async () => {
            const page = await setupPage();
            const instance = setupNavigateNextInstance(page);
            jest.spyOn(instance, 'setAddressValidationStatus');
            jest.spyOn(instance, 'switchActiveQuestionSet').mockImplementation(jest.fn());
            instance.addressValidationStatuses = { 1234567890: ValidationStatus.REQUIRED };
            instance.addressIdsToBeValidated = ['1234567890'];
            instance.activeQuestionSet = { answers: [{ answer_pool_id: '1234567890' }] };
            await page.waitForChanges();
            instance.handleNavigateNext();
            expect(instance.setAddressValidationStatus).toHaveBeenCalledWith({
                validationStatus: ValidationStatus.READY_TO_VALIDATE,
                addressValidationId: '1234567890',
            });
            expect(instance.switchActiveQuestionSet).not.toHaveBeenCalled();
        });
        it('should proceed next when address validation is present but all addresses are completed', async () => {
            const page = await setupPage();
            const instance = setupNavigateNextInstance(page);
            jest.spyOn(instance, 'setAddressValidationStatus');
            jest.spyOn(instance, 'switchActiveQuestionSet').mockImplementation(jest.fn());
            instance.addressValidationStatuses = { 1234567890: ValidationStatus.COMPLETED };
            instance.addressIdsToBeValidated = [];
            instance.activeQuestionSet = { answers: [{ answer_pool_id: '1234567890' }] };
            instance.isLocked = true;
            await page.waitForChanges();
            instance.handleNavigateNext();
            expect(instance.setAddressValidationStatus).not.toHaveBeenCalled();
            expect(instance.switchActiveQuestionSet).toHaveBeenCalled();
        });
    });
    describe('canSave', () => {
        let instance;
        const activeQsPendingProcess = { question_set_id: 'qs-456' };
        const otherQsPendingProcess = { question_set_id: 'qs-789' };
        beforeEach(async () => {
            const page = await setupPage();
            instance = setupInstance(page);
            instance.activeQuestionSet = { id: 'afqs-123', question_set_id: 'qs-456', question_set: { id: 'qs-456' } };
        });
        describe('onQueueChange', () => {
            it('should be true if there is nothing in the queue and no pending processes', () => {
                instance.isActiveQuestionSetPendingProcess = false;
                instance.onQueueChange({});
                expect(instance.canSave).toBeTruthy();
            });
            it('should be false if there is something in the queue and no pending processes', () => {
                instance.isActiveQuestionSetPendingProcess = false;
                instance.onQueueChange([{}]);
                expect(instance.canSave).toBeFalsy();
            });
            it('should be false if there is nothing in the queue but there are pending processes on active QS', () => {
                instance.isActiveQuestionSetPendingProcess = true;
                instance.onQueueChange();
                expect(instance.canSave).toBeFalsy();
            });
            it('should be true if there is nothing in the queue and there are no pending processes on active QS', () => {
                instance.isActiveQuestionSetPendingProcess = false;
                instance.onQueueChange();
                expect(instance.canSave).toBeTruthy();
            });
        });
        describe('onIsActiveQuestionSetPendingProcess', () => {
            it('should set canSave to true if there are no pending processes for the active question set', () => {
                instance.onIsActiveQuestionSetPendingProcess(false);
                expect(instance.canSave).toEqual(true);
            });
            it('should set canSave to false if there are pending processes for the active question set', () => {
                instance.onIsActiveQuestionSetPendingProcess(true);
                expect(instance.canSave).toEqual(false);
            });
        });
    });
});
