Moved setting selected value in store from question components to parent components. Pulled over arePagePrerequisitesValids methods.

This commit is contained in:
Jason Wheeler 2022-11-01 16:12:58 -04:00
parent 5606f41432
commit ced1b59fed
5 changed files with 53 additions and 5 deletions

View file

@ -40,8 +40,6 @@
},
set: function(newValue) {
this.$emit("update:modelValue", newValue);
this.mainStore.updateVehicleMake(newValue);
this.$router.navigate(this.navigationScenarios.SELECTED_MAKE, this.$route)
}
}
},

View file

@ -5,6 +5,7 @@ import { fetchCmsContentForPage } from "@/helpers/cms-content-helper";
import baseMixin from "@/mixins/base-mixin.js";
import { getMountOptions } from "@/helpers/unit-test-helper.js";
import { nextTick } from "vue";
import { useMainStore } from "@/store";
// Components
import vehicleMake from "@/layouts/vehicle-make/vehicle-make.vue";
@ -72,6 +73,25 @@ describe("vehicle-make.vue", () => {
});
});
test("Year set, arePagePrerequisitesValid should be true ", async () => {
//Arrange
const { wrapper } = setupMocks({});
useMainStore().order.vehicle.year = 2001;
//Act
vehicleMake.beforeRouteEnter.call(
wrapper.vm,
{ query: { issPage: "vehicle-make" } },
undefined,
(c) => c(wrapper.vm)
);
let arePagePrerequisitesValid = wrapper.vm.arePagePrerequisitesValid();
//Assert
expect(arePagePrerequisitesValid).toBe(true);
});
});
function setupMocks({

View file

@ -42,7 +42,7 @@
};
},
async beforeRouteEnter(to, from, next) {
async beforeRouteEnter(to, from, next) {
// Call APIs
const cmsContentPromise = fetchCmsContentForPage(to.query.issPage);
const makeQuestionInitialDataPromise = makeQuestion.methods.loadInitialData();
@ -76,6 +76,13 @@
this.$route
);
},
arePagePrerequisitesValid() {
console.log(this.mainStore.order)
if (this.mainStore.order.vehicle.year){
return true;
}
return false;
},
},
components: {
makeQuestion,
@ -83,5 +90,14 @@
siteSubHeader,
vehicleBanner,
},
watch: {
selectedMake(make) {
this.mainStore.updateVehicleMake(make);
this.$router.navigate(
this.navigationScenarios.SELECTED_MAKE,
this.$route
);
},
},
};
</script>

View file

@ -65,6 +65,22 @@
);
});
},
watch: {
selectedYear(year) {
const parsedYear = parseInt(year);
this.mainStore.updateVehicleYear(parsedYear);
this.$router.navigate(
this.navigationScenarios.SELECTED_YEAR,
this.$route
);
},
},
methods: {
arePagePrerequisitesValid() {
return true;
},
},
components: {
yearQuestion,

View file

@ -40,8 +40,6 @@
},
set: function(newValue) {
this.$emit("update:modelValue", newValue);
this.mainStore.updateVehicleYear(newValue);
this.$router.navigate(this.navigationScenarios.SELECTED_YEAR, this.$route)
}
}
},