// Components
import orderConfirmation from '@/layouts/order-confirmation/order-confirmation.vue';

// Supporting Files
import { getMountOptions } from '@/helpers/unit-test-helper.js';
import { useMainStore } from '@/store/index.js';
import settleAllPromises from '@/helpers/layout-helper.js';
import { fetchCmsContentForPage, getStringWithCustomValues, processIfStatements } from '@/helpers/cms-content-helper';
import { mount } from '@vue/test-utils';
import { createTestingPinia } from '@pinia/testing';
import { nextTick } from 'vue';
import coverageStatuses from '@/constants/coverage-statuses';
import coverageType from '@/constants/coverage-type';
import { deepClone } from '@/helpers/object-helper';
import { AppointmentTypeStrings } from '@/constants/schedule-constants';
import { paymentMethods } from '@/constants/payment-method-constants';

jest.mock('@/helpers/layout-helper.js', () => jest.fn());

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

const mockMixin = {
    methods: {
        getCmsContent: jest.fn(),
        setCmsContent: jest.fn()
    }
};

const footerStub = {
    render: () => {},
    methods: {
        updateButtonText: jest.fn()
    }
};

const headerStub = {
    render: () => {}
};

const addToCalendarStub = {
    render: () => {}
};

const initialStore = {
    order: {
        schedule: {
            date: '2024-03-01',
            startTime: '09:00',
            endTime: '10:00',
            jobMinMinutes: 60,
            jobMaxMinutes: 90
        },
        serviceLocation: {
            address: '123 Test Way',
            address2: '#1',
            city: 'Mesa',
            state: 'AZ',
            zipCode: '12345',
            appointmentType: 'Inshop',
            provider: {
                address: {
                    streetAddress: '123 Safelite Street',
                    city: 'Mesa',
                    state: 'AZ',
                    zipCode: '12345'
                }
            }
        },
        insuranceCoverage: {
            coverageStatus: coverageStatuses.VERIFIED,
            coverageType: coverageType.Deductible
        },
        payment: {
            isInsurance: true,
            paymentMethod: paymentMethods.PAY_AT_TIME_OF_SERVICE
        },
        contactInfo: {
            firstName: 'Test',
            lastName: 'Test',
            servicePhone: '111-111-1111',
            emailAddress: 'test@email.com'
        },
        damage: {
            isRepair: false
        },
        currentDeductible: {
            replace: 100,
            repair: 0
        }
    }
};

const sessionStorage = {
    schedule: {
        date: '2024-03-01',
        startTime: '09:00',
        endTime: '10:00',
        jobMinMinutes: 60,
        jobMaxMinutes: 90
    },
    serviceLocation: {
        address: '123 Test Way',
        address2: '#1',
        city: 'Mesa',
        state: 'AZ',
        zipCode: '12345',
        appointmentType: 'Inshop',
        provider: {
            address: {
                streetAddress: '123 Safelite Street',
                city: 'Mesa',
                state: 'AZ',
                zipCode: '12345'
            }
        }
    },
    insuranceCoverage: {
        coverageStatus: coverageStatuses.VERIFIED,
        coverageType: coverageType.Deductible
    },
    payment: {
        isPayInAdvance: false
    },
    lineItems: {
        vaps: []
    },
    policy: {},
    damage: {
        isRepair: false
    },
    vehicle: {
        year: 2000,
        make: 'Honda',
        model: 'Civic'
    },
    customer: {},
    customerPortalLoginToken: 'token',
    currentDeductible: {
        replace: 100,
        repair: 0
    }
};

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

    mountOptions.global.stubs = {
        siteFooter: footerStub,
        siteHeader: headerStub,
        addToCalendar: addToCalendarStub
    };

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

    mountOptions.global.mixins[0].methods.getSettingValue = jest.fn(() => 'false');
    mountOptions.global.plugins = [testingPinia];
    mountOptions.mixins = [mixin];
    mountOptions.data = () => (
        initialData
    );

    const apiResponses = {
        supportingItems: []
    };
    const apiPromise = Promise.resolve(apiResponses);
    settleAllPromises.mockImplementation(() => apiPromise);
    fetchCmsContentForPage.mockImplementation(() => Promise.resolve());

    const wrapper = mount(orderConfirmation, mountOptions);
    return { wrapper };
}

describe('OrderConfirmation.vue', () => {
    afterEach(() => {
        jest.resetAllMocks();
    });
    describe('Page pre-requisites', () => {
        test('If submitted order saved to store, page pre-reqs return true', async () => {
            // Arrange
            const mockStoreActions = () => {
                useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => sessionStorage);
            };
            const { wrapper } = getMountedComponent(initialStore, {}, mockStoreActions);

            // Act
            const arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
            await nextTick();

            // Assert
            expect(arePagePrerequisitesValid).toBe(true);
        });
    });
    describe('Rendering', () => {
        let wrapper;
        beforeEach(() => {
            const mockStoreActions = () => {
                useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => sessionStorage);
            };
            wrapper = getMountedComponent({}, {}, mockStoreActions).wrapper;
        });
        test('Should render Site Header', () => {
            // Act
            const siteHeader = wrapper.findComponent(headerStub);

            // Assert
            expect(siteHeader.exists()).toBe(true);
        });
        test('If Advanced flow, should display Site Footer', () => {
            // Arrange
            const mockStoreActions = () => {
                useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => sessionStorage);
            };
            const testStore = {
                order: {
                    schedule: {
                        date: '2019-01-01',
                        startTime: '09:00'
                    },
                    serviceLocation: {
                        appointmentType: 'Inshop'
                    }
                },
                issConfig: {
                    successReturnURL: 'testURL'
                }
            };
            wrapper = getMountedComponent(testStore, {}, mockStoreActions).wrapper;

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

            // Assert
            expect(siteFooter.exists()).toBe(true);
        });
        test('If Essential flow, should not display Site Footer', () => {
            // Act
            const siteFooter = wrapper.findComponent({ ref: 'siteFooter' });

            // Assert
            expect(siteFooter.isVisible()).toBe(false);
        });
    });
    describe('Navigation', () => {
        test('If Advanced flow, forward button action navigates to carrier URL', () => {
            // Arrange
            window.sessionStorage.setItem('submittedOrder', JSON.stringify(sessionStorage));
            const mockStoreActions = () => {
                useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => sessionStorage);
            };
            const carrierReturnUrl = 'testURL';
            const testStore = {
                order: {
                    schedule: {
                        date: '2019-01-01',
                        startTime: '09:00'
                    },
                    serviceLocation: {
                        appointmentType: 'Inshop'
                    }
                },
                issConfig: {
                    successReturnURL: carrierReturnUrl
                }
            };
            const { wrapper } = getMountedComponent(testStore, {}, mockStoreActions);

            // Act
            wrapper.vm.forwardButtonAction();

            // Assert
            expect(wrapper.vm.$router.navigateToExternalUrl).toHaveBeenCalledWith(carrierReturnUrl);
        });
    });
    describe('Computed properties', () => {
        describe('customValueMap', () => {
            test.each([
                'inShopAppointment',
                'dropOffAppointment',
                'vehicleYear',
                'vehicleMake',
                'vehicleModel',
                'address',
                'inShopDuration',
                'email',
                'CUSTOMER_PORTAL_URL',
                'CUSTOMER_PORTAL_LOGIN_TOKEN'
            ])('contains key %p', (key) => {
                // Arrange
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => sessionStorage);
                };
                const { wrapper } = getMountedComponent(initialStore, {}, mockStoreActions);

                // Act
                const keyExists = key in wrapper.vm.customValueMap;

                // Assert
                expect(keyExists).toBeTruthy();
            });
            test('returns expected vehicle info', () => {
                // Arrange
                const order = deepClone(sessionStorage);
                const year = 1998;
                const make = 'Toyota';
                const model = 'Cruse';
                order.vehicle = {
                    year, make, model
                };
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent(initialStore, {}, mockStoreActions);

                // Act
                const actualYear = wrapper.vm.customValueMap.vehicleYear;
                const actualMake = wrapper.vm.customValueMap.vehicleMake;
                const actualModel = wrapper.vm.customValueMap.vehicleModel;

                // Assert
                expect(actualYear).toBe(year);
                expect(actualMake).toBe(make);
                expect(actualModel).toBe(model);
            });
            test('returns expected customer email', () => {
                // Arrange
                const order = deepClone(sessionStorage);
                const emailAddress = 'email@google.com';
                order.customer.emailAddress = emailAddress;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent(initialStore, {}, mockStoreActions);

                // Act
                const actualEmail = wrapper.vm.customValueMap.email;

                // Assert
                expect(actualEmail).toBe(emailAddress);
            });
        });
        describe('confirmationEmailText', () => {
            const greaterId = '&gt;';
            const lessId = '&lt;';
            test.each([
                ['test', 'test'],
                [`te${greaterId}st`, 'te>st'],
                [`${greaterId}test${greaterId}`, '>test>'],
                [`te${greaterId}st ${greaterId}`, 'te>st >'],
                [`${lessId} test`, '< test'],
                [`t${lessId}e${lessId}st`, 't<e<st'],
                [`${greaterId}t${lessId}${lessId}e st${greaterId}`, '>t<<e st>']
            ])('given %p returned from cms, returns %p', (rawCms, expected) => {
                // Arrange
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => sessionStorage);
                };
                getStringWithCustomValues.mockReturnValue(rawCms);
                const { wrapper } = getMountedComponent(initialStore, {}, mockStoreActions);

                // Act
                const text = wrapper.vm.confirmationEmailText;

                // Assert
                expect(text).toBe(expected);
            });
        });
        describe('appointmentTimeText', () => {
            test.each([
                ['Between 9 AM - 10 AM', '09:00', '10:00'],
                ['Between 1 PM - 5 PM', '13:00', '17:00'],
                ['Between 8:30 AM - 3 PM', '08:30', '15:00'],
                ['Between 1 AM - 2 AM', '01:00', '02:00'],
                ['Between 12 AM - 2 AM', '00:00', '02:00'],
                ['Between 12 PM - 2 AM', '12:00', '02:00'],
                ['Between 11 PM - 12 AM', '23:00', '00:00']
            ])('should return Mobile time in expected format "%p" when start time "%p" and end time "%p"', (expected, startTime, endTime) => {
                // Arrange
                const order = deepClone(sessionStorage);
                order.schedule.startTime = startTime;
                order.schedule.endTime = endTime;
                order.serviceLocation.appointmentType = AppointmentTypeStrings.MOBILE;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);

                // Act
                const testValue = wrapper.vm.appointmentTimeText;

                // Assert
                expect(testValue).toEqual(expected);
            });
            test.each([
                ['09:00', '10:00'],
                ['13:00', '17:00'],
                ['08:30', '15:00'],
                ['01:00', '02:00']
            ])('should return Drop off time in same format regardless of start/end time', (startTime, endTime) => {
                // Arrange
                const order = deepClone(sessionStorage);
                order.schedule.startTime = startTime;
                order.schedule.endTime = endTime;
                order.serviceLocation.appointmentType = AppointmentTypeStrings.DROP_OFF;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);

                // Act
                const testValue = wrapper.vm.appointmentTimeText;

                // Assert
                expect(testValue).toEqual('Drop off before 9:30 AM');
            });
            test.each([
                ['at 9:00 AM', '09:00', '10:00'],
                ['at 1:00 PM', '13:00', '17:00'],
                ['at 8:30 AM', '08:30', '15:00'],
                ['at 1:00 AM', '01:00', '02:00'],
                ['at 12:00 AM', '00:00', '02:00'],
                ['at 12:00 PM', '12:00', '02:00']
            ])('should return In Shop time in expected format "%p" when start time "%p"', (expected, startTime, endTime) => {
                // Arrange
                const order = deepClone(sessionStorage);
                order.schedule.startTime = startTime;
                order.schedule.endTime = endTime;
                order.serviceLocation.appointmentType = AppointmentTypeStrings.IN_SHOP;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);

                // Act
                const testValue = wrapper.vm.appointmentTimeText;

                // Assert
                expect(testValue).toEqual(expected);
            });
        });
        describe('appointmentLocation', () => {
            const order = deepClone(sessionStorage);
            order.serviceLocation = {
                address: '123 Service Rd.',
                address2: 'Box 4',
                city: 'Columbus',
                state: 'OH',
                zipCode: '12345',
                provider: {
                    address: {
                        streetAddress: '304 provider Ln.',
                        city: 'pittsburg',
                        state: 'PA',
                        zipCode: '16001'
                    }
                }
            };
            const expectedServiceLocation = '123 Service Rd., Box 4,<br/> Columbus, OH 12345';
            const expectedShopLocation = '304 Provider Ln.,<br/> Pittsburg, PA 16001';
            test.each([
                AppointmentTypeStrings.MOBILE,
                AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP
            ])('mobile location %p returns service location', (type) => {
                // Arrange
                order.serviceLocation.appointmentType = type;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);

                // Act
                const text = wrapper.vm.appointmentLocation;

                // Assert
                expect(text).toBe(expectedServiceLocation);
            });
            test.each([
                AppointmentTypeStrings.IN_SHOP,
                AppointmentTypeStrings.DROP_OFF
            ])('%p appointment location returns shop location', (type) => {
                // Arrange
                order.serviceLocation.appointmentType = type;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);

                // Act
                const text = wrapper.vm.appointmentLocation;

                // Assert
                expect(text).toBe(expectedShopLocation);
            });
            test.each(['turtle', undefined, null])('unknown appointment type %p returns null', (type) => {
                // Arrange
                order.serviceLocation.appointmentType = type;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);

                // Act
                const text = wrapper.vm.appointmentLocation;

                // Assert
                expect(text).toBeNull();
            });
        });
        describe('serviceLocationFullAddress', () => {
            const order = deepClone(sessionStorage);
            beforeEach(() => {
                order.serviceLocation = {
                    address: '123 Service Rd.',
                    address2: 'Box 4',
                    city: 'Columbus',
                    state: 'OH',
                    zipCode: '12345',
                    provider: {
                        address: {
                            streetAddress: '304 provider Ln.',
                            city: 'pittsburg',
                            state: 'PA',
                            zipCode: '16001'
                        }
                    }
                };
            });
            test('returns expected when all defined', () => {
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);
                const expected = '123 Service Rd., Box 4,<br/> Columbus, OH 12345';

                // Act
                const text = wrapper.vm.serviceLocationFullAddress;

                // Assert
                expect(text).toBe(expected);
            });
            test('returns expected when address null', () => {
                order.serviceLocation.address = null;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);
                const expected = ', Box 4,<br/> Columbus, OH 12345';

                // Act
                const text = wrapper.vm.serviceLocationFullAddress;

                // Assert
                expect(text).toBe(expected);
            });
            test('returns expected when address2 null', () => {
                order.serviceLocation.address2 = null;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);
                const expected = '123 Service Rd., <br/> Columbus, OH 12345';

                // Act
                const text = wrapper.vm.serviceLocationFullAddress;

                // Assert
                expect(text).toBe(expected);
            });
            test('returns expected when city null', () => {
                order.serviceLocation.city = null;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);
                const expected = '123 Service Rd., Box 4,<br/> , OH 12345';

                // Act
                const text = wrapper.vm.serviceLocationFullAddress;

                // Assert
                expect(text).toBe(expected);
            });
            test('returns expected when state null', () => {
                order.serviceLocation.state = null;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);
                const expected = '123 Service Rd., Box 4,<br/> Columbus,  12345';

                // Act
                const text = wrapper.vm.serviceLocationFullAddress;

                // Assert
                expect(text).toBe(expected);
            });
            test('returns expected when zipCode null', () => {
                order.serviceLocation.zipCode = null;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);
                const expected = '123 Service Rd., Box 4,<br/> Columbus, OH ';

                // Act
                const text = wrapper.vm.serviceLocationFullAddress;

                // Assert
                expect(text).toBe(expected);
            });
            test('returns expected when all null', () => {
                order.serviceLocation.address = null;
                order.serviceLocation.address2 = null;
                order.serviceLocation.city = null;
                order.serviceLocation.state = null;
                order.serviceLocation.zipCode = null;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);
                const expected = ', <br/> ,  ';

                // Act
                const text = wrapper.vm.serviceLocationFullAddress;

                // Assert
                expect(text).toBe(expected);
            });
        });
        describe('providerFullAddress', () => {
            const order = deepClone(sessionStorage);
            beforeEach(() => {
                order.serviceLocation = {
                    address: '123 Service Rd.',
                    address2: 'Box 4',
                    city: 'Columbus',
                    state: 'OH',
                    zipCode: '12345',
                    provider: {
                        address: {
                            streetAddress: '304 provider Ln.',
                            city: 'pittsburg',
                            state: 'PA',
                            zipCode: '16001'
                        }
                    }
                };
            });
            test('returns expected when all properties defined', () => {
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);
                const expected = '304 Provider Ln.,<br/> Pittsburg, PA 16001';

                // Act
                const text = wrapper.vm.providerFullAddress;

                // Assert
                expect(text).toBe(expected);
            });
            test('returns expected when streetAddress null', () => {
                order.serviceLocation.provider.address.streetAddress = null;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);
                const expected = '';

                // Act
                const text = wrapper.vm.providerFullAddress;

                // Assert
                expect(text).toBe(expected);
            });
            test('returns expected when city null', () => {
                order.serviceLocation.provider.address.city = null;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);
                const expected = '304 Provider Ln.,<br/> , PA 16001';

                // Act
                const text = wrapper.vm.providerFullAddress;

                // Assert
                expect(text).toBe(expected);
            });
            test('returns expected when state null', () => {
                order.serviceLocation.provider.address.state = null;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);
                const expected = '304 Provider Ln.,<br/> Pittsburg,  16001';

                // Act
                const text = wrapper.vm.providerFullAddress;

                // Assert
                expect(text).toBe(expected);
            });
            test('returns expected when zipCode null', () => {
                order.serviceLocation.provider.address.zipCode = null;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);
                const expected = '304 Provider Ln.,<br/> Pittsburg, PA ';

                // Act
                const text = wrapper.vm.providerFullAddress;

                // Assert
                expect(text).toBe(expected);
            });
            test('returns expected when all null', () => {
                order.serviceLocation.provider.address.streetAddress = null;
                order.serviceLocation.provider.address.city = null;
                order.serviceLocation.provider.address.state = null;
                order.serviceLocation.provider.address.zipCode = null;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);
                const expected = '';

                // Act
                const text = wrapper.vm.providerFullAddress;

                // Assert
                expect(text).toBe(expected);
            });
        });
        describe('appointmentWordingText', () => {
            const mobileWording = 'Mobile wording';
            const nonMobileWording = 'Non mobile wording';
            const mobileWidget = 'MobileWordingWidget';
            const dropOffAndInShopWidget = 'DropOffAndInShopWordingWidget';
            let mixin;
            beforeEach(() => {
                processIfStatements.mockImplementation((content) => content);
                getStringWithCustomValues.mockImplementation((content, _) => content);
                mixin = {
                    methods: {
                        getCmsContent: jest.fn().mockImplementation((widget, _) => {
                            if (widget === mobileWidget) {
                                return mobileWording;
                            }
                            if (widget === dropOffAndInShopWidget) {
                                return nonMobileWording;
                            }
                            return '';
                        }),
                        setCmsContent: jest.fn()
                    }
                };
            });
            test.each([
                [AppointmentTypeStrings.MOBILE, mobileWording],
                [AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP, mobileWording],
                [AppointmentTypeStrings.DROP_OFF, nonMobileWording],
                [AppointmentTypeStrings.IN_SHOP, nonMobileWording],
                ['unknown', null],
                [null, null],
                [undefined, null]
            ])('appointment type %p returns wording %p', (type, wording) => {
                // Arrange
                const order = deepClone(sessionStorage);
                order.serviceLocation.appointmentType = type;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };

                const { wrapper } = getMountedComponent({}, {}, mockStoreActions, mixin);

                // Act
                const testValue = wrapper.vm.appointmentWordingText;

                // Assert
                expect(testValue).toEqual(wording);
            });
        });
        describe('appointmentWordingText2', () => {
            const mobileWording = 'Mobile wording';
            const nonMobileWording = 'Non mobile wording';
            const mobileWidget = 'MobileWordingWidget';
            const dropOffAndInShopWidget = 'DropOffAndInShopWordingWidget';
            let mixin;
            beforeEach(() => {
                processIfStatements.mockImplementation((content) => content);
                getStringWithCustomValues.mockImplementation((content, _) => content);
                mixin = {
                    methods: {
                        getCmsContent: jest.fn().mockImplementation((widget, _) => {
                            if (widget === mobileWidget) {
                                return mobileWording;
                            }
                            if (widget === dropOffAndInShopWidget) {
                                return nonMobileWording;
                            }
                            return '';
                        }),
                        setCmsContent: jest.fn()
                    }
                };
            });
            test.each([
                [AppointmentTypeStrings.MOBILE, mobileWording],
                [AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP, mobileWording],
                [AppointmentTypeStrings.DROP_OFF, nonMobileWording],
                [AppointmentTypeStrings.IN_SHOP, nonMobileWording],
                ['unknown', null],
                [null, null],
                [undefined, null]
            ])('appointment type %p returns wording "%p"', (type, wording) => {
                // Arrange
                const order = deepClone(sessionStorage);
                order.serviceLocation.appointmentType = type;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions, mixin);

                // Act
                const testValue = wrapper.vm.appointmentWordingText2;

                // Assert
                expect(testValue).toEqual(wording);
            });
        });
        describe('isMobileAppointment', () => {
            test.each([
                [AppointmentTypeStrings.MOBILE, true],
                [AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP, true],
                [AppointmentTypeStrings.IN_SHOP, false],
                [AppointmentTypeStrings.DROP_OFF, false],
                ['other', false],
                [null, false],
                [undefined, false]
            ])('appointment type %p returns %p', (type, expected) => {
                // Arrange
                const order = deepClone(sessionStorage);
                order.serviceLocation.appointmentType = type;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);

                // Act
                const testValue = wrapper.vm.isMobileAppointment;

                // Assert
                expect(testValue).toBe(expected);
            });
        });
        describe('isInShopAppointment', () => {
            test.each([
                [AppointmentTypeStrings.MOBILE, false],
                [AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP, false],
                [AppointmentTypeStrings.IN_SHOP, true],
                [AppointmentTypeStrings.DROP_OFF, false],
                ['other', false],
                [null, false],
                [undefined, false]
            ])('appointment type %p returns %p', (type, expected) => {
                // Arrange
                const order = deepClone(sessionStorage);
                order.serviceLocation.appointmentType = type;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);

                // Act
                const testValue = wrapper.vm.isInShopAppointment;

                // Assert
                expect(testValue).toBe(expected);
            });
        });
        describe('isDropOffAppointment', () => {
            test.each([
                [AppointmentTypeStrings.MOBILE, false],
                [AppointmentTypeStrings.MOBILE_NOT_ITAC_AND_NOT_NOCOMP, false],
                [AppointmentTypeStrings.IN_SHOP, false],
                [AppointmentTypeStrings.DROP_OFF, true],
                ['other', false],
                [null, false],
                [undefined, false]
            ])('appointment type %p returns %p', (type, expected) => {
                // Arrange
                const order = deepClone(sessionStorage);
                order.serviceLocation.appointmentType = type;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);

                // Act
                const testValue = wrapper.vm.isDropOffAppointment;

                // Assert
                expect(testValue).toBe(expected);
            });
        });
        describe('showCart', () => {
            test.each([
                [true, true, 100],
                [true, false, 100],
                [false, true, 0],
                [false, true, null]
            ])('showCart is %p when is PIA is %p and settledTenderAmount is %p', (expected, isPia, settledTenderAmount) => {
                // Arrange
                const order = deepClone(sessionStorage);
                order.payment.isPayInAdvance = isPia;
                order.settledTenderAmount = settledTenderAmount;
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);

                // Act
                const testValue = wrapper.vm.showCart;

                // Assert
                expect(testValue).toBe(expected);
            });
        });
    });
    describe('Methods', () => {
        describe('formatDate', () => {
            test.each([
                ['Wednesday, April 22', '2020-04-22'],
                ['Thursday, February 1', '2018-02-01'],
                ['Wednesday, December 30', '2026-12-30']
            ])('returns %p given %p', (expected, date) => {
                // Arrange
                const order = deepClone(sessionStorage);
                const mockStoreActions = () => {
                    useMainStore().getSubmittedOrder = jest.fn().mockImplementation(() => order);
                };
                const { wrapper } = getMountedComponent({}, {}, mockStoreActions);

                // Act
                const result = wrapper.vm.formatDate(date);

                // Assert
                expect(result).toBe(expected);
            });
        });
    });
});
