// Components
import { shallowMount } from '@vue/test-utils';
import { createTestingPinia } from '@pinia/testing';
import tpaSearch from '@/layouts/tpa-search/tpa-search.vue';

// Supporting Files
import baseMixin from '@/mixins/base-mixin';
import { getMountOptions } from '@/helpers/unit-test-helper.js';
import { useMainStore } from '@/store';
import { fetchCmsContentForPage } from '@/helpers/cms-content-helper';
import settleAllPromises from '@/helpers/layout-helper.js';
import globalRules from '@/constants/global-rules.js';
import widgetFields from '@/constants/cms-widget-fields.js';
import navigationScenarios from '@/router/router-constants/navigation-scenarios';

// Mock fetchCmsContentForPage
jest.mock('@/helpers/cms-content-helper', () => ({
    fetchCmsContentForPage: jest.fn(),
    doesCopyContainRouterLink: jest.fn()
}));

// Mock our module for promises.
jest.mock('@/helpers/layout-helper.js', () => jest.fn());

function getMountedComponent(mainInitialState = {}, initialData = {}, methodToRunAfterInitializingStore = () => {}) {
    const mountOptions = getMountOptions({
        router: {
            navigate: jest.fn()
        }
    });

    const testingPinia = createTestingPinia({
        initialState: {
            main: mainInitialState
        }
    });
    useMainStore(testingPinia);
    methodToRunAfterInitializingStore();

    mountOptions.global.plugins = [testingPinia];
    mountOptions.data = () => (initialData);

    const apiResponses = { cmsContent: {} };

    settleAllPromises.mockImplementation(() => apiResponses);
    fetchCmsContentForPage.mockImplementation(() => Promise.resolve());

    const wrapper = shallowMount(tpaSearch, mountOptions);
    wrapper.vm.getCmsContent = jest.fn().mockImplementation(() => {});
    wrapper.vm.setCmsContent = jest.fn();
    wrapper.vm.$router.navigateWithSpinner = jest.fn();
    wrapper.vm.navigateBack = baseMixin.methods.navigateBack;

    return { wrapper };
}

