Unit tests ready
This commit is contained in:
parent
357c16539f
commit
71555378d5
3 changed files with 88 additions and 36 deletions
|
|
@ -48,7 +48,7 @@ describe("phone-number-question.vue", () => {
|
||||||
expect(wrapper.emitted("update:modelValue")).toEqual([["val2"]]);
|
expect(wrapper.emitted("update:modelValue")).toEqual([["val2"]]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Should combine external and internal validation rules to pass to textbox-question", async() => {
|
it("Should combine external and internal validation rules to pass to textbox-question", async () => {
|
||||||
// Act
|
// Act
|
||||||
const wrapper = shallowMount(phoneNumberQuestion, {
|
const wrapper = shallowMount(phoneNumberQuestion, {
|
||||||
propsData: {
|
propsData: {
|
||||||
|
|
@ -57,6 +57,8 @@ describe("phone-number-question.vue", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
expect(wrapper.vm.validationRulesForTextBoxQuestion).toEqual("outsideValidation|phone-number-format");
|
expect(wrapper.vm.validationRulesForTextBoxQuestion).toEqual(
|
||||||
|
"outsideValidation|phone-number-format"
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -1 +1,65 @@
|
||||||
test.todo("some test to be written in the future");
|
// Components
|
||||||
|
import textareaQuestion from "./textarea-question";
|
||||||
|
|
||||||
|
// Supporting Files
|
||||||
|
import { shallowMount } from "@vue/test-utils";
|
||||||
|
|
||||||
|
const questionText = "textareaQuestionText";
|
||||||
|
const mockMixin = {
|
||||||
|
methods: {
|
||||||
|
getCmsContent: jest.fn().mockImplementation(() => {
|
||||||
|
return questionText;
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
describe("textarea-question.vue", () => {
|
||||||
|
it("Should render a textarea", async () => {
|
||||||
|
// Arrange
|
||||||
|
const wrapper = shallowMount(textareaQuestion, {
|
||||||
|
propsData: {
|
||||||
|
modelValue: "",
|
||||||
|
},
|
||||||
|
mixins: [mockMixin],
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.getCmsContent = jest.fn();
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const textarea = wrapper.find("textarea");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(textarea.exists()).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should emit new value when modelValue is changed", async () => {
|
||||||
|
// Act
|
||||||
|
const wrapper = shallowMount(textareaQuestion, {
|
||||||
|
propsData: {
|
||||||
|
modelValue: "val",
|
||||||
|
},
|
||||||
|
mixins: [mockMixin],
|
||||||
|
});
|
||||||
|
|
||||||
|
await wrapper.find("textarea").setValue("val2");
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.emitted("update:modelValue")).toEqual([["val2"]]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should limit the number of characters entered to the max length value property passed in", async () => {
|
||||||
|
// Act
|
||||||
|
const wrapper = shallowMount(textareaQuestion, {
|
||||||
|
propsData: {
|
||||||
|
modelValue: "123456789",
|
||||||
|
maxLength: 10,
|
||||||
|
},
|
||||||
|
mixins: [mockMixin],
|
||||||
|
});
|
||||||
|
|
||||||
|
wrapper.vm.value = "12345678910";
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(wrapper.vm.value).toEqual("1234567891");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,16 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="textarea-question">
|
<div class="textarea-question">
|
||||||
<div class="label-wrapper mb-1" :aria-label="TextAreaContentWidget">
|
<div class="label-wrapper mb-1" :aria-label="questionText">
|
||||||
<!-- Wrap label and span because v-html prevents v-if from displaying if v-if <span> is inside <label>-->
|
<!-- Wrap label and span because v-html prevents v-if from displaying if v-if <span> is inside <label>-->
|
||||||
<label for="textarea-comments" class="fw-bold" v-html="TextAreaContentWidget"></label>
|
<label for="textarea-question" class="fw-bold" v-html="questionText"></label>
|
||||||
<span v-if="!isRequired" class="fw-normal ms-1">(Optional)</span>
|
<span v-if="!isRequired" class="fw-normal ms-1">(Optional)</span>
|
||||||
</div>
|
</div>
|
||||||
<textarea
|
<textarea
|
||||||
|
id="textareaQuestion"
|
||||||
|
ref="textarea"
|
||||||
v-model="value"
|
v-model="value"
|
||||||
|
v-maska="mask"
|
||||||
@keyup="updateCount"
|
@keyup="updateCount"
|
||||||
id="textarea-comments"
|
|
||||||
class="p-4"
|
class="p-4"
|
||||||
:maxlength="maxLength"
|
:maxlength="maxLength"
|
||||||
role="textbox"
|
role="textbox"
|
||||||
|
|
@ -18,7 +20,7 @@
|
||||||
<p
|
<p
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
class="caption mt-2 mb-0"
|
class="caption mt-2 mb-0"
|
||||||
id="charactersremaining"
|
id="charactersRemaining"
|
||||||
:class="[urgentCountdown ? 'urgent-countdown' : '']">
|
:class="[urgentCountdown ? 'urgent-countdown' : '']">
|
||||||
{{ remainingCount }}/{{ maxLength }} characters remaining
|
{{ remainingCount }}/{{ maxLength }} characters remaining
|
||||||
</p>
|
</p>
|
||||||
|
|
@ -37,30 +39,10 @@ export default {
|
||||||
},
|
},
|
||||||
modelValue: String,
|
modelValue: String,
|
||||||
},
|
},
|
||||||
setup(props) {
|
// TODO: At some point in the future we should probably add the tie in to validation here in case the field must be populated for some other use cases
|
||||||
const inputId = !props.customInputId ? `input-${crypto.randomUUID()}` : props.customInputId;
|
setup() {},
|
||||||
|
|
||||||
const propsClone = Object.assign({}, props);
|
|
||||||
const modelValue = propsClone.modelValue;
|
|
||||||
let initialValue;
|
|
||||||
|
|
||||||
switch (typeof modelValue) {
|
|
||||||
case "number":
|
|
||||||
initialValue = modelValue;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
initialValue = modelValue && modelValue.length > 0 ? modelValue : "";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
const fieldOptions = {
|
|
||||||
type: "text",
|
|
||||||
value: modelValue,
|
|
||||||
initialValue: initialValue,
|
|
||||||
};
|
|
||||||
},
|
|
||||||
computed: {
|
computed: {
|
||||||
TextAreaContentWidget() {
|
questionText() {
|
||||||
return this.getCmsContent(this.cmsWidgetName, "QuestionText");
|
return this.getCmsContent(this.cmsWidgetName, "QuestionText");
|
||||||
},
|
},
|
||||||
value: {
|
value: {
|
||||||
|
|
@ -77,12 +59,16 @@ export default {
|
||||||
urgentCountdown() {
|
urgentCountdown() {
|
||||||
return this.remainingCount <= this.maxLength * 0.1 ? true : false;
|
return this.remainingCount <= this.maxLength * 0.1 ? true : false;
|
||||||
},
|
},
|
||||||
},
|
mask() {
|
||||||
methods: {
|
// Allow any character but only the max length number of times.
|
||||||
updateCount() {
|
return {
|
||||||
if (this.value.length > this.maxLength) {
|
mask: `x*${this.maxLength}`,
|
||||||
this.value = this.value.slice(0, this.maxLength);
|
tokens: {
|
||||||
}
|
x: {
|
||||||
|
pattern: /.|\n|\r/,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue