requested updates
This commit is contained in:
parent
a9df577851
commit
21ec33f8dc
6 changed files with 81 additions and 62 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Reference in a new issue