CSR-756 Fix validation issue on vehicle-damage page
This commit is contained in:
parent
4a6c9828aa
commit
2588ddc066
5 changed files with 50 additions and 43 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
<template>
|
<template>
|
||||||
<transition name="fade" mode="out-in">
|
<transition name="fade" mode="out-in">
|
||||||
<div v-if="isAvailable && this.answersToDisplay.length > 0" class="replace-options-question" :class="this.answersToDisplay.length < 2 ? 'd-none' : ''" aria-live="polite">
|
<div v-if="shouldDisplayReplaceOptionsQuestion" class="replace-options-question" :class="this.answersToDisplay.length < 2 ? 'd-none' : ''" aria-live="polite">
|
||||||
<buttonQuestion
|
<buttonQuestion
|
||||||
isWide
|
isWide
|
||||||
:questionText="questionText"
|
:questionText="questionText"
|
||||||
|
|
@ -80,11 +80,19 @@ export default ({
|
||||||
return ans;
|
return ans;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
shouldDisplayReplaceOptionsQuestion() {
|
||||||
|
return this.isAvailable && this.answersToDisplay.length > 0
|
||||||
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
isAvailable(val) {
|
isAvailable(val) {
|
||||||
// CHECK TO UPDATE SELECTED VALUES WHEN ISAVAILABLE IS TRUE
|
// CHECK TO UPDATE SELECTED VALUES WHEN ISAVAILABLE IS TRUE
|
||||||
val && this.updateSelectedValues();
|
val && this.updateSelectedValues();
|
||||||
|
},
|
||||||
|
shouldDisplayReplaceOptionsQuestion(shouldDisplayReplaceOptionsQuestion) {
|
||||||
|
if (!shouldDisplayReplaceOptionsQuestion) {
|
||||||
|
this.selectedValues = [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ import store from "@/store";
|
||||||
import { defineRule } from "vee-validate";
|
import { defineRule } from "vee-validate";
|
||||||
import { required } from "@/helpers/validation-rules";
|
import { required } from "@/helpers/validation-rules";
|
||||||
import { errorMessages } from "@/constants/error-messages";
|
import { errorMessages } from "@/constants/error-messages";
|
||||||
|
import { damageLocationsSelected } from "@/constants/damage-locations-selected";
|
||||||
|
|
||||||
// DEFINE VALIDATION RULES
|
// DEFINE VALIDATION RULES
|
||||||
defineRule("damage-side-required", required(errorMessages.DAMAGE_SIDE_REQUIRED));
|
defineRule("damage-side-required", required(errorMessages.DAMAGE_SIDE_REQUIRED));
|
||||||
|
|
@ -128,10 +129,10 @@ export default ({
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
isDriverSideReplaceOptionsQuestionAvailable(){
|
isDriverSideReplaceOptionsQuestionAvailable(){
|
||||||
return (Array.isArray(this.selectedDoorSidesValues) && this.selectedDoorSidesValues.includes("DriverSide") && (Array.isArray(this.selectedDamageLocations) && this.selectedDamageLocations.includes("SideDoor")));
|
return (Array.isArray(this.selectedDoorSidesValues) && this.selectedDoorSidesValues.includes(damageLocationsSelected.DRIVERSIDE) && (Array.isArray(this.selectedDamageLocations) && this.selectedDamageLocations.includes(damageLocationsSelected.SIDEDOOR)));
|
||||||
},
|
},
|
||||||
isPassengerSideReplaceOptionsQuestionAvailable(){
|
isPassengerSideReplaceOptionsQuestionAvailable(){
|
||||||
return (Array.isArray(this.selectedDoorSidesValues) && this.selectedDoorSidesValues.includes("PassengerSide") && (Array.isArray(this.selectedDamageLocations) && this.selectedDamageLocations.includes("SideDoor")));
|
return (Array.isArray(this.selectedDoorSidesValues) && this.selectedDoorSidesValues.includes(damageLocationsSelected.PASSENGERSIDE) && (Array.isArray(this.selectedDamageLocations) && this.selectedDamageLocations.includes(damageLocationsSelected.SIDEDOOR)));
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
|
|
|
||||||
|
|
@ -225,6 +225,8 @@ function navigateToUrl(url, optionalQuery = {}) {
|
||||||
externalUrl.searchParams.append(queryKey, optionalQuery[queryKey]);
|
externalUrl.searchParams.append(queryKey, optionalQuery[queryKey]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
externalUrl.searchParams.append("experiments", "ConceptFunnel=ConceptFunnel_V1=ConceptFunnel_TEST=true");
|
||||||
|
|
||||||
window.location.assign(externalUrl);
|
window.location.assign(externalUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ describe("list-card.vue", () => {
|
||||||
groupID: "checkbox-demo-1",
|
groupID: "checkbox-demo-1",
|
||||||
groupName: "Checkbox 1",
|
groupName: "Checkbox 1",
|
||||||
buttonImage: "windshield-damage.svg",
|
buttonImage: "windshield-damage.svg",
|
||||||
modelValue: ["List Card Checkbox"],
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -33,7 +32,6 @@ describe("list-card.vue", () => {
|
||||||
groupID: "radio-demo-1",
|
groupID: "radio-demo-1",
|
||||||
groupName: "radio 1",
|
groupName: "radio 1",
|
||||||
buttonImage: "windshield-damage.svg",
|
buttonImage: "windshield-damage.svg",
|
||||||
modelValue: ["List Card Checkbox"],
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -53,7 +51,6 @@ describe("list-card.vue", () => {
|
||||||
groupName: "radio 1",
|
groupName: "radio 1",
|
||||||
buttonImage: "windshield-damage.svg",
|
buttonImage: "windshield-damage.svg",
|
||||||
buttonLabelSubCopy: "Test",
|
buttonLabelSubCopy: "Test",
|
||||||
modelValue: ["List Card Checkbox"],
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -73,7 +70,6 @@ describe("list-card.vue", () => {
|
||||||
groupName: "radio 1",
|
groupName: "radio 1",
|
||||||
buttonImage: "windshield-damage.svg",
|
buttonImage: "windshield-damage.svg",
|
||||||
buttonLabelSubCopy: "Test",
|
buttonLabelSubCopy: "Test",
|
||||||
modelValue: ["List Card Checkbox"],
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -93,7 +89,6 @@ describe("list-card.vue", () => {
|
||||||
groupName: "radio 1",
|
groupName: "radio 1",
|
||||||
buttonImage: "windshield-damage.svg",
|
buttonImage: "windshield-damage.svg",
|
||||||
buttonLabelSubCopy: "Test",
|
buttonLabelSubCopy: "Test",
|
||||||
modelValue: ["List Card Checkbox"],
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -113,7 +108,6 @@ describe("list-card.vue", () => {
|
||||||
groupName: "radio 1",
|
groupName: "radio 1",
|
||||||
buttonImage: "windshield-damage.svg",
|
buttonImage: "windshield-damage.svg",
|
||||||
isRequired: true,
|
isRequired: true,
|
||||||
modelValue: ["List Card Checkbox"],
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -135,7 +129,6 @@ describe("list-card.vue", () => {
|
||||||
isRequired: true,
|
isRequired: true,
|
||||||
isWide: true,
|
isWide: true,
|
||||||
buttonLabelSubCopy: "",
|
buttonLabelSubCopy: "",
|
||||||
modelValue: ["List Card Checkbox"],
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -157,7 +150,6 @@ describe("list-card.vue", () => {
|
||||||
isRequired: true,
|
isRequired: true,
|
||||||
isWide: true,
|
isWide: true,
|
||||||
buttonLabelSubCopy: "Button Subcopy",
|
buttonLabelSubCopy: "Button Subcopy",
|
||||||
modelValue: ["List Card Checkbox"],
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -178,7 +170,6 @@ describe("list-card.vue", () => {
|
||||||
buttonImage: "windshield-damage.svg",
|
buttonImage: "windshield-damage.svg",
|
||||||
isRequired: true,
|
isRequired: true,
|
||||||
isWide: false,
|
isWide: false,
|
||||||
modelValue: ["List Card Checkbox"],
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -199,13 +190,13 @@ describe("list-card.vue", () => {
|
||||||
buttonImage: "windshield-damage.svg",
|
buttonImage: "windshield-damage.svg",
|
||||||
isRequired: true,
|
isRequired: true,
|
||||||
isWide: false,
|
isWide: false,
|
||||||
modelValue: ["List Card Checkbox"],
|
buttonID: 'list-card-id',
|
||||||
buttonID: 'list-card-id'
|
selectedValues: "List Card Checkbox"
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
wrapper.vm.handleCheckChange();
|
wrapper.vm.handleCheckChange();
|
||||||
// Assert
|
// Assert
|
||||||
expect(wrapper.emitted()["isCheckedChanged"][0]).toEqual([{value: "List Card Checkbox", checkValue: "List Card Checkbox", buttonId: 'list-card-id'}]);
|
expect(wrapper.emitted()["isCheckedChanged"][0]).toEqual([{value: "List Card Checkbox", checkValue: true, buttonId: 'list-card-id'}]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should set checkValue data if selectedButtonIDs has value(s)", async () => {
|
it("Should set checkValue data if selectedButtonIDs has value(s)", async () => {
|
||||||
|
|
@ -220,12 +211,11 @@ describe("list-card.vue", () => {
|
||||||
buttonImage: "windshield-damage.svg",
|
buttonImage: "windshield-damage.svg",
|
||||||
isRequired: true,
|
isRequired: true,
|
||||||
isWide: false,
|
isWide: false,
|
||||||
modelValue: ["List Card Checkbox"],
|
selectedValues: "Car-Front"
|
||||||
selectedValues: ["Car-Front"]
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
// Assert
|
// Assert
|
||||||
expect(wrapper.componentVM.checkValue).toEqual("Car-Front");
|
expect(wrapper.componentVM.checkValue).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should set an initial value for validation if selectedValues include the value", async () => {
|
it("Should set an initial value for validation if selectedValues include the value", async () => {
|
||||||
|
|
@ -234,7 +224,6 @@ describe("list-card.vue", () => {
|
||||||
propsData: {
|
propsData: {
|
||||||
value: "Windshield",
|
value: "Windshield",
|
||||||
groupName: "radio 1",
|
groupName: "radio 1",
|
||||||
modelValue: ["Windshield"],
|
|
||||||
selectedValues: ["Windshield"],
|
selectedValues: ["Windshield"],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { useField } from "vee-validate";
|
import { useField } from "vee-validate";
|
||||||
import { toRef } from "vue";
|
import { toRef, computed } from "vue";
|
||||||
import { queryStrings } from "@/constants/query-strings";
|
import { queryStrings } from "@/constants/query-strings";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
|
@ -87,7 +87,7 @@ export default {
|
||||||
colLength: String,
|
colLength: String,
|
||||||
validationRules: String,
|
validationRules: String,
|
||||||
selectedValues: [Array, String],
|
selectedValues: [Array, String],
|
||||||
modelValue: Object,
|
// modelValue: Object,
|
||||||
hasError: Boolean,
|
hasError: Boolean,
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
|
|
@ -95,19 +95,18 @@ export default {
|
||||||
checkValue: null,
|
checkValue: null,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
mounted() {
|
||||||
if (Array.isArray(this.selectedValues)) {
|
if (Array.isArray(this.validateValue)) {
|
||||||
this.checkValue = this.isMultiSelect
|
this.checkValue = this.isValueSelectedByArray(this.selectedValues);
|
||||||
? this.selectedValues.includes(this.value)
|
|
||||||
: this.selectedValues[0];
|
const isSelectedByValidator = this.isValueSelectedByArray(this.validateValue);
|
||||||
}
|
|
||||||
else if (Array.isArray(this.modelValue)) {
|
if (this.checkValue != isSelectedByValidator) {
|
||||||
this.checkValue = this.isMultiSelect
|
this.handleChange(this.value);
|
||||||
? this.modelValue.includes(this.value)
|
}
|
||||||
: this.modelValue[0];
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.checkValue = this.selectedValues == this.value || this.modelValue == this.value;
|
this.checkValue = this.selectedValues == this.value;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
|
@ -124,10 +123,15 @@ export default {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
isValueSelectedByArray(arr) {
|
||||||
|
return this.isMultiSelect
|
||||||
|
? arr.includes(this.value)
|
||||||
|
: arr[0];
|
||||||
|
},
|
||||||
handleInputChange() {
|
handleInputChange() {
|
||||||
if(!this.selectingInitiatesLoad) {
|
if(!this.selectingInitiatesLoad) {
|
||||||
this.handleCheckChange();
|
this.handleCheckChange();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleKeyupArrow() {
|
handleKeyupArrow() {
|
||||||
if (this.isMultiSelect) {
|
if (this.isMultiSelect) {
|
||||||
|
|
@ -155,20 +159,14 @@ export default {
|
||||||
|
|
||||||
this.handleChange(this.value);
|
this.handleChange(this.value);
|
||||||
this.$emit("isCheckedChanged", emitEvent);
|
this.$emit("isCheckedChanged", emitEvent);
|
||||||
this.$emit("update:modelValue", emitEvent);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
// Changing this will impact pre-selection data loads on vehicle-parts.
|
// Changing this will impact pre-selection data loads on vehicle-parts.
|
||||||
// If changed, please regression test that vehicle-parts data still loads correctly with previous selections.
|
// If changed, please regression test that vehicle-parts data still loads correctly with previous selections.
|
||||||
modelValue(newVal) {
|
// model
|
||||||
if (newVal !== undefined) {
|
|
||||||
this.checkValue = newVal.value;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
selectedValues(newVal) {
|
selectedValues(newVal) {
|
||||||
if (typeof newVal === "string") {
|
if (typeof newVal === "string") {
|
||||||
this.handleChange(newVal);
|
|
||||||
this.checkValue = newVal == this.value;
|
this.checkValue = newVal == this.value;
|
||||||
}
|
}
|
||||||
else if (newVal !== undefined) {
|
else if (newVal !== undefined) {
|
||||||
|
|
@ -194,11 +192,20 @@ export default {
|
||||||
const {
|
const {
|
||||||
handleChange,
|
handleChange,
|
||||||
errors,
|
errors,
|
||||||
|
checked,
|
||||||
|
meta,
|
||||||
|
value
|
||||||
} = useField(toRef(props, "groupName"), toRef(props, "validationRules"), fieldOptions);
|
} = useField(toRef(props, "groupName"), toRef(props, "validationRules"), fieldOptions);
|
||||||
|
|
||||||
|
// First land on the blank, unselected page, no handleChange
|
||||||
|
// Land on page with initial values, handleChange
|
||||||
|
const validateValue = value;
|
||||||
return {
|
return {
|
||||||
handleChange,
|
handleChange,
|
||||||
errors,
|
errors,
|
||||||
|
checked,
|
||||||
|
meta,
|
||||||
|
validateValue,
|
||||||
fieldOptions, // only need to expose this for unit test purposes
|
fieldOptions, // only need to expose this for unit test purposes
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue