Merge branch 'develop' into feature/CSR-335

This commit is contained in:
FrankRua 2022-03-02 13:38:54 -05:00
commit 2686521117
3 changed files with 64 additions and 24 deletions

View file

@ -57,17 +57,20 @@ const routes = [
try { try {
// If we already have our route, go to it. // If we already have our route, go to it.
if (router.hasRoute(to.query.fmgPage)) { if (router.hasRoute(to.query.fmgPage)) {
// Since our route is already in scope, we can grab the component from it and call the arePagePrerequisitesValid function. // Since our route is already in scope, we can grab the component from it and call the arePagePrerequisitesValid function.
const component = router let component = router.getRoutes().filter((x) => x.name === to.query.fmgPage)[0].components;
.getRoutes()
.filter((x) => x.name === to.query.fmgPage)[0].components; // If the component hasn't been loaded fully, load it before we check prerequisites.
if (component.default.methods === undefined) {
component = await component.default();
}
if (!arePagePrerequisitesValid(component)) { if (!arePagePrerequisitesValid(component)) {
await GoToFunnelStartOn404(next); await GoToFunnelStartOn404(next);
} }
return next({ name: to.query.fmgPage, query: to.query, params: to.params });
return next({ name: to.query.fmgPage, query: to.query, params: to.params });
} }
// Get route info for the given url. Names will have a 1:1 relationship with names in the Cms. // Get route info for the given url. Names will have a 1:1 relationship with names in the Cms.
@ -82,10 +85,7 @@ const routes = [
// Call the next components arePagePrerequisitesValid method before load. // Call the next components arePagePrerequisitesValid method before load.
// If it returns false, use the 404 logic. // If it returns false, use the 404 logic.
const nextComponent = await router const nextComponent = await router.getRoutes().filter((x) => x.name === routeData[0].name)[0].components.default();
.getRoutes()
.filter((x) => x.name === routeData[0].name)[0]
.components.default();
if (!arePagePrerequisitesValid(nextComponent)) { if (!arePagePrerequisitesValid(nextComponent)) {
await GoToFunnelStartOn404(next); await GoToFunnelStartOn404(next);

View file

@ -60,4 +60,42 @@ describe("radio.vue", () => {
expect(paragraph.text()).toEqual("screenreader text"); expect(paragraph.text()).toEqual("screenreader text");
}); });
it("Should emit button value on click", async () => {
// Act
const wrapper = shallowMount(radio, {
propsData: {
buttonLabel: "Windshield",
value: "List Card Checkbox",
buttonID: "List Card Checkbox",
groupID: "radio-demo-1",
groupName: "radio 1",
isRequired: true,
isWide: false,
modelValue: ["List Card Checkbox"],
},
});
wrapper.vm.handleCheckChange();
// Assert
expect(wrapper.emitted()["isCheckedChanged"][0]).toEqual([{"buttonID": "List Card Checkbox", value: "List Card Checkbox", checkValue: Boolean}]);
});
it("Should set checkValue data if selectedButtonIDs has value(s)", async () => {
// Act
const wrapper = shallowMount(radio, {
propsData: {
buttonLabel: "Windshield",
buttonID: "List Card Checkbox",
groupID: "radio-demo-1",
groupName: "radio 1",
buttonImage: "windshield-damage.svg",
isRequired: true,
modelValue: ["List Card Checkbox"],
value: "Car-Front",
selectedValues: ["Car-Front"]
},
});
// Assert
expect(wrapper.componentVM.checkValue).toEqual(true);
});
}); });

View file

@ -10,7 +10,8 @@
:aria-required="isRequired" :aria-required="isRequired"
:value="value" :value="value"
:v-model="checkValue" :v-model="checkValue"
@change="handleCheckChanged()" @change="handleCheckChange()"
:checked="checkValue"
/> />
<label class="d-flex align-items-start form-check-label" :for="buttonID"> <label class="d-flex align-items-start form-check-label" :for="buttonID">
<p v-if="buttonLabel" class="m-0">{{ buttonLabel }}</p> <p v-if="buttonLabel" class="m-0">{{ buttonLabel }}</p>
@ -36,6 +37,7 @@ export default {
default: "", default: "",
}, },
screenReaderOnlyText: String, screenReaderOnlyText: String,
selectedValues: [Array, String],
hasError: Boolean, hasError: Boolean,
}, },
data() { data() {
@ -44,15 +46,15 @@ export default {
}; };
}, },
created() { created() {
if (this.selectedButtonIDs) { if (this.selectedValues) {
this.checkValue = this.selectedButtonIDs[0]; this.checkValue = this.selectedValues[0] === this.value;
} }
}, },
methods: { methods: {
handleClick(value) { handleClick(value) {
this.handleChange(value); this.handleChange(value);
}, },
handleCheckChanged(newValue, oldValue) { handleCheckChange(newValue, oldValue) {
const isInitialization = typeof oldValue === "function"; const isInitialization = typeof oldValue === "function";
if (!isInitialization) { if (!isInitialization) {
@ -68,19 +70,19 @@ export default {
}, },
}, },
setup(props) { setup(props) {
const { groupName, value } = toRefs(props); const inputType = "radio";
const { checked, handleChange, errorMessage } = useField( const {
groupName, value: inputValue,
undefined, handleChange,
{ errors,
type: "radio", } = useField(props.groupName, props.validationRules,
checkedValue: value, {
} type: inputType,
); checkedValue: props.value,
});
return { return {
checked,
handleChange, handleChange,
errorMessage, errors,
}; };
}, },
}; };