// Components import review from '@/layouts/review-page/review-page.vue'; // Supporting Files import { createTestingPinia } from '@pinia/testing'; import { shallowMount } from '@vue/test-utils'; import { getMountOptions } from '@/helpers/unit-test-helper.js'; import { useMainStore } from '@/store/index.js'; // Mock fetchCmsContentForPage jest.mock('@/helpers/cms-content-helper', () => ({ fetchCmsContentForPage: jest.fn() })); const mockMixin = { methods: { getCmsContent: jest.fn().mockImplementation(() => ''), setCmsContent: jest.fn() } }; const footerStub = { render: () => {}, methods: { updateButtonText: jest.fn() } }; const loadingModalStub = { render: () => {}, methods: { showModal: jest.fn(), hideModal: jest.fn() } }; function getShallowMountedComponent(initialData = {}, methodToRun = () => {}) { const mountOptions = getMountOptions({ router: { navigate: jest.fn() } }); // mountOptions.global.mocks["$store"] = store; mountOptions.global.stubs = { siteFooter: footerStub, loadingModal: loadingModalStub }; methodToRun(); mountOptions.mixins = [mockMixin]; mountOptions.data = () => ( initialData ); const wrapper = shallowMount(review, mountOptions); return { wrapper }; } beforeEach(() => { const testingPinia = createTestingPinia({ initialState: { main: { order: { vehicle: { year: '2020', make: 'Acura', model: 'MDX', style: '4 door sedan' }, damage: { isRepair: false, numberOfChips: 2, glassToReplace: ['dummy location value'] }, lineItems: { glassParts: ['dummy part value'], supportingItems: ['dummy supporting item'], vaps: ['dummy vap'] }, serviceLocation: { address: 'address 1', address2: 'address 2', city: 'city', state: 'state', zipCode: 'zip code', appointmentType: 'Mobile', provider: { providerNumber: 1, address: { streetAddress: 'provider address 1', city: 'provider city', state: 'provider state', zipCode: 'provider zip code' } } }, schedule: { date: 'date', startTime: 'start', endTime: 'end', jobMinMinutes: '30', jobMaxMinutes: '45' }, customer: { firstName: 'first name', lastName: 'last name', emailAddress: 'builddigitaltest@safelite.com', phoneNumber: '555-555-5555', isSmsOptIn: true } } } } }); useMainStore(testingPinia); }); afterEach(() => { jest.clearAllMocks(); }); describe('Review Page', () => { describe('arePagePrerequisitesValid', () => { test('Returns true for baseline valid state', () => { // Arrange const { wrapper } = getShallowMountedComponent(); // Act const isValid = wrapper.vm.arePagePrerequisitesValid(); // Assert expect(isValid).toBe(true); }); test('Returns false for empty state', () => { // Arrange const { wrapper } = getShallowMountedComponent(); wrapper.vm.mainStore.order = { vehicle: { year: null, make: null, model: null, style: null, carId: null, category: null, vin: null, imageUrl: null, imageVifNumber: null, imageColor: null, registration: { licensePlate: null } }, serviceLocation: { address: null, address2: null, city: null, state: null, zipCode: null, zipCodeCtu: null, appointmentType: null, isVehicleProtected: null, provider: { providerNumber: null, address: { streetAddress: null, city: null, state: null, zipCode: null, zipCodeCtu: null } }, techNotes: null }, customer: { firstName: null, lastName: null, emailAddress: null, phoneNumber: null, isSmsOptIn: null }, damage: { isRepair: null, numberOfChips: null, glassToReplace: null, partQuestionAnswers: null, moldingQuestionAnswers: null, capabilityQuestionAnswers: null }, lineItems: { glassParts: null, supportingItems: null, vaps: null, serverData: null }, payment: { isInsurance: null, insuranceCoverage: { isVerified: null, coverageStatus: null }, parentAccountNumber: 0 }, schedule: { date: null, startTime: null, endTime: null, routeCode: null, jobMaxMinutes: null, jobMinMinutes: null }, referralNumber: null, referralSequenceNumber: null, referralDate: null, referralCorrelationId: null, eon: null }; // Act const isValid = wrapper.vm.arePagePrerequisitesValid(); // Assert expect(isValid).toBe(false); }); describe('Damage requirements', () => { test('Accepts null glassToReplace when is repair', () => { // Arrange const { wrapper } = getShallowMountedComponent(); wrapper.vm.mainStore.order.damage.isRepair = true; wrapper.vm.mainStore.order.damage.glassToReplace = null; wrapper.vm.mainStore.order.damage.numberOfChips = 1; // Act const isValid = wrapper.vm.arePagePrerequisitesValid(); // Assert expect(isValid).toBe(true); }); test('Rejects 0 chips when repair', () => { // Arrange const { wrapper } = getShallowMountedComponent(); wrapper.vm.mainStore.order.damage.isRepair = true; wrapper.vm.mainStore.order.damage.numberOfChips = 0; // Act const isValid = wrapper.vm.arePagePrerequisitesValid(); // Assert expect(isValid).toBe(false); }); test('Rejects null chips when repair', () => { // Arrange const { wrapper } = getShallowMountedComponent(); wrapper.vm.mainStore.order.damage.isRepair = true; wrapper.vm.mainStore.order.damage.numberOfChips = null; // Act const isValid = wrapper.vm.arePagePrerequisitesValid(); // Assert expect(isValid).toBe(false); }); test('Accepts null chips when not repair', () => { // Arrange const { wrapper } = getShallowMountedComponent(); wrapper.vm.mainStore.order.damage.isRepair = false; wrapper.vm.mainStore.order.damage.numberOfChips = null; // Act const isValid = wrapper.vm.arePagePrerequisitesValid(); // Assert expect(isValid).toBe(true); }); test('Rejects empty glassToReplace when not repair', () => { // Arrange const { wrapper } = getShallowMountedComponent(); wrapper.vm.mainStore.order.damage.isRepair = false; wrapper.vm.mainStore.order.damage.glassToReplace = null; // Act const isValid = wrapper.vm.arePagePrerequisitesValid(); // Assert expect(isValid).toBe(false); }); test('Rejects null glassToReplace when not repair', () => { // Arrange const { wrapper } = getShallowMountedComponent(); wrapper.vm.mainStore.order.damage.isRepair = false; wrapper.vm.mainStore.order.damage.glassToReplace = []; // Act const isValid = wrapper.vm.arePagePrerequisitesValid(); // Assert expect(isValid).toBe(false); }); }); describe('Package requirements', () => { test('Accepts null glassParts when is repair', () => { // Arrange const { wrapper } = getShallowMountedComponent(); wrapper.vm.mainStore.order.damage.isRepair = true; wrapper.vm.mainStore.order.lineItems.glassParts = null; // Act const isValid = wrapper.vm.arePagePrerequisitesValid(); // Assert expect(isValid).toBe(true); }); test('Rejects null glassParts when not repair', () => { // Arrange const { wrapper } = getShallowMountedComponent(); wrapper.vm.mainStore.order.damage.isRepair = false; wrapper.vm.mainStore.order.lineItems.glassParts = null; // Act const isValid = wrapper.vm.arePagePrerequisitesValid(); // Assert expect(isValid).toBe(false); }); }); describe('Service Location requirements', () => { test('Accepts null provider address when mobile appointment', () => { // Arrange const { wrapper } = getShallowMountedComponent(); wrapper.vm.mainStore.order.serviceLocation.appointmentType = 'Mobile'; wrapper.vm.mainStore.order.serviceLocation.provider.address = {}; // Act const isValid = wrapper.vm.arePagePrerequisitesValid(); // Assert expect(isValid).toBe(true); }); test('Reject null provider address when non-mobile appointment', () => { // Arrange const { wrapper } = getShallowMountedComponent(); wrapper.vm.mainStore.order.serviceLocation.appointmentType = 'Inshop'; wrapper.vm.mainStore.order.serviceLocation.provider.address = {}; // Act const isValid = wrapper.vm.arePagePrerequisitesValid(); // Assert expect(isValid).toBe(false); }); test('Accepts null service location address when non-mobile appointment', () => { // Arrange const { wrapper } = getShallowMountedComponent(); wrapper.vm.mainStore.order.serviceLocation.appointmentType = 'Inshop'; wrapper.vm.mainStore.order.serviceLocation.address = null; wrapper.vm.mainStore.order.serviceLocation.address2 = null; wrapper.vm.mainStore.order.serviceLocation.zipCode = null; wrapper.vm.mainStore.order.serviceLocation.city = null; wrapper.vm.mainStore.order.serviceLocation.state = null; // Act const isValid = wrapper.vm.arePagePrerequisitesValid(); // Assert expect(isValid).toBe(true); }); test('Rejects null service location address when mobile appointment', () => { // Arrange const { wrapper } = getShallowMountedComponent(); wrapper.vm.mainStore.order.serviceLocation.appointmentType = 'Mobile'; wrapper.vm.mainStore.order.serviceLocation.address = null; wrapper.vm.mainStore.order.serviceLocation.address2 = null; wrapper.vm.mainStore.order.serviceLocation.zipCode = null; wrapper.vm.mainStore.order.serviceLocation.city = null; wrapper.vm.mainStore.order.serviceLocation.state = null; // Act const isValid = wrapper.vm.arePagePrerequisitesValid(); // Assert expect(isValid).toBe(false); }); }); }); });