From 71555378d55aab6b623b42d48cb601451f61756e Mon Sep 17 00:00:00 2001 From: Leah Schumann Date: Mon, 10 Jul 2023 10:05:45 -0400 Subject: [PATCH] Unit tests ready --- .../phone-number-question.spec.js | 6 +- .../textarea-question.spec.js | 66 ++++++++++++++++++- .../textarea-question/textarea-question.vue | 52 ++++++--------- 3 files changed, 88 insertions(+), 36 deletions(-) diff --git a/src/digital-components/phone-number-question/phone-number-question.spec.js b/src/digital-components/phone-number-question/phone-number-question.spec.js index a3b6e9424..78ff60bf7 100644 --- a/src/digital-components/phone-number-question/phone-number-question.spec.js +++ b/src/digital-components/phone-number-question/phone-number-question.spec.js @@ -48,7 +48,7 @@ describe("phone-number-question.vue", () => { 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 const wrapper = shallowMount(phoneNumberQuestion, { propsData: { @@ -57,6 +57,8 @@ describe("phone-number-question.vue", () => { }); // Assert - expect(wrapper.vm.validationRulesForTextBoxQuestion).toEqual("outsideValidation|phone-number-format"); + expect(wrapper.vm.validationRulesForTextBoxQuestion).toEqual( + "outsideValidation|phone-number-format" + ); }); }); diff --git a/src/digital-components/textarea-question/textarea-question.spec.js b/src/digital-components/textarea-question/textarea-question.spec.js index 3d0843e10..93b6cad54 100644 --- a/src/digital-components/textarea-question/textarea-question.spec.js +++ b/src/digital-components/textarea-question/textarea-question.spec.js @@ -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"); + }); +}); diff --git a/src/digital-components/textarea-question/textarea-question.vue b/src/digital-components/textarea-question/textarea-question.vue index e4e48092d..0ffe5ec0a 100644 --- a/src/digital-components/textarea-question/textarea-question.vue +++ b/src/digital-components/textarea-question/textarea-question.vue @@ -1,14 +1,16 @@