import { newSpecPage } from "@stencil/core/testing";
jest.mock('lodash/debounce');
import { BpSdkSelectInput } from "./bp-sdk-select-input";
const setupPage = async () => {
    const page = await newSpecPage({
        html: '<bp-sdk-select-input></bp-sdk-select-input>',
        components: [BpSdkSelectInput],
    });
    return page;
};
const setupInstance = (page) => {
    const instance = page.rootInstance;
    return instance;
};
describe('bp-sdk-select-input', () => {
    beforeEach(() => {
        global['FocusEvent'] = Event;
        jest.useFakeTimers({ legacyFakeTimers: true });
    });
    afterEach(() => {
        global['FocusEvent'] = undefined;
        jest.clearAllTimers();
    });
    afterAll(() => {
        jest.useRealTimers();
    });
    describe('rendering', () => {
        it('vanilla', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.choices = [
                {
                    id: '1',
                    value: '1',
                },
                {
                    id: '2',
                    value: '2',
                },
            ];
            instance.labelId = 'aria';
            instance.labelledBy = 'label';
            await page.waitForChanges();
            expect(page.body.querySelectorAll('bp-sdk-errors-container').length).toEqual(0);
            expect(page.body.querySelectorAll('.bp-sdk-select__list-item').length).toEqual(2);
            expect(page.body.querySelectorAll('span.bp-sdk-select__list-item-content').length).toEqual(2);
            expect(page.body.querySelectorAll('input.bp-sdk-select__list-item-content').length).toEqual(0);
            expect(page.body.querySelectorAll('span.bp-sdk-select__list-item-text').length).toEqual(2);
            const input = page.body.querySelector('button');
            expect(input.getAttribute('aria-labelledby')).toEqual('label aria');
        });
        it('multiple', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.choices = [
                {
                    id: '1',
                    value: '1',
                },
                {
                    id: '2',
                    value: '2',
                },
            ];
            instance.multiple = true;
            await page.waitForChanges();
            expect(page.body.querySelectorAll('bp-sdk-errors-container').length).toEqual(0);
            expect(page.body.querySelectorAll('.bp-sdk-select__list-item').length).toEqual(2);
            expect(page.body.querySelectorAll('span.bp-sdk-select__list-item-content').length).toEqual(0);
            expect(page.body.querySelectorAll('input.bp-sdk-select__list-item-content').length).toEqual(2);
            expect(page.body.querySelectorAll('input.bp-sdk-select__list-item-input').length).toEqual(2);
        });
        it('renders errors', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.errors = ['errors'];
            instance.touched = true;
            instance.pristine = false;
            await page.waitForChanges();
            expect(page.body.querySelectorAll('bp-sdk-errors-container').length).toEqual(1);
        });
        it('renders errors if is completed', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.errors = ['errors'];
            instance.touched = true;
            instance.pristine = false;
            instance.isCompleted = true;
            await page.waitForChanges();
            expect(page.body.querySelectorAll('bp-sdk-errors-container').length).toEqual(1);
        });
        it('renders error text', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.errorText = 'errors';
            instance.touched = true;
            instance.pristine = false;
            await page.waitForChanges();
            expect(page.body.querySelectorAll('bp-sdk-errors-container').length).toEqual(1);
        });
        it('hides error text if is completed', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.errorText = 'errors';
            instance.touched = true;
            instance.pristine = false;
            instance.isCompleted = true;
            await page.waitForChanges();
            expect(page.body.querySelectorAll('bp-sdk-errors-container').length).toEqual(0);
        });
        it('does render null errors', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.errors = null;
            instance.touched = true;
            instance.pristine = false;
            await page.waitForChanges();
            expect(page.body.querySelectorAll('bp-sdk-errors-container').length).toEqual(0);
        });
        it('renders external component if defined', async () => {
            const whenDefinedMock = jest.spyOn(customElements, 'whenDefined').mockResolvedValueOnce({});
            const page = await setupPage();
            await page.waitForChanges();
            const element = page.root.querySelector('div');
            expect(element).toBeFalsy();
            whenDefinedMock.mockRestore();
        });
        describe('when the component is marked as read only', () => {
            const choices = [
                {
                    id: '1',
                    value: 'one',
                },
                {
                    id: '2',
                    value: 'two',
                },
            ];
            let page;
            let instance;
            beforeEach(async () => {
                page = await setupPage();
                instance = setupInstance(page);
                instance.isReadOnly = true;
                instance.choices = choices;
                instance.choiceIds = choices.map((c) => c.id);
                await page.waitForChanges();
            });
            it('should render a read only value', () => {
                const element = page.body.querySelector('.read-only-value');
                const expectedText = choices.map((c) => c.value).join(', ');
                expect(element.textContent).toEqual(expectedText);
            });
            it('should not render selectable options', () => {
                expect(page.body.querySelectorAll('ul').length).toEqual(0);
            });
        });
    });
    describe('onCodeChange', () => {
        it('should set expected id', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.onCodeChange('newCode');
            expect(instance.selectButtonId).toEqual('select-btn-newCode');
        });
    });
    describe('onKeydown', () => {
        describe('tab key', () => {
            describe('list hidden', () => {
                it('should make expected calls', async () => {
                    const page = await setupPage();
                    const instance = setupInstance(page);
                    jest.spyOn(instance, 'handleKeyEvent').mockImplementation(() => { });
                    const event = new KeyboardEvent('keydown', {
                        key: 'Tab',
                    });
                    jest.spyOn(event, 'preventDefault').mockImplementation(() => { });
                    instance.onKeydown(event);
                    expect(event.preventDefault).toHaveBeenCalledTimes(0);
                    expect(instance.handleKeyEvent).toHaveBeenCalledTimes(0);
                });
            });
            describe('list shown', () => {
                it('should make expected calls', async () => {
                    const page = await setupPage();
                    const instance = setupInstance(page);
                    instance.showSelectList = true;
                    jest.spyOn(instance, 'handleKeyEvent').mockImplementation(() => { });
                    const event = new KeyboardEvent('keydown', {
                        key: 'Tab',
                    });
                    jest.spyOn(event, 'preventDefault').mockImplementation(() => { });
                    instance.onKeydown(event);
                    expect(event.preventDefault).toHaveBeenCalledTimes(1);
                    expect(instance.handleKeyEvent).toHaveBeenCalledTimes(1);
                    expect(instance.handleKeyEvent).toHaveBeenCalledWith('Tab');
                });
            });
        });
        it('shift key should be ignored', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.showSelectList = true;
            jest.spyOn(instance, 'handleKeyEvent').mockImplementation(() => { });
            const event = new KeyboardEvent('keydown', {
                key: 'Shift',
            });
            jest.spyOn(event, 'preventDefault').mockImplementation(() => { });
            instance.onKeydown(event);
            expect(event.preventDefault).toHaveBeenCalledTimes(0);
            expect(instance.handleKeyEvent).toHaveBeenCalledTimes(0);
        });
        it('otherwise makes expected calls', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.showSelectList = true;
            jest.spyOn(instance, 'handleKeyEvent').mockImplementation(() => { });
            const event = new KeyboardEvent('keydown', {
                key: 'A',
            });
            jest.spyOn(event, 'preventDefault').mockImplementation(() => { });
            instance.onKeydown(event);
            expect(event.preventDefault).toHaveBeenCalledTimes(1);
            expect(instance.handleKeyEvent).toHaveBeenCalledTimes(1);
            expect(instance.handleKeyEvent).toHaveBeenCalledWith('A');
        });
    });
    describe('onChoiceIdChange', () => {
        it('should make expected calls', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.choiceId = 'some choice';
            instance.choiceIds = ['a', 'collection', 'of', 'choices'];
            jest.spyOn(instance, 'updateTextDisplayed').mockImplementation(() => { });
            instance.onChoiceIdChange(instance.choiceId);
            expect(instance.choice).toEqual([instance.choiceId]);
            expect(instance.updateTextDisplayed).toHaveBeenCalledTimes(1);
            expect(instance.updateTextDisplayed).toHaveBeenCalledWith(instance.choiceId);
        });
        it('should be called when choice changes', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            await page.waitForChanges();
            let choice = 'some choice';
            jest.spyOn(instance, 'onChoiceIdChange');
            jest.spyOn(instance, 'updateTextDisplayed').mockImplementation(() => { });
            page.root.setAttribute('choice_id', choice);
            await page.waitForChanges();
            expect(instance.choice).toEqual([instance.choiceId]);
            expect(instance.updateTextDisplayed).toHaveBeenCalledWith(instance.choiceId);
            choice = 'some new choice';
            page.root.setAttribute('choice_id', choice);
            await page.waitForChanges();
            expect(instance.choice).toEqual([instance.choiceId]);
            expect(instance.updateTextDisplayed).toHaveBeenCalledWith(instance.choiceId);
        });
    });
    describe('onChoiceIdsChange', () => {
        it('should make expected calls', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.choiceId = undefined;
            instance.choiceIds = ['a', 'collection', 'of', 'choices'];
            jest.spyOn(instance, 'updateTextDisplayed').mockImplementation(() => { });
            instance.onChoiceIdsChange(instance.choiceIds, []);
            expect(instance.choice).toEqual(instance.choiceIds);
            expect(instance.updateTextDisplayed).toHaveBeenCalledTimes(1);
            expect(instance.updateTextDisplayed).toHaveBeenCalledWith(instance.choice);
        });
        it('should be called when choice changes', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            await page.waitForChanges();
            jest.spyOn(instance, 'onChoiceIdsChange');
            jest.spyOn(instance, 'updateTextDisplayed').mockImplementation(() => { });
            instance.choiceId = null;
            instance.choiceIds = ['many', 'choices'];
            await page.waitForChanges();
            expect(instance.choice).toEqual(instance.choiceIds);
            expect(instance.updateTextDisplayed).toHaveBeenCalledWith(instance.choiceIds);
        });
    });
    describe('componentWillLoad', () => {
        it('should make expected calls', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            jest.spyOn(instance, 'onChoiceIdChange').mockImplementation(() => { });
            jest.spyOn(instance, 'onChoiceIdsChange').mockImplementation(() => { });
            instance.componentWillLoad();
            expect(instance.onChoiceIdChange).toHaveBeenCalledTimes(1);
            expect(instance.onChoiceIdsChange).toHaveBeenCalledTimes(1);
        });
    });
    describe('onChange', () => {
        it('should make expected calls', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            jest.spyOn(instance, 'updateTextDisplayed').mockImplementation(() => { });
            const event = {
                target: {
                    value: 'some value',
                },
                preventDefault: jest.fn(),
            };
            instance.onChange(event);
            expect(instance.updateTextDisplayed).toHaveBeenCalledTimes(1);
            expect(instance.updateTextDisplayed).toHaveBeenCalledWith(event.target.value);
            expect(event.preventDefault).toHaveBeenCalledTimes(1);
        });
    });
    describe('focusOption', () => {
        it('should make expected calls', async () => {
            const page = await setupPage();
            const focusSpy = jest.fn();
            const instance = setupInstance(page);
            jest.spyOn(instance.el, 'querySelector').mockReturnValue({
                children: [
                    {
                        focus: focusSpy,
                    },
                ],
            });
            jest.spyOn(instance, 'getSelectableIndex').mockReturnValue(0);
            instance.focusOption(0);
            jest.runAllTimers();
            expect(instance.getSelectableIndex).toHaveBeenCalledTimes(1);
            expect(instance.getSelectableIndex).toHaveBeenCalledWith(0);
            expect(focusSpy).toHaveBeenCalledTimes(1);
        });
    });
    describe('selectFocus', () => {
        describe('showSelectList is true', () => {
            it('should make expected calls', async () => {
                const page = await setupPage();
                const instance = setupInstance(page);
                const event = new MouseEvent('click');
                jest.spyOn(event, 'preventDefault').mockImplementation(() => { });
                jest.spyOn(instance, 'focusElement').mockImplementation(() => { });
                instance.showSelectList = true;
                instance.selectFocus(event);
                expect(event.preventDefault).toHaveBeenCalledTimes(1);
                expect(instance.focusElement).toHaveBeenCalledTimes(0);
                expect(instance.showSelectList).toBeFalsy();
            });
        });
        describe('showSelectList is false', () => {
            it('should make expected calls', async () => {
                const page = await setupPage();
                const instance = setupInstance(page);
                const event = new MouseEvent('click');
                jest.spyOn(event, 'preventDefault').mockImplementation(() => { });
                jest.spyOn(instance, 'focusElement').mockImplementation(() => { });
                instance.selectFocus(event);
                expect(event.preventDefault).toHaveBeenCalledTimes(1);
                expect(instance.focusElement).toHaveBeenCalledTimes(1);
            });
        });
    });
    describe('focusElement', () => {
        describe('is single', () => {
            describe('has a choice', () => {
                it('should make expected calls', async () => {
                    const page = await setupPage();
                    const instance = setupInstance(page);
                    instance.choice = ['1'];
                    instance.choices = [
                        { id: '0', value: '0' },
                        { id: '1', value: '1' },
                    ];
                    instance.focusOption = jest.fn();
                    await page.waitForChanges();
                    instance.focusElement();
                    expect(instance.showSelectList).toBeTruthy();
                    expect(instance.focusOption).toHaveBeenCalledWith(1);
                    expect(instance.focusOption).toHaveBeenCalledTimes(1);
                });
            });
            describe('no choice', () => {
                it('should make expected calls', async () => {
                    const page = await setupPage();
                    const instance = setupInstance(page);
                    instance.multiple = false;
                    instance.choice = [];
                    instance.choices = [
                        { id: 1, value: 1 },
                        { id: 2, value: 2 },
                    ];
                    await page.waitForChanges();
                    // jest.spyOn(instance, 'focusOption');
                    instance.focusElement();
                    expect(instance.showSelectList).toBeTruthy();
                    // expect(instance.focusOption).toHaveBeenCalledWith(0);
                    // expect(instance.focusOption).toHaveBeenCalledTimes(1);
                });
            });
        });
        describe('is multiple', () => {
            it('should make expected calls', async () => {
                const page = await setupPage();
                const instance = setupInstance(page);
                instance.multiple = true;
                jest.spyOn(instance, 'focusOption').mockImplementation(() => { });
                instance.focusElement();
                expect(instance.showSelectList).toBeTruthy();
                expect(instance.focusOption).toHaveBeenCalledWith(0);
                expect(instance.focusOption).toHaveBeenCalledTimes(1);
            });
        });
    });
    describe('choiceText', () => {
        describe('use alias', () => {
            describe('has alias', () => {
                it('should return expected value', async () => {
                    const page = await setupPage();
                    const instance = setupInstance(page);
                    instance.useAlias = true;
                    expect(instance.choiceText({
                        alias: 'bob',
                    })).toEqual('bob');
                });
            });
            describe('no alias', () => {
                it('should return expected value', async () => {
                    const page = await setupPage();
                    const instance = setupInstance(page);
                    instance.useAlias = true;
                    expect(instance.choiceText({
                        value: 'some value',
                    })).toBe('some value');
                });
            });
        });
        describe("don't use alias", () => {
            describe('has alias', () => {
                it('should return expected value', async () => {
                    const page = await setupPage();
                    const instance = setupInstance(page);
                    expect(instance.choiceText({
                        alias: 'bob',
                        value: 'some value',
                    })).toBe('some value');
                });
            });
            describe('no alias', () => {
                it('should return expected value', async () => {
                    const page = await setupPage();
                    const instance = setupInstance(page);
                    instance.useAlias = true;
                    expect(instance.choiceText({
                        value: 'some value',
                    })).toBe('some value');
                });
            });
        });
    });
    describe('delayedClickSelectItem', () => {
        it('multiple takes precedence', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.multiple = true;
            jest.spyOn(instance, 'updateTextDisplayed').mockImplementation(() => { });
            jest.spyOn(instance, 'getControlValue').mockReturnValue('3');
            jest.spyOn(instance, 'clickSelectButton').mockImplementation(() => { });
            instance.delayedClickSelectItem('0');
            jest.runAllTimers();
            expect(instance.choice).toEqual(['3']);
            expect(instance.updateTextDisplayed).toHaveBeenCalledWith('3');
            expect(instance.updateTextDisplayed).toHaveBeenCalledTimes(1);
            expect(instance.clickSelectButton).toHaveBeenCalledTimes(0);
            expect(instance.getControlValue).toHaveBeenCalledTimes(1);
        });
        it('choice id is used otherwise', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            jest.spyOn(instance, 'updateTextDisplayed').mockImplementation(() => { });
            jest.spyOn(instance, 'getControlValue').mockReturnValue('0');
            jest.spyOn(instance, 'clickSelectButton').mockImplementation(() => { });
            instance.delayedClickSelectItem('0');
            jest.runAllTimers();
            expect(instance.choice).toEqual(['0']);
            expect(instance.updateTextDisplayed).toHaveBeenCalledWith('0');
            expect(instance.updateTextDisplayed).toHaveBeenCalledTimes(1);
            expect(instance.clickSelectButton).toHaveBeenCalledTimes(1);
            expect(instance.getControlValue).toHaveBeenCalledTimes(0);
        });
        it('choice on instance is fallback', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.choice = ['5'];
            jest.spyOn(instance, 'updateTextDisplayed').mockImplementation(() => { });
            jest.spyOn(instance, 'getControlValue').mockReturnValue('0');
            jest.spyOn(instance, 'clickSelectButton').mockImplementation(() => { });
            instance.delayedClickSelectItem(null);
            jest.runAllTimers();
            expect(instance.choice).toEqual(['5']);
            expect(instance.updateTextDisplayed).toHaveBeenCalledWith(['5']);
            expect(instance.updateTextDisplayed).toHaveBeenCalledTimes(1);
            expect(instance.clickSelectButton).toHaveBeenCalledTimes(1);
            expect(instance.getControlValue).toHaveBeenCalledTimes(0);
        });
    });
    describe('getControlValue', () => {
        describe('is chosen', () => {
            it('should make expected calls', async () => {
                const page = await setupPage();
                const instance = setupInstance(page);
                jest.spyOn(instance, 'isChosen').mockReturnValue(true);
                instance.choice = ['some', 'choices'];
                expect(instance.getControlValue('some')).toEqual(['choices']);
            });
        });
        describe('is not chosen', () => {
            it('should make expected calls', async () => {
                const page = await setupPage();
                const instance = setupInstance(page);
                jest.spyOn(instance, 'isChosen').mockReturnValue(false);
                instance.choice = ['some', 'choices'];
                expect(instance.getControlValue('new')).toEqual(['some', 'choices', 'new']);
            });
        });
    });
    describe('clickSelectButton', () => {
        it('should make expected calls', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            const event = new MouseEvent('click');
            const focusSpy = jest.fn();
            jest.spyOn(event, 'preventDefault').mockImplementation(() => { });
            jest.spyOn(instance.el, 'querySelector').mockReturnValue({
                focus: focusSpy,
            });
            instance.clickSelectButton();
            expect(focusSpy).toHaveBeenCalledTimes(1);
            expect(instance.el.querySelector).toHaveBeenCalledTimes(1);
        });
        it('handles fallback', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            const event = new MouseEvent('click');
            jest.spyOn(event, 'preventDefault').mockImplementation(() => { });
            jest.spyOn(instance.el, 'querySelector').mockReturnValue(null);
            instance.clickSelectButton();
            expect(instance.el.querySelector).toHaveBeenCalledTimes(1);
        });
    });
    describe('isChosen', () => {
        it('should return expected results', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.choice = null;
            expect(instance.isChosen('some')).toBeFalsy();
            expect(instance.isChosen('new')).toBeFalsy();
            instance.choice = [];
            expect(instance.isChosen('some')).toBeFalsy();
            expect(instance.isChosen('new')).toBeFalsy();
            instance.choice = ['some', 'choices'];
            expect(instance.isChosen('some')).toBeTruthy();
            expect(instance.isChosen('new')).toBeFalsy();
        });
        it('should have fallback', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            expect(instance.isChosen('some')).toBeFalsy();
            expect(instance.isChosen('new')).toBeFalsy();
        });
    });
    describe('handleKeyEvent', () => {
        it('should make expected calls', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            jest.spyOn(instance, 'getKeyEventOptions').mockReturnValue({});
            jest.spyOn(instance, 'getIndexToSelect').mockReturnValue(0);
            jest.spyOn(instance, 'mapKeyEventToAction').mockImplementation(() => { });
            instance.handleKeyEvent('key');
            expect(instance.getKeyEventOptions).toBeCalledWith('key');
            expect(instance.getIndexToSelect).toBeCalledWith('key', {});
            expect(instance.mapKeyEventToAction).toBeCalledWith('key', 0, {});
            expect(instance.getKeyEventOptions).toBeCalledTimes(1);
            expect(instance.getIndexToSelect).toBeCalledTimes(1);
            expect(instance.mapKeyEventToAction).toBeCalledTimes(1);
        });
    });
    describe('getKeyEventOptions', () => {
        describe('ArrowUp', () => {
            it('should return expected result', async () => {
                const page = await setupPage();
                const instance = setupInstance(page);
                const options = {
                    addToFilter: false,
                    openSelectList: false,
                    isOpenOrSelectKey: false,
                    shouldMoveIndex: true,
                    goToPrevious: true,
                    goToNext: false,
                };
                expect(instance.getKeyEventOptions('ArrowUp')).toEqual(options);
            });
        });
        describe('ArrowDown', () => {
            it('should return expected result', async () => {
                const page = await setupPage();
                const instance = setupInstance(page);
                const options = {
                    addToFilter: false,
                    openSelectList: false,
                    isOpenOrSelectKey: false,
                    shouldMoveIndex: true,
                    goToPrevious: false,
                    goToNext: true,
                };
                expect(instance.getKeyEventOptions('ArrowDown')).toEqual(options);
            });
        });
        describe('Enter', () => {
            it('should return expected result', async () => {
                const page = await setupPage();
                const instance = setupInstance(page);
                const options = {
                    addToFilter: true,
                    openSelectList: true,
                    isOpenOrSelectKey: true,
                    shouldMoveIndex: false,
                    goToPrevious: false,
                    goToNext: false,
                };
                expect(instance.getKeyEventOptions('Enter')).toEqual(options);
            });
        });
        describe('space', () => {
            it('should return expected result', async () => {
                const page = await setupPage();
                const instance = setupInstance(page);
                const options = {
                    addToFilter: false,
                    openSelectList: true,
                    isOpenOrSelectKey: true,
                    shouldMoveIndex: false,
                    goToPrevious: false,
                    goToNext: false,
                };
                expect(instance.getKeyEventOptions(' ')).toEqual(options);
            });
        });
        describe('Tab', () => {
            describe('show select list', () => {
                it('should return expected result', async () => {
                    const page = await setupPage();
                    const instance = setupInstance(page);
                    instance.showSelectList = true;
                    const options = {
                        addToFilter: true,
                        openSelectList: false,
                        isOpenOrSelectKey: true,
                        shouldMoveIndex: false,
                        goToPrevious: false,
                        goToNext: false,
                    };
                    expect(instance.getKeyEventOptions('Tab')).toEqual(options);
                });
            });
            describe('hide select list', () => {
                it('should return expected result', async () => {
                    const page = await setupPage();
                    const instance = setupInstance(page);
                    const options = {
                        addToFilter: true,
                        openSelectList: false,
                        isOpenOrSelectKey: false,
                        shouldMoveIndex: false,
                        goToPrevious: false,
                        goToNext: false,
                    };
                    expect(instance.getKeyEventOptions('Tab')).toEqual(options);
                });
            });
        });
        it("if list isn't open, open it", async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.showSelectList = false;
            const options = {
                addToFilter: true,
                openSelectList: false,
                isOpenOrSelectKey: false,
                shouldMoveIndex: false,
                goToPrevious: false,
                goToNext: false,
            };
            expect(instance.getKeyEventOptions('Tab')).toEqual(options);
        });
        it('Other keys should return expected result', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            const options = {
                addToFilter: true,
                openSelectList: false,
                isOpenOrSelectKey: false,
                shouldMoveIndex: false,
                goToPrevious: false,
                goToNext: false,
            };
            expect(instance.getKeyEventOptions('A')).toEqual(options);
        });
    });
    describe('getIndexToSelect', () => {
        it('should open select list', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            const options = {
                isOpenOrSelectKey: true,
                shouldMoveIndex: true,
                goToPrevious: true,
            };
            instance.showSelectList = true;
            instance.focusedIndex = 10;
            expect(instance.getIndexToSelect('Escape', options)).toEqual(instance.focusedIndex);
        });
        it('should skip open or select key option if choices are hidden', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            const options = {
                isOpenOrSelectKey: true,
                shouldMoveIndex: true,
                goToPrevious: true,
            };
            instance.showSelectList = false;
            instance.focusedIndex = 10;
            expect(instance.getIndexToSelect('Escape', options)).toBeUndefined();
            expect(instance.showSelectList).toBeFalsy();
        });
        it('should close list if escape key pressed', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            const options = {
                isOpenOrSelectKey: false,
                shouldMoveIndex: true,
                goToPrevious: true,
            };
            instance.showSelectList = true;
            instance.focusedIndex = 10;
            expect(instance.getIndexToSelect('Escape', options)).toBeUndefined();
            expect(instance.showSelectList).toBeFalsy();
        });
        it('should not return selected index if choices are shown', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            const options = {
                isOpenOrSelectKey: false,
                shouldMoveIndex: true,
                goToPrevious: true,
            };
            instance.showSelectList = true;
            instance.focusedIndex = 10;
            expect(instance.getIndexToSelect('Any Other Key', options)).toBeUndefined();
            expect(instance.showSelectList).toBeTruthy();
        });
        it('should return previous index if go to previous', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            const options = {
                isOpenOrSelectKey: false,
                shouldMoveIndex: true,
                goToPrevious: true,
            };
            instance.showSelectList = false;
            instance.focusedIndex = 10;
            instance.choice = ['1'];
            expect(instance.getIndexToSelect('Any Other Key', options)).toBe(instance.focusedIndex - 1);
            expect(instance.showSelectList).toBeFalsy();
        });
        it('should return next index if not go previous', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            const options = {
                isOpenOrSelectKey: false,
                shouldMoveIndex: true,
                goToPrevious: false,
            };
            instance.choice = ['1'];
            instance.showSelectList = false;
            instance.focusedIndex = 10;
            expect(instance.getIndexToSelect('Any Other Key', options)).toBe(instance.focusedIndex + 1);
            expect(instance.showSelectList).toBeFalsy();
        });
        it('should return next index if not go previous', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            const options = {
                isOpenOrSelectKey: false,
                shouldMoveIndex: true,
                goToPrevious: false,
            };
            instance.choice = null;
            instance.showSelectList = false;
            instance.focusedIndex = 10;
            expect(instance.getIndexToSelect('Any Other Key', options)).toBe(0);
            expect(instance.showSelectList).toBeFalsy();
        });
        it('otherwise returns undefined and does nothing', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            const options = {
                isOpenOrSelectKey: false,
                shouldMoveIndex: false,
                goToPrevious: true,
            };
            instance.showSelectList = false;
            instance.focusedIndex = 10;
            expect(instance.getIndexToSelect('Any Other Key', options)).toBeUndefined();
            expect(instance.showSelectList).toBeFalsy();
        });
    });
    describe('mapKeyEventToAction', () => {
        it('should open select list if flag is set', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.focusOption = jest.fn();
            instance.selectOptionByIndex = jest.fn();
            jest.spyOn(instance, 'filterText').mockImplementation(() => { });
            const options = {
                openSelectList: true,
                shouldMoveIndex: true,
                goToPrevious: true,
            };
            expect(instance.focusedIndex).toEqual(0);
            instance.mapKeyEventToAction('some key', 1, options);
            expect(instance.focusOption).toHaveBeenCalledWith(instance.focusedIndex);
            expect(instance.focusOption).toHaveBeenCalledTimes(1);
            expect(instance.selectOptionByIndex).toHaveBeenCalledTimes(0);
            expect(instance.filterText).toHaveBeenCalledTimes(0);
        });
        it('should select from index if index is provided', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.focusOption = jest.fn();
            instance.selectOptionByIndex = jest.fn();
            jest.spyOn(instance, 'filterText').mockImplementation(() => { });
            const options = {
                shouldMoveIndex: true,
                goToPrevious: true,
            };
            expect(instance.focusedIndex).toEqual(0);
            instance.mapKeyEventToAction('some key', 1, options);
            expect(instance.selectOptionByIndex).toHaveBeenCalledWith(1);
            expect(instance.focusOption).toHaveBeenCalledTimes(0);
            expect(instance.selectOptionByIndex).toHaveBeenCalledTimes(1);
            expect(instance.filterText).toHaveBeenCalledTimes(0);
        });
        it('should move back if should move and not opening list or selecting index', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.focusOption = jest.fn();
            instance.selectOptionByIndex = jest.fn();
            jest.spyOn(instance, 'filterText').mockImplementation(() => { });
            instance.showSelectList = true;
            const options = {
                shouldMoveIndex: true,
                goToPrevious: true,
            };
            expect(instance.focusedIndex).toEqual(0);
            instance.mapKeyEventToAction('some key', null, options);
            expect(instance.focusOption).toHaveBeenCalledWith(-1);
            expect(instance.focusOption).toHaveBeenCalledTimes(1);
            expect(instance.selectOptionByIndex).toHaveBeenCalledTimes(0);
            expect(instance.filterText).toHaveBeenCalledTimes(0);
        });
        it('should move forward if not going back if should move and not opening list or selecting index', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.focusOption = jest.fn();
            instance.selectOptionByIndex = jest.fn();
            jest.spyOn(instance, 'filterText').mockImplementation(() => { });
            instance.showSelectList = true;
            const options = {
                shouldMoveIndex: true,
                goToPrevious: false,
            };
            instance.focusedIndex = 1;
            instance.mapKeyEventToAction('some key', null, options);
            expect(instance.focusOption).toHaveBeenCalledWith(2);
            expect(instance.focusOption).toHaveBeenCalledTimes(1);
            expect(instance.selectOptionByIndex).toHaveBeenCalledTimes(0);
            expect(instance.filterText).toHaveBeenCalledTimes(0);
        });
        it('should otherwise add to filter if flag is set', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            jest.spyOn(instance, 'focusOption').mockImplementation((res) => console.log(res));
            jest.spyOn(instance, 'selectOptionByIndex').mockImplementation(() => { });
            jest.spyOn(instance, 'filterText').mockImplementation(() => { });
            const options = {
                openSelectList: false,
                shouldMoveIndex: false,
                goToPrevious: false,
                addToFilter: true,
            };
            const key = 'some key';
            expect(instance.focusedIndex).toEqual(0);
            instance.mapKeyEventToAction(key, null, options);
            expect(instance.focusOption).toHaveBeenCalledTimes(0);
            expect(instance.selectOptionByIndex).toHaveBeenCalledTimes(0);
            expect(instance.filterText).toHaveBeenCalledTimes(1);
            expect(instance.filterText).toHaveBeenCalledWith(key);
        });
        it('should do nothing otherwise', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.focusOption = jest.fn();
            instance.selectOptionByIndex = jest.fn();
            jest.spyOn(instance, 'filterText').mockImplementation(() => { });
            instance.showSelectList = true;
            const options = {
                shouldMoveIndex: false,
                goToPrevious: true,
            };
            instance.mapKeyEventToAction('some key', null, options);
            expect(instance.focusOption).toHaveBeenCalledTimes(0);
            expect(instance.selectOptionByIndex).toHaveBeenCalledTimes(0);
            expect(instance.filterText).toHaveBeenCalledTimes(0);
        });
        it("should do nothing if 'showSelectList' is false", async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.focusOption = jest.fn();
            instance.selectOptionByIndex = jest.fn();
            jest.spyOn(instance, 'filterText').mockImplementation(() => { });
            instance.showSelectList = false;
            const options = {
                shouldMoveIndex: true,
                goToPrevious: true,
            };
            instance.mapKeyEventToAction('some key', null, options);
            expect(instance.focusOption).toHaveBeenCalledTimes(0);
            expect(instance.selectOptionByIndex).toHaveBeenCalledTimes(0);
            expect(instance.filterText).toHaveBeenCalledTimes(0);
        });
    });
    describe('selectOptionByIndex', () => {
        it('should make expected choice', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            jest.spyOn(instance, 'delayedClickSelectItem').mockImplementation(() => { });
            instance.choices = [
                { id: '1', value: '1' },
                { id: '2', value: '2' },
            ];
            expect(instance.focusedIndex).toEqual(0);
            instance.selectOptionByIndex(2);
            expect(instance.focusedIndex).toEqual(1);
            expect(instance.delayedClickSelectItem).toHaveBeenCalledTimes(1);
            expect(instance.delayedClickSelectItem).toHaveBeenCalledWith('2');
        });
    });
    describe('updateTextDisplayed', () => {
        describe('multiple', () => {
            it('use placeholder as fallback', async () => {
                const page = await setupPage();
                const instance = setupInstance(page);
                jest.spyOn(instance, 'updateMultiSelectText').mockImplementation(() => { });
                jest.spyOn(instance, 'updateSingleSelectText').mockImplementation(() => { });
                instance.multiple = true;
                instance.placeholder = 'some placeholder';
                expect(instance.selectText).toEqual('');
                instance.updateTextDisplayed(null);
                expect(instance.selectText).toEqual(instance.placeholder);
                expect(instance.updateMultiSelectText).toHaveBeenCalledTimes(0);
                expect(instance.updateSingleSelectText).toHaveBeenCalledTimes(0);
            });
            it('uses fallback if empty array', async () => {
                const page = await setupPage();
                const instance = setupInstance(page);
                jest.spyOn(instance, 'updateMultiSelectText').mockImplementation(() => { });
                jest.spyOn(instance, 'updateSingleSelectText').mockImplementation(() => { });
                instance.multiple = true;
                instance.placeholder = 'some placeholder';
                expect(instance.selectText).toEqual('');
                instance.updateTextDisplayed([]);
                expect(instance.selectText).toEqual(instance.placeholder);
                expect(instance.updateMultiSelectText).toHaveBeenCalledTimes(0);
                expect(instance.updateSingleSelectText).toHaveBeenCalledTimes(0);
            });
            it('otherwise makes expected calls', async () => {
                const page = await setupPage();
                const instance = setupInstance(page);
                jest.spyOn(instance, 'updateMultiSelectText').mockImplementation(() => { });
                jest.spyOn(instance, 'updateSingleSelectText').mockImplementation(() => { });
                instance.multiple = true;
                instance.placeholder = 'some placeholder';
                expect(instance.selectText).toEqual('');
                const choiceValue = ['an array'];
                instance.updateTextDisplayed(choiceValue);
                expect(instance.selectText).toEqual('');
                expect(instance.updateMultiSelectText).toHaveBeenCalledTimes(1);
                expect(instance.updateMultiSelectText).toBeCalledWith(choiceValue);
                expect(instance.updateSingleSelectText).toHaveBeenCalledTimes(0);
            });
        });
        describe('single', () => {
            it('use placeholder as fallback', async () => {
                const page = await setupPage();
                const instance = setupInstance(page);
                jest.spyOn(instance, 'updateMultiSelectText').mockImplementation(() => { });
                jest.spyOn(instance, 'updateSingleSelectText').mockImplementation(() => { });
                instance.placeholder = 'some placeholder';
                expect(instance.selectText).toEqual('');
                instance.updateTextDisplayed(['not an array']);
                expect(instance.selectText).toEqual(instance.placeholder);
                expect(instance.updateMultiSelectText).toHaveBeenCalledTimes(0);
                expect(instance.updateSingleSelectText).toHaveBeenCalledTimes(0);
            });
            it('otherwise makes expected calls', async () => {
                const page = await setupPage();
                const instance = setupInstance(page);
                jest.spyOn(instance, 'updateMultiSelectText').mockImplementation(() => { });
                jest.spyOn(instance, 'updateSingleSelectText').mockImplementation(() => { });
                instance.placeholder = 'some placeholder';
                expect(instance.selectText).toEqual('');
                const choiceValue = 'a string';
                instance.updateTextDisplayed(choiceValue);
                expect(instance.selectText).toEqual('');
                expect(instance.updateMultiSelectText).toHaveBeenCalledTimes(0);
                expect(instance.updateSingleSelectText).toBeCalledWith(choiceValue);
                expect(instance.updateSingleSelectText).toHaveBeenCalledTimes(1);
            });
        });
    });
    describe('updateMultiSelectText', () => {
        describe('use alias', () => {
            it('updates selected choices', async () => {
                const page = await setupPage();
                const instance = setupInstance(page);
                instance.choices = [
                    { id: '1', alias: 'one', value: '1' },
                    { id: '2', alias: 'two', value: '2' },
                    { id: '4', alias: 'four', value: '4' },
                ];
                instance.useAlias = true;
                expect(instance.selectText).toEqual('');
                instance.updateMultiSelectText(['1', '2', '3']);
                expect(instance.selectText).toEqual('one, two');
            });
        });
        describe("don't use alias", () => {
            it('updates selected choices', async () => {
                const page = await setupPage();
                const instance = setupInstance(page);
                instance.choices = [
                    { id: '1', alias: 'one', value: '1' },
                    { id: '2', alias: 'two', value: '2' },
                    { id: '4', alias: 'four', value: '4' },
                ];
                expect(instance.selectText).toEqual('');
                instance.updateMultiSelectText(['1', '2', '3']);
                expect(instance.selectText).toEqual('1, 2');
            });
        });
        it('does not update selected choices if empty', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.choices = [
                { id: '1', alias: 'one', value: '1' },
                { id: '2', alias: 'two', value: '2' },
                { id: '4', alias: 'four', value: '4' },
            ];
            expect(instance.selectText).toEqual('');
            instance.updateMultiSelectText([]);
            expect(instance.selectText).toEqual('');
        });
    });
    describe('updateSingleSelectText', () => {
        it('does updates if match found', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.choices = [
                { id: '1', alias: 'one', value: '1' },
                { id: '2', alias: 'two', value: '2' },
                { id: '4', alias: 'four', value: '4' },
            ];
            expect(instance.selectText).toEqual('');
            instance.updateSingleSelectText('1');
            expect(instance.selectText).toEqual('1');
        });
        it('uses alias if flagged', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.useAlias = true;
            instance.choices = [
                { id: '1', alias: 'one', value: '1' },
                { id: '2', alias: 'two', value: '2' },
                { id: '4', alias: 'four', value: '4' },
            ];
            expect(instance.selectText).toEqual('');
            instance.updateSingleSelectText('1');
            expect(instance.selectText).toEqual('one');
        });
        it('does not update selected choices if empty', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.choices = [
                { id: '1', alias: 'one', value: '1' },
                { id: '2', alias: 'two', value: '2' },
                { id: '4', alias: 'four', value: '4' },
            ];
            expect(instance.selectText).toEqual('');
            instance.updateSingleSelectText('3');
            expect(instance.selectText).toEqual('');
        });
    });
    describe('watchFilterText', () => {
        it('adds new value', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            jest.spyOn(instance, 'listenToTextFilter').mockImplementation(() => { });
            instance.accumulateFilter = false;
            instance.currentFilterText = '12';
            instance.filterText('3');
            expect(instance.currentFilterText).toEqual('3');
            expect(instance.listenToTextFilter).toBeCalledWith('3');
            expect(instance.listenToTextFilter).toHaveBeenCalledTimes(1);
        });
        it('does not update selected choices if empty', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            jest.spyOn(instance, 'listenToTextFilter').mockImplementation(() => { });
            instance.currentFilterText = '12';
            instance.accumulateFilter = true;
            instance.filterText('3');
            expect(instance.currentFilterText).toEqual('123');
            expect(instance.listenToTextFilter).toBeCalledWith('123');
            expect(instance.listenToTextFilter).toHaveBeenCalledTimes(1);
        });
    });
    describe('listenToTextFilter', () => {
        it('makes expected calls', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            await page.waitForChanges();
            jest.spyOn(instance, 'handleTextEntry').mockImplementation(() => { });
            instance.listenToTextFilter('3');
            expect(instance.handleTextEntry).toHaveBeenCalledTimes(1);
            expect(instance.handleTextEntry).toHaveBeenCalledWith('3');
        });
    });
    describe('handleTextEntry', () => {
        describe('show select list', () => {
            it('makes expected calls', async () => {
                const page = await setupPage();
                const instance = setupInstance(page);
                await page.waitForChanges();
                jest.spyOn(instance, 'focusOption').mockImplementation(() => { });
                jest.spyOn(instance, 'delayedClickSelectItem').mockImplementation(() => { });
                instance.accumulateFilter = true;
                instance.choices = [
                    { id: '1', value: '1' },
                    { id: '2', value: '2' },
                ];
                instance.showSelectList = true;
                instance.handleTextEntry('1');
                expect(instance.accumulateFilter).toBeFalsy();
                expect(instance.delayedClickSelectItem).toBeCalledTimes(0);
                expect(instance.focusOption).toBeCalledTimes(1);
                expect(instance.focusOption).toBeCalledWith(0);
            });
            it('fallback if choice', async () => {
                const page = await setupPage();
                const instance = setupInstance(page);
                await page.waitForChanges();
                jest.spyOn(instance, 'focusOption').mockImplementation(() => { });
                jest.spyOn(instance, 'delayedClickSelectItem').mockImplementation(() => { });
                instance.accumulateFilter = true;
                instance.choices = [
                    { id: '1', value: '1' },
                    { id: '2', value: '2' },
                ];
                instance.showSelectList = false;
                instance.handleTextEntry('1');
                expect(instance.accumulateFilter).toBeFalsy();
                expect(instance.delayedClickSelectItem).toBeCalledWith('1');
                expect(instance.delayedClickSelectItem).toBeCalledTimes(1);
                expect(instance.focusOption).toBeCalledTimes(0);
            });
            it('otherwise does nothing', async () => {
                const page = await setupPage();
                const instance = setupInstance(page);
                await page.waitForChanges();
                jest.spyOn(instance, 'focusOption').mockImplementation(() => { });
                jest.spyOn(instance, 'delayedClickSelectItem').mockImplementation(() => { });
                instance.accumulateFilter = true;
                instance.choices = [
                    { id: '1', value: '1' },
                    { id: '2', value: '2' },
                ];
                instance.showSelectList = false;
                instance.handleTextEntry('3');
                expect(instance.accumulateFilter).toBeFalsy();
                expect(instance.delayedClickSelectItem).toBeCalledTimes(0);
                expect(instance.focusOption).toBeCalledTimes(0);
            });
            it('does not error if called with nullable', async () => {
                const page = await setupPage();
                const instance = setupInstance(page);
                await page.waitForChanges();
                jest.spyOn(instance, 'focusOption').mockImplementation(() => { });
                jest.spyOn(instance, 'delayedClickSelectItem').mockImplementation(() => { });
                instance.accumulateFilter = true;
                instance.choices = [
                    { id: '1', value: '1' },
                    { id: '2', value: '2' },
                ];
                instance.showSelectList = false;
                instance.handleTextEntry(null);
                expect(instance.accumulateFilter).toBeFalsy();
                expect(instance.delayedClickSelectItem).toBeCalledTimes(0);
                expect(instance.focusOption).toBeCalledTimes(0);
            });
        });
        describe('hide select list', () => {
            it('makes expected calls', async () => {
                const page = await setupPage();
                const instance = setupInstance(page);
                await page.waitForChanges();
                jest.spyOn(instance, 'focusOption').mockImplementation(() => { });
                jest.spyOn(instance, 'delayedClickSelectItem').mockImplementation(() => { });
                instance.showSelectList = true;
                instance.accumulateFilter = true;
                instance.choices = [
                    { id: '1', value: '1' },
                    { id: '2', value: '2' },
                ];
                instance.handleTextEntry('1');
                expect(instance.accumulateFilter).toBeFalsy();
                expect(instance.delayedClickSelectItem).toBeCalledTimes(0);
                expect(instance.focusOption).toBeCalledTimes(1);
                expect(instance.focusOption).toBeCalledWith(0);
            });
        });
    });
    describe('getSelectableIndex', () => {
        it('makes expected calls', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.choices = ['1', '2', '3'];
            await page.waitForChanges();
            expect(instance.getSelectableIndex(-1)).toEqual(0);
            expect(instance.getSelectableIndex(0)).toEqual(0);
            expect(instance.getSelectableIndex(1)).toEqual(1);
            expect(instance.getSelectableIndex(2)).toEqual(2);
            expect(instance.getSelectableIndex(3)).toEqual(2);
        });
    });
    describe('handleOutsideClick', () => {
        it('makes expected calls', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            await page.waitForChanges();
            instance.showSelectList = true;
            instance.handleOutsideClick();
            expect(instance.showSelectList).toBeFalsy();
        });
    });
    describe('onSubmitButtonClick', () => {
        it('makes expected calls', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            jest.spyOn(instance, 'selectFocus').mockImplementation(() => { });
            const event = new MouseEvent('click');
            instance.onSubmitButtonClick(event);
            expect(instance.selectFocus).toBeCalledTimes(1);
            expect(instance.selectFocus).toHaveBeenCalledWith(event);
        });
    });
    describe('onListBlur', () => {
        it('makes expected calls', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            instance.showSelectList = true;
            instance.onListBlur();
            expect(instance.showSelectList).toBeFalsy();
        });
    });
    describe('onChoiceClick', () => {
        it('returns function that makes expected calls', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            jest.spyOn(instance, 'delayedClickSelectItem').mockImplementation(() => { });
            const func = instance.onChoiceClick({ id: '1' });
            const event = new MouseEvent('click');
            jest.spyOn(event, 'stopPropagation');
            func(event);
            expect(instance.delayedClickSelectItem).toBeCalledTimes(1);
            expect(instance.delayedClickSelectItem).toHaveBeenCalledWith('1');
            expect(event.stopPropagation).toBeCalledTimes(1);
        });
    });
    describe('onAutocomplete', () => {
        it('returns function that makes expected calls', async () => {
            const page = await setupPage();
            const instance = setupInstance(page);
            jest.spyOn(instance, 'delayedClickSelectItem').mockImplementation(() => { });
            const value = 'Georgia';
            const targetChoice = { id: '1', alias: 'GA', value: 'Georgia' };
            instance.choices = [{}, targetChoice, { id: '2', value: 'Georgia', alias: 'Georgia' }];
            instance.onAutocomplete({ target: { value } });
            expect(instance.delayedClickSelectItem).toBeCalledTimes(1);
            expect(instance.delayedClickSelectItem).toHaveBeenCalledWith(targetChoice.id);
        });
    });
});
