From 21ec33f8dcb4d286b21e380f5b2953313c960b9f Mon Sep 17 00:00:00 2001 From: Jason Wheeler Date: Fri, 11 Nov 2022 15:33:32 -0500 Subject: [PATCH] requested updates --- src/layouts/vehicle-make/vehicle-make.vue | 6 +- src/layouts/vehicle-model/vehicle-model.vue | 6 +- src/layouts/vehicle-style/vehicle-style.vue | 15 +--- src/layouts/vehicle-year/vehicle-year.vue | 5 +- src/store/index.js | 90 ++++++++++++++------- src/store/store.spec.js | 21 +++-- 6 files changed, 81 insertions(+), 62 deletions(-) diff --git a/src/layouts/vehicle-make/vehicle-make.vue b/src/layouts/vehicle-make/vehicle-make.vue index 3261ae92..3338132e 100644 --- a/src/layouts/vehicle-make/vehicle-make.vue +++ b/src/layouts/vehicle-make/vehicle-make.vue @@ -90,11 +90,7 @@ }, watch: { selectedMake(make) { - if(make != this.mainStore.order.vehicle.make) - { - const vehicle = this.mainStore.order.vehicle; - this.mainStore.updateVehicle( { year: vehicle.year, make }, true ); - } + this.mainStore.updateVehicleMake( make ); this.$router.navigate( this.navigationScenarios.SELECTED_MAKE, this.$route diff --git a/src/layouts/vehicle-model/vehicle-model.vue b/src/layouts/vehicle-model/vehicle-model.vue index 443585ec..986d4bed 100644 --- a/src/layouts/vehicle-model/vehicle-model.vue +++ b/src/layouts/vehicle-model/vehicle-model.vue @@ -83,11 +83,7 @@ watch: { selectedModel(model) { - if(model != this.mainStore.order.vehicle.model) - { - const vehicle = this.mainStore.order.vehicle; - this.mainStore.updateVehicle( { year: vehicle.year, make: vehicle.make, model }, true ); - } + this.mainStore.updateVehicleModel( model ); this.$router.navigate( this.navigationScenarios.SELECTED_MODEL, this.$route diff --git a/src/layouts/vehicle-style/vehicle-style.vue b/src/layouts/vehicle-style/vehicle-style.vue index 6ced6799..1ce939af 100644 --- a/src/layouts/vehicle-style/vehicle-style.vue +++ b/src/layouts/vehicle-style/vehicle-style.vue @@ -76,20 +76,7 @@ export default { watch: { selectedStyle(style) { - if(style != this.mainStore.order.vehicle.style) - { - const vehicle = this.mainStore.order.vehicle; - this.mainStore.updateVehicle( - { - year: vehicle.year, - make: vehicle.make, - model: vehicle.model, - style - }, - true - ); - } - + this.mainStore.updateVehicleStyle( style ); this.mainStore.setVehicle().then(() => { this.$router.navigate( this.navigationScenarios.SELECTED_STYLE, diff --git a/src/layouts/vehicle-year/vehicle-year.vue b/src/layouts/vehicle-year/vehicle-year.vue index 1f0e7f5e..876c619d 100644 --- a/src/layouts/vehicle-year/vehicle-year.vue +++ b/src/layouts/vehicle-year/vehicle-year.vue @@ -69,10 +69,7 @@ watch: { selectedYear(year) { const parsedYear = parseInt(year); - if(parsedYear != this.mainStore.order.vehicle.year) - { - this.mainStore.updateVehicle( { year: parsedYear }, true ); - } + this.mainStore.updateVehicleYear( parsedYear ); this.$router.navigate( this.navigationScenarios.SELECTED_YEAR, diff --git a/src/store/index.js b/src/store/index.js index 108f4074..8653686c 100644 --- a/src/store/index.js +++ b/src/store/index.js @@ -198,42 +198,76 @@ export const useMainStore = defineStore({ payload: {}, }) .then((response) => { - this.updateVehicle(response.data); + updateVehicle(response.vehicle); return response; }); }, - updateVehicle(vehicle, reset = false) - { - if(reset) - { - this.resetVehicle(); - } + updateVehicle(vehicle) { this.order.vehicle = { ...this.order.vehicle, ...vehicle }; }, - resetVehicle() + resetVehicleState() { - this.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, - address: null, - city: null, - state: null, - zipCode: null, - firstName: null, - lastName: null, - }, + this.order.vehicle.year = null; + this.order.vehicle.make = null; + this.order.vehicle.model = null; + this.order.vehicle.style = null; + this.order.vehicle.carId = null; + this.order.vehicle.category = null; + this.order.vehicle.vin = null; + this.order.vehicle.imageUrl = null; + this.order.vehicle.imageVifNumber = null; + this.order.vehicle.imageColor = null; + }, + + updateVehicleYear(year) { + if(this.order.vehicle.year != year) + { + this.resetVehicleState(); + this.order.vehicle.year = year; + } + }, + + updateVehicleMake(make) { + if(this.order.vehicle.make != make) + { + const year = this.order.vehicle.year; + + this.resetVehicleState(); + + this.order.vehicle.year = year; + this.order.vehicle.make = make; + } + }, + + updateVehicleModel(model) { + if(this.order.vehicle.model != model) + { + const year = this.order.vehicle.year; + const make = this.order.vehicle.make; + + this.resetVehicleState(); + + this.order.vehicle.year = year; + this.order.vehicle.make = make; + this.order.vehicle.model = model; + } + }, + + updateVehicleStyle(style) { + if(this.order.vehicle.style != style) + { + const year = this.order.vehicle.year; + const make = this.order.vehicle.make; + const model = this.order.vehicle.model; + + this.resetVehicleState(); + + this.order.vehicle.year = year; + this.order.vehicle.make = make; + this.order.vehicle.model = model; + this.order.vehicle.style = style; } }, diff --git a/src/store/store.spec.js b/src/store/store.spec.js index 4c1160b3..5136aab2 100644 --- a/src/store/store.spec.js +++ b/src/store/store.spec.js @@ -19,6 +19,13 @@ describe("Store", () => { jest.resetAllMocks(); }) + + it("Should Store Vehicle Year", () => { + let testYear = "2001"; + store.updateVehicleYear(testYear); + expect(store.order.vehicle.year).toEqual(testYear); + }); + it("Should add events to the bus", () => { let event = { category: "TestCategory", @@ -90,7 +97,7 @@ describe("Store", () => { imageColor: null, }; - const response = { + const response = {data: { "carId": "CR00069299", "category": "CAR", "year": 2020, @@ -100,19 +107,20 @@ describe("Store", () => { "imageUrl": "https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13996/13996_cc0320_032_WX.jpg", "imageVifNumber": "13996", "imageVifColor": "white" + } }; - store.updateVehicle(response); + store.updateVehicle(response.data); - expect(store.order.vehicle.imageUrl).toEqual(response.imageUrl); - expect(store.order.vehicle.imageVifNumber).toEqual(response.imageVifNumber); - expect(store.order.vehicle.imageVifColor).toEqual(response.imageVifColor); + expect(store.order.vehicle.imageUrl).toEqual(response.data.imageUrl); + expect(store.order.vehicle.imageVifNumber).toEqual(response.data.imageVifNumber); + expect(store.order.vehicle.imageVifColor).toEqual(response.data.imageVifColor); }); it("setVehicle should call globalMethods.callHttpClient", () => { store.order.vehicle = jest.fn(); - const response = { + const response = {data: { "carId": "CR00069299", "category": "CAR", "year": 2020, @@ -122,6 +130,7 @@ describe("Store", () => { "imageUrl": "https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13996/13996_cc0320_032_WX.jpg", "imageVifNumber": "13996", "imageVifColor": "white" + } }; globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response));