commit
24862ec0e1
8 changed files with 5 additions and 121 deletions
|
|
@ -1,35 +0,0 @@
|
|||
import { shallowMount } from "@vue/test-utils";
|
||||
import textInput from "./text-input";
|
||||
|
||||
describe("text-input.vue", () => {
|
||||
it("Should render a text input", async () => {
|
||||
// Act
|
||||
const wrapper = shallowMount(textInput, {
|
||||
propsData: {
|
||||
name: "test",
|
||||
label: "unit test label",
|
||||
},
|
||||
});
|
||||
|
||||
// Assert
|
||||
const input = wrapper.find("input");
|
||||
|
||||
expect(input.exists()).toBe(true);
|
||||
});
|
||||
|
||||
it("Should return aria-required state", async () => {
|
||||
// Act
|
||||
const wrapper = shallowMount(textInput, {
|
||||
propsData: {
|
||||
name: "test",
|
||||
label: "unit test label",
|
||||
isRequired: true,
|
||||
},
|
||||
});
|
||||
|
||||
// Assert
|
||||
const input = wrapper.find("input");
|
||||
|
||||
expect(input.attributes()["aria-required"]).toEqual("true");
|
||||
});
|
||||
});
|
||||
|
|
@ -1,71 +0,0 @@
|
|||
<!-- Simple implementation of an input field -->
|
||||
<template>
|
||||
<div class="d-flex w-50 mb-2" :class="{ 'has-error': !!errorMessage }">
|
||||
<input
|
||||
type="text"
|
||||
:name="name"
|
||||
:value="inputValue"
|
||||
:id="name"
|
||||
:aria-required="isRequired"
|
||||
@input="handleChange"
|
||||
@blur="handleBlur"
|
||||
:data-focus-target="name"
|
||||
/>
|
||||
<label
|
||||
:for="name"
|
||||
:aria-labelledby="name"
|
||||
class="d-flex justify-content-center py-3 px-4"
|
||||
>
|
||||
<span class="m-0">{{ label }}</span>
|
||||
</label>
|
||||
</div>
|
||||
<div v-show="errorMessage" class="row px-3 form-test-error">
|
||||
{{ errorMessage }}
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { useField } from "vee-validate";
|
||||
|
||||
export default {
|
||||
name: "textInput",
|
||||
props: {
|
||||
type: {
|
||||
type: String,
|
||||
default: "text",
|
||||
},
|
||||
value: {
|
||||
type: String,
|
||||
default: "",
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
label: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
isRequired: Boolean,
|
||||
},
|
||||
setup(props) {
|
||||
const {
|
||||
value: inputValue,
|
||||
errorMessage,
|
||||
handleBlur,
|
||||
handleChange,
|
||||
meta,
|
||||
} = useField(props.name, undefined, {
|
||||
initialValue: props.value,
|
||||
});
|
||||
|
||||
return {
|
||||
handleChange,
|
||||
handleBlur,
|
||||
errorMessage,
|
||||
inputValue,
|
||||
meta,
|
||||
};
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
@ -167,7 +167,7 @@ describe("textboxQuestion.vue", () => {
|
|||
|
||||
});
|
||||
|
||||
it("Should call this.handleChange with new value when this.semiAggressiveValidation = true, the value is changed, and the new value is valid", async () => {
|
||||
it("Should call this.handleChange with new value when the value is changed and the new value is valid", async () => {
|
||||
// Arrange
|
||||
const wrapper = shallowMount(textboxQuestion, {
|
||||
global: {
|
||||
|
|
@ -178,7 +178,6 @@ describe("textboxQuestion.vue", () => {
|
|||
propsData: {
|
||||
options: {},
|
||||
modelValue: "foo",
|
||||
semiAggressiveValidation: true,
|
||||
},
|
||||
mixins: [mockMixin]
|
||||
});
|
||||
|
|
|
|||
|
|
@ -55,7 +55,6 @@ export default {
|
|||
default: "",
|
||||
},
|
||||
validationRules: String,
|
||||
semiAggressiveValidation: Boolean,
|
||||
cmsWidgetName: String,
|
||||
maxLength: String,
|
||||
},
|
||||
|
|
@ -130,12 +129,10 @@ export default {
|
|||
},
|
||||
watch: {
|
||||
async value(newValue) {
|
||||
if (this.semiAggressiveValidation) {
|
||||
const result = await validate(newValue, this.validationRules); // do a test validation check, without triggering full validation
|
||||
if (result.valid) {
|
||||
this.handleChange(newValue); // trigger full validation on this field only
|
||||
}
|
||||
}
|
||||
const result = await validate(newValue, this.validationRules); // do a test validation check, without triggering full validation
|
||||
if (result.valid) {
|
||||
this.handleChange(newValue); // trigger full validation on this field only
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@
|
|||
inputId="cbf28188fdf2436688fd735915f7ee56"
|
||||
disableAutoFill
|
||||
validationRules="city-required"
|
||||
semiAggressiveValidation
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -52,7 +51,6 @@
|
|||
mask="#####"
|
||||
disableAutoFill
|
||||
validationRules="zip-code-required|zip-code-format"
|
||||
semiAggressiveValidation
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@
|
|||
inputId="00450a91b8964a768ce3992e6feb890f"
|
||||
disableAutoFill
|
||||
validationRules="email-address-required|email-address-format"
|
||||
semiAggressiveValidation
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@
|
|||
v-model="email"
|
||||
inputId="email"
|
||||
validationRules="email-address-required|email-address-format"
|
||||
semiAggressiveValidation
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -54,7 +53,6 @@
|
|||
v-model="serviceZip"
|
||||
inputId="serviceZip"
|
||||
validationRules="zip-required|zip-format"
|
||||
semiAggressiveValidation
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -57,7 +57,6 @@
|
|||
isRequired
|
||||
disableAutoFill
|
||||
validationRules="email-address-required|email-address-format"
|
||||
semiAggressiveValidation
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in a new issue