describe('TPA search page', () => {
    test.skip('returns the initial data', () => {
        // Arrange
        const zipCode = '12663';
        const mainInitialState = {
            order: {
                customer: {
                    address: { zipCode }
                }
            }
        };
        const { wrapper } = getMountedComponent(mainInitialState);

        // Assert
        expect(wrapper.vm.$data).toMatchSnapshot();
    });
    describe('should render', () => {
        test('site header', () => {
            // Arrange
            const wrapper = shallowMount(tpaSearch, getMountOptions());
            const expectedWidgetName = 'SiteHeaderWidget';

            // Act
            const siteHeader = wrapper.findComponent({ ref: 'siteHeader' });

            // Assert
            expect(siteHeader.exists()).toBeTruthy();
            expect(siteHeader.props().cmsWidgetName).toBe(expectedWidgetName);
        });
        test('search providers form', () => {
            // Arrange
            const wrapper = shallowMount(tpaSearch, getMountOptions());

            // Act
            const searchProvidersForm = wrapper.findComponent('#searchProvidersForm');

            // Assert
            expect(searchProvidersForm.exists()).toBeTruthy();
        });
        test('search question label', () => {
            // Arrange
            const wrapper = shallowMount(tpaSearch, getMountOptions());

            // Act
            const searchQuestionLabel = wrapper.find('#tpaSearchQuestionLabel');

            // Assert
            expect(searchQuestionLabel.exists()).toBeTruthy();
            expect(searchQuestionLabel.attributes().for).toBe('tpaSearchQuestionField');
            expect(searchQuestionLabel.classes()).toContain('text-center');
            expect(searchQuestionLabel.classes()).toContain('mt-5');
            expect(searchQuestionLabel.classes()).toContain('mb-0');
            expect(searchQuestionLabel.classes()).toContain('text-black');
            expect(searchQuestionLabel.classes()).toContain('w-100');
            expect(searchQuestionLabel.classes()).toContain('fs-5');
        });
        test('search instructions', () => {
            // Arrange
            const wrapper = shallowMount(tpaSearch, getMountOptions());

            // Act
            const searchInstructions = wrapper.find('#searchInstructions');

            // Assert
            expect(searchInstructions.exists()).toBeTruthy();
            expect(searchInstructions.attributes().for).toBe('tpaSearchQuestionField');
            expect(searchInstructions.classes()).toContain('text-center');
            expect(searchInstructions.classes()).toContain('small');
            expect(searchInstructions.classes()).toContain('darker-gray');
            expect(searchInstructions.classes()).toContain('w-100');
            expect(searchInstructions.classes()).toContain('mb-4');
        });
        test('search question field', () => {
            // Arrange
            const wrapper = shallowMount(tpaSearch, getMountOptions());
            const expectedWidgetName = 'TPASearchQuestion';

            // Act
            const searchQuestionField = wrapper.findComponent('#tpaSearchQuestionField');

            // Assert
            expect(searchQuestionField.exists()).toBeTruthy();
            expect(searchQuestionField.props().inputId).toBe('tpaSearchQuestionFieldInput');
            expect(searchQuestionField.props().isRequired).toBeTruthy();
            expect(searchQuestionField.props().cmsWidgetName).toBe(expectedWidgetName);
            expect(searchQuestionField.props().includeSearchIcon).toBeTruthy();
            expect(searchQuestionField.props().displayQuestionText).toBeFalsy();
            expect(searchQuestionField.props().validationRules)
                .toBe(`${globalRules.ZIP_CODE_REQUIRED}|${globalRules.ZIP_CODE_SEARCH_FORMAT}`);
        });
        test('provider selection form', () => {
            // Arrange
            const wrapper = shallowMount(tpaSearch, getMountOptions());

            // Act
            const providerSelectionForm = wrapper.findComponent('#providerSelectionForm');

            // Assert
            expect(providerSelectionForm.exists()).toBeTruthy();
        });
        test('map', async () => {
            // Arrange
            const zipCode = '12345';
            const { wrapper } = getMountedComponent();
            await wrapper.setData({
                providers: [{
                    address: {
                        streetAddress: '123 Lane Ave',
                        city: 'New York',
                        state: 'NY',
                        zipCode: '99230'
                    }
                }],
                mapZipCode: zipCode
            });
            const expectedAddresses = ['123 Lane Ave, New York, NY 99230'];

            // Act
            const map = wrapper.findComponent('#map');

            // Assert
            expect(map.exists()).toBeTruthy();
            expect(map.classes()).toContain('mb-4');
            expect(map.props().markers.map((p) => p.fullAddress)).toEqual(expectedAddresses);
            expect(map.props().zipCode).toBe(zipCode);
        });
        test('search radius filter', async () => {
            // Arrange
            const wrapper = shallowMount(tpaSearch, getMountOptions());
            const expectedWidgetName = 'FilterByQuestion';

            // Act
            const searchRadiusFilter = wrapper.findComponent('#searchRadiusFilter');

            // Assert
            expect(searchRadiusFilter.exists()).toBeTruthy();
            expect(searchRadiusFilter.props().cmsWidgetName).toBe(expectedWidgetName);
            expect(searchRadiusFilter.props().validationRules).toBe(globalRules.OPTION_REQUIRED);
        });
        test('providers loader when reloadingProviders is true', async () => {
            // Arrange
            const wrapper = shallowMount(tpaSearch, getMountOptions());
            await wrapper.setData({ reloadingProviders: true });

            // Act
            const providersLoader = wrapper.findComponent('#providersLoader');

            // Assert
            expect(providersLoader.exists()).toBeTruthy();
        });
        test('select provider question when reloadingProviders are false', async () => {
            // Arrange
            const wrapper = shallowMount(tpaSearch, getMountOptions());
            await wrapper.setData({
                providers: [{
                    companyName: 'Shop Auto Glass',
                    phoneNumber: '740-555-1234',
                    distanceInMiles: 1.2345,
                    providerNumber: '232209',
                    address: {
                        streetAddress: '123 Lane Ave',
                        city: 'New York',
                        state: 'NY',
                        zipCode: '99230'
                    }
                }],
                reloadingProviders: false
            });
            const expectedAnswers = [{
                buttonLabel: 'Shop Auto Glass',
                buttonLabelSubCopy: '1.2 mi',
                buttonBodyCopy: '123 Lane Ave, New York, NY 99230<br>740-555-1234',
                value: '232209'
            }];
            const expectedAdditionalButtonData = {
                displayAvailabilityIndicators: false
            };

            // Act
            const selectProviderQuestion = wrapper.findComponent('#selectProviderQuestion');

            // Assert
            expect(selectProviderQuestion.exists()).toBeTruthy();
            expect(selectProviderQuestion.props().buttonTypeString).toBe('shopListButton');
            expect(selectProviderQuestion.classes()).toContain('radioQuestion');
            expect(selectProviderQuestion.props().groupName).toBe('chooseShop');
            expect(selectProviderQuestion.props().textPosition).toBe('text-start');
            expect(selectProviderQuestion.props().isRequired).toBeTruthy();
            expect(selectProviderQuestion.props().validationRules).toBe(globalRules.OPTION_REQUIRED);
            expect(selectProviderQuestion.props().answers).toEqual(expectedAnswers);
            expect(selectProviderQuestion.props().additionalButtonData).toEqual(expectedAdditionalButtonData);
        });
        test.each([[], null, undefined])(
            'no network providers alert when providers length is 0, undefined, or null and reloadingProviders is false',
            async (providers) => {
                // Arrange
                const initialData = {
                    providers
                };
                const wrapper = shallowMount(tpaSearch, getMountOptions({}, initialData));
                await wrapper.setData({ reloadingProviders: false });

                // Act
                const noNetworkProvidersAlert = wrapper.findComponent('#alertNoNetworkProviders');

                // Assert
                expect(noNetworkProvidersAlert.exists()).toBeTruthy();
                expect(noNetworkProvidersAlert.props().cmsWidgetName).toBeTruthy();
                expect(noNetworkProvidersAlert.props().alertClass).toBe('alert-warning');
                expect(noNetworkProvidersAlert.props().isDismissible).toBeFalsy();
            }
        );
        test('preferred shop not listed link when reloadingProviders is false', async () => {
            // Arrange
            const wrapper = shallowMount(tpaSearch, getMountOptions());
            await wrapper.setData({ reloadingProviders: false });

            // Act
            const preferredShopNotListedLink = wrapper.findComponent('#preferredShopNotListedLink');

            // Assert
            expect(preferredShopNotListedLink.exists()).toBeTruthy();
            expect(preferredShopNotListedLink.props().linkType).toBe('navigation');
            // eslint-disable-next-line no-script-url
            expect(preferredShopNotListedLink.props().href).toBe('javascript:void(0)');
        });
        test('site footer', () => {
            // Arrange
            const wrapper = shallowMount(tpaSearch, getMountOptions());

            // Act
            const footer = wrapper.findComponent({ ref: 'siteFooter' });

            // Assert
            expect(footer.exists()).toBeTruthy();
            expect(footer.props().cmsWidgetName).toBe('SiteFooterWidget');
        });
    });
    describe('should not render', () => {
        test('select provider question when reloadingProviders is true', async () => {
            // Arrange
            const { wrapper } = getMountedComponent();
            await wrapper.setData({ reloadingProviders: true });

            // Act
            const selectProviderQuestion = wrapper.findComponent('#selectProviderQuestion');

            // Assert
            expect(selectProviderQuestion.exists()).toBeFalsy();
        });
        describe('no network providers alert', () => {
            test('when providers length is not 0', async () => {
                // Arrange
                const wrapper = shallowMount(tpaSearch, getMountOptions());
                await wrapper.setData({ providers: ['p1', 'p2'] });

                // Act
                const noNetworkProvidersAlert = wrapper.findComponent('#alertNoNetworkProviders');

                // Assert
                expect(noNetworkProvidersAlert.exists()).toBeFalsy();
            });
            test('when reloadingProviders is true', async () => {
                // Arrange
                const wrapper = shallowMount(tpaSearch, getMountOptions());
                await wrapper.setData({ providers: [], reloadingProviders: true });

                // Act
                const noNetworkProvidersAlert = wrapper.findComponent('#alertNoNetworkProviders');

                // Assert
                expect(noNetworkProvidersAlert.exists()).toBeFalsy();
            });
        });
        test('preferred shop not listed link when reloadingProviders is true', async () => {
            // Arrange
            const { wrapper } = getMountedComponent();
            await wrapper.setData({ reloadingProviders: true });

            // Act
            const preferredShopNotListedLink = wrapper.findComponent('#preferredShopNotListedLink');

            // Assert
            expect(preferredShopNotListedLink.exists()).toBeFalsy();
        });
    });
    describe('computed', () => {
        describe('filterOptions', () => {
            test.each([[], null, undefined])(
                'returns empty object when cms content is empty, null or undefined',
                (cmsContent) => {
                    // Arrange
                    const mountOptions = getMountOptions();
                    mountOptions.mixins = [{
                        methods: {
                            getCmsContent: jest.fn().mockImplementation((widget, field) =>
                                (widget === 'FilterByQuestion' && field === widgetFields.INPUT_QUESTION_WIDGET.ANSWERS
                                    ? cmsContent
                                    : ''))
                        }
                    }];
                    const wrapper = shallowMount(tpaSearch, mountOptions);

                    // Act
                    const result = wrapper.vm.filterOptions;

                    // Assert
                    expect(result).toEqual({});
                }
            );
            test('returns expected when cms content is some non empty iterable', () => {
                // Arrange
                const mountOptions = getMountOptions();
                const cmsContent = [{ Name: 'foo' }, { Name: 'bar' }];
                mountOptions.mixins = [{
                    methods: {
                        getCmsContent: jest.fn().mockImplementation((widget, field) =>
                            (widget === 'FilterByQuestion' && field === widgetFields.INPUT_QUESTION_WIDGET.ANSWERS
                                ? cmsContent
                                : ''))
                    }
                }];
                const wrapper = shallowMount(tpaSearch, mountOptions);
                const expected = { foo: 'foo', bar: 'bar' };

                // Act
                const result = wrapper.vm.filterOptions;

                // Assert
                expect(result).toEqual(expected);
            });
        });
        test.each([null, undefined, '', 'non empty string'])(
            'tpaSearchQuestionLabel returns "%p" from getCmsContent',
            (cmsContent) => {
                // Arrange
                const mountOptions = getMountOptions();
                mountOptions.mixins = [{
                    methods: {
                        getCmsContent: jest.fn().mockImplementation((widget, field) =>
                            (widget === 'TPASearchQuestion' && field === widgetFields.INPUT_QUESTION_WIDGET.QUESTION_TEXT
                                ? cmsContent
                                : ''))
                    }
                }];
                const wrapper = shallowMount(tpaSearch, mountOptions);

                // Act
                const result = wrapper.vm.tpaSearchQuestionLabel;

                // Assert
                expect(result).toEqual(cmsContent);
            }
        );
        test.each([null, undefined, '', 'non empty string'])(
            'searchInstructionsText returns "%p" from getCmsContent',
            (cmsContent) => {
                // Arrange
                const mountOptions = getMountOptions();
                mountOptions.mixins = [{
                    methods: {
                        getCmsContent: jest.fn().mockImplementation((widget, field) =>
                            (widget === 'SearchInstructions' && field === widgetFields.TEXT_BLOCK_WIDGET.TEXT
                                ? cmsContent
                                : ''))
                    }
                }];
                const wrapper = shallowMount(tpaSearch, mountOptions);

                // Act
                const result = wrapper.vm.searchInstructionsText;

                // Assert
                expect(result).toEqual(cmsContent);
            }
        );
        test.each([null, undefined, '', 'non empty string'])(
            'shopNotListedModalLink returns "%p" from getCmsContent',
            (cmsContent) => {
                // Arrange
                const mountOptions = getMountOptions();
                mountOptions.mixins = [{
                    methods: {
                        getCmsContent: jest.fn().mockImplementation((widget, field) =>
                            (widget === 'ShopNotListedLink' && field === widgetFields.TEXT_BLOCK_WIDGET.TEXT
                                ? cmsContent
                                : ''))
                    }
                }];
                const wrapper = shallowMount(tpaSearch, mountOptions);

                // Act
                const result = wrapper.vm.shopNotListedModalLink;

                // Assert
                expect(result).toEqual(cmsContent);
            }
        );
        describe('radiusInMiles', () => {
            test.each([
                [15, '15 miles'],
                [25, '25 miles'],
                [50, '50 miles'],
                [100, '100 miles']
            ])(
                'returns %p when filter is "%p"',
                async (expectedRadius, filter) => {
                    // Arrange
                    const { wrapper } = getMountedComponent();
                    await wrapper.setData({ filter });

                    // Act
                    const result = wrapper.vm.radiusInMiles;

                    // Assert
                    expect(result).toEqual(expectedRadius);
                }
            );
            test.each([null, undefined, 'some random string'])(
                'returns 0 when filter is "%p"',
                async (filter) => {
                    // Arrange
                    const { wrapper } = getMountedComponent();
                    await wrapper.setData({ filter });

                    // Act
                    const result = wrapper.vm.radiusInMiles;

                    // Assert
                    expect(result).toEqual(0);
                }
            );
        });
        describe('noNetworkShopsAlertHeaderText', () => {
            test('returns exact cmsContent value when "{custom:radiusInMiles}" is not a substring', async () => {
                // Arrange
                const cmsContent = 'content returned from cms';
                const mountOptions = getMountOptions();
                mountOptions.mixins = [{
                    methods: {
                        getCmsContent: jest.fn().mockImplementation((widget, field) =>
                            (widget === 'NoNetworkShopsAlertWidget' && field === widgetFields.ALERT_WIDGET.HEADLINE_TEXT
                                ? cmsContent
                                : ''))
                    }
                }];
                const wrapper = shallowMount(tpaSearch, mountOptions);

                // Act
                const result = wrapper.vm.noNetworkShopsAlertHeaderText;

                // Assert
                expect(result).toEqual(cmsContent);
            });
            test('returns cmsContent value with all instances of "{custom:radiusInMiles}" replaced with radiusInMiles', () => {
                // Arrange
                const cmsContent = '{custom:radiusInMiles} ret{custom:radiusInMiles}urned {custom:radiusInMiles}cms{custom:radiusInMiles}';
                const mountOptions = getMountOptions();
                mountOptions.mixins = [{
                    methods: {
                        getCmsContent: jest.fn().mockImplementation((widget, field) =>
                            (widget === 'NoNetworkShopsAlertWidget' && field === widgetFields.ALERT_WIDGET.HEADLINE_TEXT
                                ? cmsContent
                                : ''))
                    }
                }];
                const wrapper = shallowMount(tpaSearch, mountOptions);
                const expected = '0 ret0urned 0cms0';

                // Act
                const result = wrapper.vm.noNetworkShopsAlertHeaderText;

                // Assert
                expect(result).toEqual(expected);
            });
        });
        describe('providerAddresses', () => {
            test.each([null, undefined, []])(
                'returns empty list when providers empty',
                async (providers) => {
                    // Arrange
                    const wrapper = shallowMount(tpaSearch, getMountOptions());
                    await wrapper.setData({ providers });

                    // Act
                    const result = wrapper.vm.providerAddresses;

                    // Assert
                    expect(result).toEqual([]);
                }
            );
            test('returns expected when providers not empty', async () => {
                // Arrange
                const wrapper = shallowMount(tpaSearch, getMountOptions());
                await wrapper.setData({
                    providers: [
                        {
                            companyName: 'Shop Auto Glass',
                            phoneNumber: '740-555-1234',
                            distanceInMiles: 1.2345,
                            providerNumber: '232209',
                            address: {
                                streetAddress: '123 Lane Ave',
                                city: 'New York',
                                state: 'NY',
                                zipCode: '99230'
                            }
                        },
                        {
                            companyName: 'Safelite AutoGlass',
                            phoneNumber: '676-555-0099',
                            distanceInMiles: 123.9452,
                            providerNumber: '123456',
                            address: {
                                streetAddress: '2003 Coral Ln',
                                city: 'Birmingham',
                                state: 'AL',
                                zipCode: '43001'
                            }
                        }
                    ]
                });
                const expectedResult = [
                    '123 Lane Ave, New York, NY 99230',
                    '2003 Coral Ln, Birmingham, AL 43001'
                ];

                // Act
                const result = wrapper.vm.providerAddresses.map((pa) => pa.fullAddress);

                // Assert
                expect(result).toEqual(expectedResult);
            });
        });
        describe('providerButtonData', () => {
            test.each([null, undefined, []])(
                'returns empty list when providers equals "%p"',
                async (providers) => {
                    // Arrange
                    const wrapper = shallowMount(tpaSearch, getMountOptions());
                    await wrapper.setData({ providers });

                    // Act
                    const result = wrapper.vm.providerButtonData;

                    // Assert
                    expect(result).toEqual([]);
                }
            );
            test('returns expected when providers not empty', async () => {
                // Arrange
                const wrapper = shallowMount(tpaSearch, getMountOptions());
                await wrapper.setData({
                    providers: [
                        {
                            companyName: 'Shop Auto Glass',
                            phoneNumber: '740-555-1234',
                            distanceInMiles: 1.2345,
                            providerNumber: '232209',
                            address: {
                                streetAddress: '123 Lane Ave',
                                city: 'New York',
                                state: 'NY',
                                zipCode: '99230'
                            }
                        },
                        {
                            companyName: 'Safelite AutoGlass',
                            phoneNumber: '676-555-0099',
                            distanceInMiles: 123.9452,
                            providerNumber: '123456',
                            address: {
                                streetAddress: '2003 Coral Ln',
                                city: 'Birmingham',
                                state: 'AL',
                                zipCode: '43001'
                            }
                        }
                    ]
                });
                const expectedResult = [
                    {
                        buttonLabel: 'Shop Auto Glass',
                        buttonLabelSubCopy: '1.2 mi',
                        buttonBodyCopy: '123 Lane Ave, New York, NY 99230<br>740-555-1234',
                        value: '232209'
                    },
                    {
                        buttonLabel: 'Safelite AutoGlass',
                        buttonLabelSubCopy: '123.9 mi',
                        buttonBodyCopy: '2003 Coral Ln, Birmingham, AL 43001<br>676-555-0099',
                        value: '123456'
                    }
                ];

                // Act
                const result = wrapper.vm.providerButtonData;

                // Assert
                expect(result).toEqual(expectedResult);
            });
        });
        describe('selectedProviderIsSafeliteShop', () => {
            test('no issue when provider in providers with no provider number', async () => {
                // Arrange
                const selectedProviderNumber = '10099';
                const providers = [
                    { isSafeliteShop: false },
                    { isSafeliteShop: true }
                ];
                const wrapper = shallowMount(tpaSearch, getMountOptions());
                await wrapper.setData({ selectedProviderNumber, providers });

                // Act
                const result = wrapper.vm.selectedProviderIsSafeliteShop;

                // Assert
                expect(result).toEqual(false);
            });
            test.each([null, undefined, []])(
                'returns false when providers %s',
                async (providers) => {
                    // Arrange
                    const selectedProviderNumber = '10099';
                    const wrapper = shallowMount(tpaSearch, getMountOptions());
                    await wrapper.setData({ selectedProviderNumber, providers });

                    // Act
                    const result = wrapper.vm.selectedProviderIsSafeliteShop;

                    // Assert
                    expect(result).toEqual(false);
                }
            );
            test.each([
                [true, true],
                [false, false]
            ])(
                'returns %p when first instance of multiple matching providerNumbers has isSafeliteShop value %p',
                async (expectedOutput, isSafeliteShop) => {
                    // Arrange
                    const selectedProviderNumber = '29987';
                    const providers = [
                        {
                            providerNumber: selectedProviderNumber,
                            isSafeliteShop
                        },
                        {
                            providerNumber: selectedProviderNumber,
                            isSafeliteShop: !isSafeliteShop
                        }
                    ];
                    const wrapper = shallowMount(tpaSearch, getMountOptions());
                    await wrapper.setData({ providers });
                    await wrapper.setData({ selectedProviderNumber });

                    // Act
                    const result = wrapper.vm.selectedProviderIsSafeliteShop;

                    // Assert
                    expect(result).toEqual(expectedOutput);
                }
            );
            test.each([[false, false], [true, true]])(
                'returns %p when providerNumber match has isSafeliteShop equal to %p',
                async (expectedOutput, isSafeliteShop) => {
                    // Arrange
                    const selectedProviderNumber = '19274';
                    const providers = [{
                        providerNumber: selectedProviderNumber,
                        isSafeliteShop
                    }];
                    const wrapper = shallowMount(tpaSearch, getMountOptions());
                    await wrapper.setData({ selectedProviderNumber, providers });

                    // Act
                    const result = wrapper.vm.selectedProviderIsSafeliteShop;

                    // Assert
                    expect(result).toEqual(expectedOutput);
                }
            );
        });
    });
    describe('watch', () => {
        // TODO update/add to filter watch tests
        test('on filter calls getTpaProviders and sets providers', async () => {
            // Arrange
            const zipCode = '78220';
            const initialMapZipCode = '88800';
            const { wrapper } = getMountedComponent({}, {
                zipCode,
                mapZipCode: initialMapZipCode,
                dataLoaded: true
            });
            const providers = { data: { shopProviders: ['some data', 'some more data'] } };
            useMainStore().getTpaProviders = jest.fn().mockImplementationOnce(() => (providers));
            const newFilter = 'new filter';

            // Act
            await wrapper.vm.$options.watch.filter.call(wrapper.vm, newFilter);

            // Assert
            expect(useMainStore().getTpaProviders).toBeCalled();
            expect(wrapper.vm.providers).toEqual(providers.data.shopProviders);
            expect(wrapper.vm.mapZipCode).toBe(zipCode);
        });
        describe('on filter', () => {
            test('calls getTpaProviders once and sets providers when dataLoaded is true', async () => {
                // Arrange
                const zipCode = '78220';
                const initialMapZipCode = '88800';
                const { wrapper } = getMountedComponent({}, {
                    zipCode,
                    mapZipCode: initialMapZipCode,
                    dataLoaded: true
                });
                const providers = { data: { shopProviders: ['some data', 'some more data'] } };
                useMainStore().getTpaProviders = jest.fn().mockImplementationOnce(() => (providers));
                const newFilter = 'new filter';

                // Act
                await wrapper.vm.$options.watch.filter.call(wrapper.vm, newFilter);

                // Assert
                expect(useMainStore().getTpaProviders).toBeCalled();
                expect(wrapper.vm.providers).toEqual(providers.data.shopProviders);
                expect(wrapper.vm.mapZipCode).toBe(zipCode);
            });
            test('never calls getTpaProviders and does not set providers when dataLoaded is false', async () => {
                // Arrange
                const zipCode = '78220';
                const initialMapZipCode = '88800';
                const { wrapper } = getMountedComponent({}, {
                    zipCode,
                    mapZipCode: initialMapZipCode,
                    dataLoaded: false
                });
                const providers = { data: { shopProviders: ['some data', 'some more data'] } };
                useMainStore().getTpaProviders = jest.fn().mockImplementationOnce(() => (providers));
                const newFilter = 'new filter';

                // Act
                await wrapper.vm.$options.watch.filter.call(wrapper.vm, newFilter);

                // Assert
                expect(useMainStore().getTpaProviders).not.toBeCalled();
                expect(wrapper.vm.providers).not.toEqual(providers.data.shopProviders);
                expect(wrapper.vm.mapZipCode).toBe(initialMapZipCode);
            });
        });
        // TODO confirm tests appropriate. Also should this method be async?
        describe('on providers', () => {
            test('does not update provider number when dataLoaded false', () => {
                // Arrange
                const initialValue = 1234;
                const { wrapper } = getMountedComponent({}, {
                    dataLoaded: false,
                    selectedProviderNumber: initialValue
                });
                const value = 'some other value';
                const newProviders = [{ providerNumber: value }];

                // Act
                wrapper.vm.$options.watch.providers.call(wrapper.vm, newProviders);

                // Assert
                expect(wrapper.vm.selectedProviderNumber).toBe(initialValue);
            });
            test.each([null, undefined, []])(
                'sets selected provider number to "" when there are no providers',
                (newProviders) => {
                    // Arrange
                    const { wrapper } = getMountedComponent({}, {
                        dataLoaded: true,
                        selectedProviderNumber: null
                    });

                    // Act
                    wrapper.vm.$options.watch.providers.call(wrapper.vm, newProviders);

                    // Assert
                    expect(wrapper.vm.selectedProviderNumber).toBe('');
                }
            );
            test('sets selected provider number to value of provider when there is one provider', () => {
                // Arrange
                const { wrapper } = getMountedComponent({}, {
                    dataLoaded: true,
                    selectedProviderNumber: null
                });
                const value = 'some value';
                const newProviders = [{ providerNumber: value }];

                // Act
                wrapper.vm.$options.watch.providers.call(wrapper.vm, newProviders);

                // Assert
                expect(wrapper.vm.selectedProviderNumber).toBe(value);
            });
            test('sets selected provider number to "" when there are more than one provider', () => {
                // Arrange
                const { wrapper } = getMountedComponent({}, {
                    dataLoaded: true,
                    selectedProviderNumber: null
                });
                const newProviders = [{ value: 'val1' }, { value: 'val2' }];

                // Act
                wrapper.vm.$options.watch.providers.call(wrapper.vm, newProviders);

                // Assert
                expect(wrapper.vm.selectedProviderNumber).toBe('');
            });
        });
        describe('selectedProviderNumber', () => {
            describe('does not call updateServiceLocation when', () => {
                test('dataLoaded is false', () => {
                    // Arrange
                    const providerNumber = 38447;
                    const { wrapper } = getMountedComponent({}, {
                        providers: [{
                            providerNumber,
                            address: {
                                streetAddress: '143 Average Lane',
                                city: 'Cambridge',
                                state: 'OH',
                                zipCode: '72983',
                                zipCodeCtu: '0390'
                            },
                            companyName: "Sally's Auto",
                            phoneNumber: '1234567890'
                        }],
                        dataLoaded: false
                    });

                    // Act
                    wrapper.vm.$options.watch.selectedProviderNumber.call(wrapper.vm, providerNumber);

                    // Assert
                    expect(wrapper.vm.mainStore.updateServiceLocation).not.toHaveBeenCalled();
                });
                test('providers list is null ', () => {
                    // Arrange
                    const { wrapper } = getMountedComponent({}, {
                        providers: null,
                        dataLoaded: true
                    });
                    const newProviderNumber = 11235;

                    // Act
                    wrapper.vm.$options.watch.selectedProviderNumber.call(wrapper.vm, newProviderNumber);

                    // Assert
                    expect(wrapper.vm.mainStore.updateServiceLocation).not.toHaveBeenCalled();
                });
                test('providers list is empty ', () => {
                    // Arrange
                    const { wrapper } = getMountedComponent({}, {
                        providers: [],
                        dataLoaded: true
                    });
                    const newProviderNumber = 11235;

                    // Act
                    wrapper.vm.$options.watch.selectedProviderNumber.call(wrapper.vm, newProviderNumber);

                    // Assert
                    expect(wrapper.vm.mainStore.updateServiceLocation).not.toHaveBeenCalled();
                });
                test('providers list does not contain match for provider number ', () => {
                    // Arrange
                    const { wrapper } = getMountedComponent({}, {
                        providers: [{
                            providerNumber: 8374,
                            address: {
                                streetAddress: '143 Average Lane',
                                city: 'Cambridge',
                                state: 'OH',
                                zipCode: '72983',
                                zipCodeCtu: '0390'
                            },
                            companyName: "Sally's Auto",
                            phoneNumber: '1234567890'
                        }],
                        dataLoaded: true
                    });
                    const newProviderNumber = 11235;

                    // Act
                    wrapper.vm.$options.watch.selectedProviderNumber.call(wrapper.vm, newProviderNumber);

                    // Assert
                    expect(wrapper.vm.mainStore.updateServiceLocation).not.toHaveBeenCalled();
                });
            });
            test('Calls updateServiceLocation when matching provider found.', () => {
                // Arrange
                const newProviderNumber = 11235;
                const streetAddress = '143 Average Lane';
                const city = 'Berlin';
                const state = 'MA';
                const zipCode = '12345';
                const zipCodeCtu = '0004';
                const companyName = "Sally's Auto";
                const phoneNumber = '3298479879';
                const provider = {
                    providerNumber: newProviderNumber,
                    address: {
                        streetAddress,
                        city,
                        state,
                        zipCode,
                        zipCodeCtu
                    },
                    companyName,
                    phoneNumber
                };
                const filter = '10 miles';
                const serviceZipCode = 10098;
                const { wrapper } = getMountedComponent({}, {
                    providers: [
                        provider,
                        { providerNumber: 328949832 }
                    ],
                    filter,
                    zipCode: serviceZipCode,
                    dataLoaded: true
                });

                // Act
                wrapper.vm.$options.watch.selectedProviderNumber.call(wrapper.vm, newProviderNumber);

                // Assert
                expect(wrapper.vm.mainStore.updateServiceLocation).toHaveBeenCalledTimes(1);
                expect(wrapper.vm.mainStore.updateServiceLocation).toHaveBeenCalledWith({
                    searchFilter: filter,
                    zipCode: serviceZipCode,
                    provider: {
                        providerNumber: newProviderNumber,
                        address: {
                            streetAddress,
                            city,
                            state,
                            zipCode,
                            zipCodeCtu
                        },
                        companyName,
                        phoneNumber
                    }
                });
            });
        });
    });
    describe('method', () => {
        test.each([
            ['address', 'city', 'ST', 'zip', 'Address, City, ST zip'],
            ['address', null, 'ST', 'zip', 'Address, ST zip'],
            ['address', 'city', null, 'zip', 'Address, City zip'],
            ['address', 'city', 'ST', null, 'Address, City, ST'],
            [null, null, null, null, '']
        ])(
            'getFullProviderAddress returns expected',
            (streetAddress, city, state, zipCode, expected) => {
                // Arrange
                const { wrapper } = getMountedComponent();
                const provider = {
                    address: {
                        streetAddress,
                        city,
                        state,
                        zipCode
                    }
                };

                // Act
                const result = wrapper.vm.getFullProviderAddress(provider);

                // Assert
                expect(result).toEqual(expected);
            }
        );
        test.each([
            ['address', 'city', 'ST', 'zip', 'Address'],
            ['address', null, 'ST', 'zip', 'Address'],
            ['address', 'city', null, 'zip', 'Address'],
            ['address', 'city', 'ST', null, 'Address'],
            [null, null, null, null, '']
        ])(
            'getProviderAddress returns expected',
            (streetAddress, city, state, zipCode, expected) => {
                // Arrange
                const { wrapper } = getMountedComponent();
                const provider = {
                    address: {
                        streetAddress,
                        city,
                        state,
                        zipCode
                    }
                };

                // Act
                const result = wrapper.vm.getProviderAddress(provider);

                // Assert
                expect(result).toEqual(expected);
            }
        );
        test.each([
            ['address', 'city', 'ST', 'zip', 'City, ST zip'],
            ['address', null, 'ST', 'zip', 'ST zip'],
            ['address', 'city', null, 'zip', 'City zip'],
            ['address', 'city', 'ST', null, 'City, ST'],
            [null, null, null, null, '']
        ])(
            'getProviderCityZipState returns expected',
            (streetAddress, city, state, zipCode, expected) => {
                // Arrange
                const { wrapper } = getMountedComponent();
                const provider = {
                    address: {
                        streetAddress,
                        city,
                        state,
                        zipCode
                    }
                };

                // Act
                const result = wrapper.vm.getProviderCityZipState(provider);

                // Assert
                expect(result).toEqual(expected);
            }
        );
        describe('getProviderButtonData', () => {
            test.each([null, undefined, {}])(
                'returns empty list when getTpaProviders returns no data',
                async (newProviders) => {
                    // Arrange
                    const { wrapper } = getMountedComponent();
                    useMainStore().getTpaProviders = jest.fn().mockImplementationOnce(() => (newProviders));

                    // Act
                    const result = await wrapper.vm.getProviderButtonData();

                    // Assert
                    expect(result).toEqual([]);
                }
            );
            test('returns expected when getTpaProviders returns data', async () => {
                // Arrange
                const { wrapper } = getMountedComponent();
                const providers = {
                    data: {
                        shopProviders: [{ companyName: 'foo' }]
                    }
                };
                useMainStore().getTpaProviders = jest.fn().mockImplementationOnce(() => (providers));

                // Act
                const result = await wrapper.vm.getProviderButtonData();

                // Assert
                expect(result).toEqual(providers.data.shopProviders);
            });
        });
        test('doNotSeeMyShopLinkClick invokes navigate method', () => {
            // Arrange
            const { wrapper } = getMountedComponent();

            // Act
            wrapper.vm.doNotSeeMyShopLinkClick();

            // Assert
            expect(wrapper.vm.$router.navigate).toHaveBeenCalled();
        });
        describe('searchClick', () => {
            test.each([null, undefined, {}])(
                'sets providers to empty list when no data returned from getProviders',
                async (newProviders) => {
                    // Arrange
                    const zipCode = '28331';
                    const initialMapZipCode = '10022';
                    const { wrapper } = getMountedComponent({}, {
                        zipCode,
                        mapZipCode: initialMapZipCode
                    });
                    useMainStore().getTpaProviders = jest.fn().mockImplementationOnce(() => (newProviders));

                    // Act
                    await wrapper.vm.searchClick();

                    // Assert
                    expect(wrapper.vm.providers).toEqual([]);
                    expect(wrapper.vm.mapZipCode).toEqual(zipCode);
                }
            );
            test('returns value from getProviders', async () => {
                // Arrange
                const zipCode = '12990';
                const initialMapZipCode = '00981';
                const { wrapper } = getMountedComponent({}, {
                    zipCode,
                    mapZipCode: initialMapZipCode
                });
                const shopProviders = [{ companyName: 'foo' }];
                useMainStore().getTpaProviders = jest.fn().mockImplementationOnce(() => ({
                    data: { shopProviders }
                }));

                // Act
                await wrapper.vm.searchClick();

                // Assert
                expect(wrapper.vm.providers).toEqual(shopProviders);
                expect(wrapper.vm.mapZipCode).toEqual(zipCode);
            });
        });
        test('backButtonAction invokes navigate method', () => {
            // Arrange
            const { wrapper } = getMountedComponent();

            // Act
            wrapper.vm.navigateBack();

            // Assert
            expect(wrapper.vm.$router.navigateWithSpinner).toHaveBeenCalled();
        });
        describe('forwardButtonAction', () => {
            test('invokes navigate method with safelite shop scenario when selectedProviderIsSafeliteShop true', async () => {
                // Arrange
                const { wrapper } = getMountedComponent();
                const providerNumber = '1109';
                await wrapper.setData({
                    selectedProviderNumber: providerNumber,
                    providers: [{
                        providerNumber,
                        isSafeliteShop: true
                    }]
                });

                // Act
                wrapper.vm.forwardButtonAction();

                // Assert
                expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(navigationScenarios.CLICKED_FORWARD_WITH_SAFELITE_SHOP, undefined);
            });
            test('invokes navigate method with non safelite shop scenario when selectedProviderIsSafeliteShop false', async () => {
                // Arrange
                const { wrapper } = getMountedComponent();
                const providerNumber = '928';
                await wrapper.setData({
                    selectedProviderNumber: providerNumber,
                    providers: [{
                        providerNumber,
                        isSafeliteShop: false
                    }]
                });

                // Act
                wrapper.vm.forwardButtonAction();

                // Assert
                expect(wrapper.vm.$router.navigate).toHaveBeenCalledWith(
                    navigationScenarios.CLICKED_FORWARD_WITH_NON_SAFELITE_SHOP,
                    undefined
                );
            });
        });
        describe('getCustomValueFromString', () => {
            test('returns radius in miles value if "radiusInMiles"', () => {
                // Arrange
                const { wrapper } = getMountedComponent();
                const str = 'radiusInMiles';

                // Act
                const result = wrapper.vm.getCustomValueFromString(str);

                // Assert
                expect(result).toBe(0);
            });
            test('returns radius in miles value if not "radiusInMiles"', () => {
                // Arrange
                const { wrapper } = getMountedComponent();
                const str = 'some other string';

                // Act
                const result = wrapper.vm.getCustomValueFromString(str);

                // Assert
                expect(result).toBeNull();
            });
        });
        describe('getShopButtonDataFromProvider', () => {
            test.each([null, undefined, {}])(
                'returns empty list given parameter with no provider',
                (provider) => {
                    // Arrange
                    const wrapper = shallowMount(tpaSearch, getMountOptions());
                    const expectedResult = {
                        buttonLabel: '',
                        buttonLabelSubCopy: '',
                        buttonBodyCopy: '<br>',
                        value: ''
                    };

                    // Act
                    const result = wrapper.vm.getShopButtonDataFromProvider(provider);

                    // Assert
                    expect(result).toEqual(expectedResult);
                }
            );
            test('returns expected given provider', () => {
                // Arrange
                const wrapper = shallowMount(tpaSearch, getMountOptions());
                const provider = {
                    companyName: 'Shop Auto Glass',
                    phoneNumber: '740-555-1234',
                    distanceInMiles: 1.2345,
                    providerNumber: '232209',
                    address: {
                        streetAddress: '123 Lane Ave',
                        city: 'New York',
                        state: 'NY',
                        zipCode: '99230'
                    }
                };
                const expectedResult = {
                    buttonLabel: 'Shop Auto Glass',
                    buttonLabelSubCopy: '1.2 mi',
                    buttonBodyCopy: '123 Lane Ave, New York, NY 99230<br>740-555-1234',
                    value: '232209'
                };

                // Act
                const result = wrapper.vm.getShopButtonDataFromProvider(provider);

                // Assert
                expect(result).toEqual(expectedResult);
            });
            describe('returns result with button label', () => {
                test.each(['', undefined, null])(
                    'equal to empty string when name is empty',
                    (companyName) => {
                        // Arrange
                        const wrapper = shallowMount(tpaSearch, getMountOptions());
                        const provider = { companyName };

                        // Act
                        const result = wrapper.vm.getShopButtonDataFromProvider(provider);

                        // Assert
                        expect(result.buttonLabel).toEqual('');
                    }
                );
                test('returns provider name when exists', () => {
                    // Arrange
                    const wrapper = shallowMount(tpaSearch, getMountOptions());
                    const companyName = 'Some Shop Name';
                    const provider = { companyName };

                    // Act
                    const result = wrapper.vm.getShopButtonDataFromProvider(provider);

                    // Assert
                    expect(result.buttonLabel).toEqual(companyName);
                });
            });
            describe('returns result with button label sub copy', () => {
                test.each([null, undefined, 'random string'])(
                    'as empty string when distanceInMiles is not a number',
                    (distanceInMiles) => {
                        // Arrange
                        const wrapper = shallowMount(tpaSearch, getMountOptions());
                        const provider = { distanceInMiles };

                        // Act
                        const result = wrapper.vm.getShopButtonDataFromProvider(provider);

                        // Assert
                        expect(result.buttonLabelSubCopy).toEqual('');
                    }
                );
                test.each([[0, 0], [0, 0.000], [-7.89, -7.9], [109, 109], [1.234, 1.2], [2.99, 3]])(
                    'displays expected distance value',
                    (distanceInMiles, displayedDistance) => {
                        // Arrange
                        const wrapper = shallowMount(tpaSearch, getMountOptions());
                        const provider = { distanceInMiles };
                        const expectedSubCopy = `${displayedDistance} mi`;

                        // Act
                        const result = wrapper.vm.getShopButtonDataFromProvider(provider);

                        // Assert
                        expect(result.buttonLabelSubCopy).toEqual(expectedSubCopy);
                    }
                );
            });
            test('returns result with button body copy showing expected address and phone number', () => {
                // Arrange
                const wrapper = shallowMount(tpaSearch, getMountOptions());
                const provider = {
                    phoneNumber: '123-555-0099',
                    address: {
                        streetAddress: '434 Up Down Blvd',
                        city: 'San Francisco',
                        state: 'CA',
                        zipCode: '90887'
                    }
                };
                const expected = '434 Up Down Blvd, San Francisco, CA 90887<br>123-555-0099';

                // Act
                const result = wrapper.vm.getShopButtonDataFromProvider(provider);

                // Assert
                expect(result.buttonBodyCopy).toEqual(expected);
            });
            describe('returns result with value', () => {
                test.each(['', undefined, null])(
                    'equal to empty string when providerNumber is empty',
                    (providerNumber) => {
                        // Arrange
                        const wrapper = shallowMount(tpaSearch, getMountOptions());
                        const provider = { providerNumber };

                        // Act
                        const result = wrapper.vm.getShopButtonDataFromProvider(provider);

                        // Assert
                        expect(result.value).toEqual('');
                    }
                );
                test('returns provider number when exists', () => {
                    // Arrange
                    const wrapper = shallowMount(tpaSearch, getMountOptions());
                    const providerNumber = '123391';
                    const provider = { providerNumber };

                    // Act
                    const result = wrapper.vm.getShopButtonDataFromProvider(provider);

                    // Assert
                    expect(result.value).toEqual(providerNumber);
                });
            });
        });
    });
    describe('before route enter', () => {
        test('when service location zipCode set in store, it is used', async () => {
            // Arrange
            const { wrapper } = getMountedComponent();
            const customerZipCode = '18394';
            const serviceZipCode = '43982';
            useMainStore().order.customer.address.zipCode = customerZipCode;
            useMainStore().order.serviceLocation.zipCode = serviceZipCode;

            // Act
            await tpaSearch.beforeRouteEnter.call(
                wrapper.vm,
                { query: { issPage: 'tpa-search' } },
                undefined,
                (c) => c(wrapper.vm)
            );

            await wrapper.vm.$nextTick();
            await wrapper.vm.$nextTick();

            // Assert
            expect(wrapper.vm.zipCode).toBe(serviceZipCode);
        });
        test('when service location zipCode not set in store, customer zipCode used', async () => {
            // Arrange
            const { wrapper } = getMountedComponent();
            const customerZipCode = '18394';
            useMainStore().order.customer.address.zipCode = customerZipCode;
            useMainStore().order.serviceLocation.zipCode = null;

            // Act
            await tpaSearch.beforeRouteEnter.call(
                wrapper.vm,
                { query: { issPage: 'tpa-search' } },
                undefined,
                (c) => c(wrapper.vm)
            );

            await wrapper.vm.$nextTick();
            await wrapper.vm.$nextTick();

            // Assert
            expect(wrapper.vm.zipCode).toBe(customerZipCode);
        });
        test('when search filter set in store, expected filter and provider number returned', async () => {
            // Arrange
            const { wrapper } = getMountedComponent();
            const customerZipCode = '18394';
            const searchFilter = '25 miles';
            const providerNumber = 749321;
            useMainStore().order.customer.address.zipCode = customerZipCode;
            useMainStore().order.serviceLocation.zipCode = null;
            useMainStore().order.serviceLocation.searchFilter = searchFilter;
            useMainStore().order.serviceLocation.provider.providerNumber = providerNumber;
            const providers = [{ companyName: 'some provider' }];
            const expectedRadius = 25;
            useMainStore().getTpaProviders = jest.fn().mockImplementation((_, radius) =>
                ({ data: { shopProviders: radius === expectedRadius ? providers : [] } }));

            // Act
            await tpaSearch.beforeRouteEnter.call(
                wrapper.vm,
                { query: { issPage: 'tpa-search' } },
                undefined,
                (c) => c(wrapper.vm)
            );

            await wrapper.vm.$nextTick();
            await wrapper.vm.$nextTick();

            // Assert
            expect(wrapper.vm.filter).toBe(searchFilter);
            expect(wrapper.vm.providers).toEqual(providers);
            expect(wrapper.vm.selectedProviderNumber).toBe(providerNumber);
            expect(useMainStore().getTpaProviders).toBeCalledTimes(1);
            expect(useMainStore().getTpaProviders).toBeCalledWith(customerZipCode, expectedRadius);
        });
        test('when providers exist at 15 mile radius, filter is set to "15 miles" and providers set to expected', async () => {
            // Arrange
            const { wrapper } = getMountedComponent();
            const zipCode = '18394';
            useMainStore().order.customer.address.zipCode = '00001';
            useMainStore().order.serviceLocation.zipCode = zipCode;
            useMainStore().order.serviceLocation.searchFilter = null;
            const providers = [{ companyName: 'provider' }];
            useMainStore().getTpaProviders = jest.fn().mockImplementation((_, radius) =>
                ({ data: { shopProviders: radius === 15 ? providers : [] } }));
            const expectedFilter = '15 miles';

            // Act
            await tpaSearch.beforeRouteEnter.call(
                wrapper.vm,
                { query: { issPage: 'tpa-search' } },
                undefined,
                (c) => c(wrapper.vm)
            );

            await wrapper.vm.$nextTick();
            await wrapper.vm.$nextTick();

            // Assert
            expect(wrapper.vm.zipCode).toBe(zipCode);
            expect(wrapper.vm.filter).toBe(expectedFilter);
            expect(wrapper.vm.providers).toEqual(providers);
            expect(wrapper.vm.selectedProviderNumber).toBeNull();
            expect(useMainStore().getTpaProviders).toBeCalledTimes(1);
        });
        test('when providers exist at 25 mile radius, filter is set to "25 miles" and providers set to expected', async () => {
            // Arrange
            const { wrapper } = getMountedComponent();
            const zipCode = '18394';
            useMainStore().order.customer.address.zipCode = '00001';
            useMainStore().order.serviceLocation.zipCode = zipCode;
            useMainStore().order.serviceLocation.searchFilter = null;
            const providers = [{ companyName: 'provider' }];
            useMainStore().getTpaProviders = jest.fn().mockImplementation((_, radius) =>
                ({ data: { shopProviders: radius === 25 ? providers : [] } }));
            const expectedFilter = '25 miles';

            // Act
            await tpaSearch.beforeRouteEnter.call(
                wrapper.vm,
                { query: { issPage: 'tpa-search' } },
                undefined,
                (c) => c(wrapper.vm)
            );

            await wrapper.vm.$nextTick();
            await wrapper.vm.$nextTick();

            // Assert
            expect(wrapper.vm.zipCode).toBe(zipCode);
            expect(wrapper.vm.filter).toBe(expectedFilter);
            expect(wrapper.vm.providers).toEqual(providers);
            expect(wrapper.vm.selectedProviderNumber).toBeNull();
            expect(useMainStore().getTpaProviders).toBeCalledTimes(2);
        });
        test('when providers exist at 50 mile radius but not 25, filter is set to "50 miles" and providers set to expected', async () => {
            // Arrange
            const { wrapper } = getMountedComponent();
            const zipCode = '18394';
            useMainStore().order.customer.address.zipCode = '00001';
            useMainStore().order.serviceLocation.zipCode = zipCode;
            useMainStore().order.serviceLocation.searchFilter = null;
            const providers = [{ companyName: 'provider' }];
            useMainStore().getTpaProviders = jest.fn().mockImplementation((_, radius) =>
                ({ data: { shopProviders: radius === 50 ? providers : [] } }));
            const expectedFilter = '50 miles';

            // Act
            await tpaSearch.beforeRouteEnter.call(
                wrapper.vm,
                { query: { issPage: 'tpa-search' } },
                undefined,
                (c) => c(wrapper.vm)
            );

            await wrapper.vm.$nextTick();
            await wrapper.vm.$nextTick();

            // Assert
            expect(wrapper.vm.zipCode).toBe(zipCode);
            expect(wrapper.vm.filter).toBe(expectedFilter);
            expect(wrapper.vm.providers).toEqual(providers);
            expect(wrapper.vm.selectedProviderNumber).toBeNull();
            expect(useMainStore().getTpaProviders).toBeCalledTimes(3);
        });
        test(
            'when providers exist at 100 mile radius but not 50 or 25, filter is set to "100 miles" and providers set to expected',
            async () => {
                // Arrange
                const { wrapper } = getMountedComponent();
                const zipCode = '18394';
                useMainStore().order.customer.address.zipCode = zipCode;
                useMainStore().order.serviceLocation.zipCode = null;
                useMainStore().order.serviceLocation.searchFilter = null;
                const providers = [{ companyName: 'provider' }];
                useMainStore().getTpaProviders = jest.fn().mockImplementation((_, radius) =>
                    ({ data: { shopProviders: radius === 100 ? providers : [] } }));
                const expectedFilter = '100 miles';

                // Act
                await tpaSearch.beforeRouteEnter.call(
                    wrapper.vm,
                    { query: { issPage: 'tpa-search' } },
                    undefined,
                    (c) => c(wrapper.vm)
                );

                await wrapper.vm.$nextTick();
                await wrapper.vm.$nextTick();

                // Assert
                expect(wrapper.vm.zipCode).toBe(zipCode);
                expect(wrapper.vm.filter).toBe(expectedFilter);
                expect(wrapper.vm.providers).toEqual(providers);
                expect(wrapper.vm.selectedProviderNumber).toBeNull();
                expect(useMainStore().getTpaProviders).toBeCalledTimes(4);
            }
        );
        test(
            'when no providers exist at 100, 50, or 25 mile radius, filter is set to "100 miles" and providers set to empty list',
            async () => {
                // Arrange
                const { wrapper } = getMountedComponent();
                const zipCode = '18394';
                useMainStore().order.customer.address.zipCode = '00001';
                useMainStore().order.serviceLocation.zipCode = zipCode;
                useMainStore().order.serviceLocation.searchFilter = null;
                useMainStore().getTpaProviders = jest.fn().mockImplementation(() => ([]));
                const expectedFilter = '100 miles';

                // Act
                await tpaSearch.beforeRouteEnter.call(
                    wrapper.vm,
                    { query: { issPage: 'tpa-search' } },
                    undefined,
                    (c) => c(wrapper.vm)
                );

                await wrapper.vm.$nextTick();
                await wrapper.vm.$nextTick();

                // Assert
                expect(wrapper.vm.zipCode).toBe(zipCode);
                expect(wrapper.vm.filter).toBe(expectedFilter);
                expect(wrapper.vm.providers).toEqual([]);
                expect(wrapper.vm.selectedProviderNumber).toBeNull();
                expect(useMainStore().getTpaProviders).toBeCalledTimes(4);
            }
        );
    });
});
