requested updates

This commit is contained in:
Jason Wheeler 2022-11-11 15:33:32 -05:00
parent a9df577851
commit 21ec33f8dc
6 changed files with 81 additions and 62 deletions

View file

@ -90,11 +90,7 @@
}, },
watch: { watch: {
selectedMake(make) { selectedMake(make) {
if(make != this.mainStore.order.vehicle.make) this.mainStore.updateVehicleMake( make );
{
const vehicle = this.mainStore.order.vehicle;
this.mainStore.updateVehicle( { year: vehicle.year, make }, true );
}
this.$router.navigate( this.$router.navigate(
this.navigationScenarios.SELECTED_MAKE, this.navigationScenarios.SELECTED_MAKE,
this.$route this.$route

View file

@ -83,11 +83,7 @@
watch: { watch: {
selectedModel(model) { selectedModel(model) {
if(model != this.mainStore.order.vehicle.model) this.mainStore.updateVehicleModel( model );
{
const vehicle = this.mainStore.order.vehicle;
this.mainStore.updateVehicle( { year: vehicle.year, make: vehicle.make, model }, true );
}
this.$router.navigate( this.$router.navigate(
this.navigationScenarios.SELECTED_MODEL, this.navigationScenarios.SELECTED_MODEL,
this.$route this.$route

View file

@ -76,20 +76,7 @@ export default {
watch: { watch: {
selectedStyle(style) { selectedStyle(style) {
if(style != this.mainStore.order.vehicle.style) this.mainStore.updateVehicleStyle( style );
{
const vehicle = this.mainStore.order.vehicle;
this.mainStore.updateVehicle(
{
year: vehicle.year,
make: vehicle.make,
model: vehicle.model,
style
},
true
);
}
this.mainStore.setVehicle().then(() => { this.mainStore.setVehicle().then(() => {
this.$router.navigate( this.$router.navigate(
this.navigationScenarios.SELECTED_STYLE, this.navigationScenarios.SELECTED_STYLE,

View file

@ -69,10 +69,7 @@
watch: { watch: {
selectedYear(year) { selectedYear(year) {
const parsedYear = parseInt(year); const parsedYear = parseInt(year);
if(parsedYear != this.mainStore.order.vehicle.year) this.mainStore.updateVehicleYear( parsedYear );
{
this.mainStore.updateVehicle( { year: parsedYear }, true );
}
this.$router.navigate( this.$router.navigate(
this.navigationScenarios.SELECTED_YEAR, this.navigationScenarios.SELECTED_YEAR,

View file

@ -198,42 +198,76 @@ export const useMainStore = defineStore({
payload: {}, payload: {},
}) })
.then((response) => { .then((response) => {
this.updateVehicle(response.data); updateVehicle(response.vehicle);
return response; return response;
}); });
}, },
updateVehicle(vehicle, reset = false) updateVehicle(vehicle) {
{
if(reset)
{
this.resetVehicle();
}
this.order.vehicle = { ...this.order.vehicle, ...vehicle }; this.order.vehicle = { ...this.order.vehicle, ...vehicle };
}, },
resetVehicle() resetVehicleState()
{ {
this.order.vehicle = { this.order.vehicle.year = null;
year: null, this.order.vehicle.make = null;
make: null, this.order.vehicle.model = null;
model: null, this.order.vehicle.style = null;
style: null, this.order.vehicle.carId = null;
carId: null, this.order.vehicle.category = null;
category: null, this.order.vehicle.vin = null;
vin: null, this.order.vehicle.imageUrl = null;
imageUrl: null, this.order.vehicle.imageVifNumber = null;
imageVifNumber: null, this.order.vehicle.imageColor = null;
imageColor: null, },
registration: {
licensePlate: null, updateVehicleYear(year) {
address: null, if(this.order.vehicle.year != year)
city: null, {
state: null, this.resetVehicleState();
zipCode: null, this.order.vehicle.year = year;
firstName: null, }
lastName: null, },
},
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;
} }
}, },

View file

@ -19,6 +19,13 @@ describe("Store", () => {
jest.resetAllMocks(); 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", () => { it("Should add events to the bus", () => {
let event = { let event = {
category: "TestCategory", category: "TestCategory",
@ -90,7 +97,7 @@ describe("Store", () => {
imageColor: null, imageColor: null,
}; };
const response = { const response = {data: {
"carId": "CR00069299", "carId": "CR00069299",
"category": "CAR", "category": "CAR",
"year": 2020, "year": 2020,
@ -100,19 +107,20 @@ describe("Store", () => {
"imageUrl": "https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13996/13996_cc0320_032_WX.jpg", "imageUrl": "https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13996/13996_cc0320_032_WX.jpg",
"imageVifNumber": "13996", "imageVifNumber": "13996",
"imageVifColor": "white" "imageVifColor": "white"
}
}; };
store.updateVehicle(response); store.updateVehicle(response.data);
expect(store.order.vehicle.imageUrl).toEqual(response.imageUrl); expect(store.order.vehicle.imageUrl).toEqual(response.data.imageUrl);
expect(store.order.vehicle.imageVifNumber).toEqual(response.imageVifNumber); expect(store.order.vehicle.imageVifNumber).toEqual(response.data.imageVifNumber);
expect(store.order.vehicle.imageVifColor).toEqual(response.imageVifColor); expect(store.order.vehicle.imageVifColor).toEqual(response.data.imageVifColor);
}); });
it("setVehicle should call globalMethods.callHttpClient", () => { it("setVehicle should call globalMethods.callHttpClient", () => {
store.order.vehicle = jest.fn(); store.order.vehicle = jest.fn();
const response = { const response = {data: {
"carId": "CR00069299", "carId": "CR00069299",
"category": "CAR", "category": "CAR",
"year": 2020, "year": 2020,
@ -122,6 +130,7 @@ describe("Store", () => {
"imageUrl": "https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13996/13996_cc0320_032_WX.jpg", "imageUrl": "https://dbhdyzvm8lm25.cloudfront.net/color_0320_032/MY2020/13996/13996_cc0320_032_WX.jpg",
"imageVifNumber": "13996", "imageVifNumber": "13996",
"imageVifColor": "white" "imageVifColor": "white"
}
}; };
globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response)); globalMethods.callHttpClient = jest.fn().mockReturnValue(Promise.resolve(response));