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 new file mode 100644 index 000000000..78ff60bf7 --- /dev/null +++ b/src/digital-components/phone-number-question/phone-number-question.spec.js @@ -0,0 +1,64 @@ +// Components +import phoneNumberQuestion from "./phone-number-question"; + +// Supporting Files +import { shallowMount } from "@vue/test-utils"; + +describe("phone-number-question.vue", () => { + it("Should render phoneNumberQuestion sub-component (textbox-question)", async () => { + // Arrange + const wrapper = shallowMount(phoneNumberQuestion, {}); + + wrapper.getCmsContent = jest.fn(); + + // Act + const phoneNumber = wrapper.findComponent({ ref: "phoneNumber" }); + + // Assert + expect(phoneNumber.exists()).toBe(true); + }); + + it("Should emit new value when modelValue is changed", async () => { + // Act + const wrapper = shallowMount(phoneNumberQuestion, { + propsData: { + modelValue: "val", + }, + }); + + const phoneNumber = wrapper.findComponent({ ref: "phoneNumber" }); + await phoneNumber.setValue("val2"); + + // Assert + expect(wrapper.emitted("update:modelValue")).toEqual([["val2"]]); + }); + + it("Should emit new value when modelValue is changed", async () => { + // Act + const wrapper = shallowMount(phoneNumberQuestion, { + propsData: { + modelValue: "val", + }, + }); + + const phoneNumber = wrapper.findComponent({ ref: "phoneNumber" }); + await phoneNumber.setValue("val2"); + + // Assert + expect(wrapper.emitted("update:modelValue")).toEqual([["val2"]]); + }); + + it("Should combine external and internal validation rules to pass to textbox-question", async () => { + // Act + const wrapper = shallowMount(phoneNumberQuestion, { + propsData: { + validationRules: "outsideValidation", + }, + }); + + // Assert + expect(wrapper.vm.validationRulesForTextBoxQuestion).toEqual( + "outsideValidation|phone-number-format" + ); + }); +}); diff --git a/src/digital-components/phone-number-question/phone-number-question.vue b/src/digital-components/phone-number-question/phone-number-question.vue new file mode 100644 index 000000000..f3fdc6cd6 --- /dev/null +++ b/src/digital-components/phone-number-question/phone-number-question.vue @@ -0,0 +1,95 @@ + + + + + diff --git a/src/digital-components/phonenumber-question/phonenumber-question.spec.js b/src/digital-components/phonenumber-question/phonenumber-question.spec.js deleted file mode 100644 index 3d0843e10..000000000 --- a/src/digital-components/phonenumber-question/phonenumber-question.spec.js +++ /dev/null @@ -1 +0,0 @@ -test.todo("some test to be written in the future"); diff --git a/src/digital-components/phonenumber-question/phonenumber-question.vue b/src/digital-components/phonenumber-question/phonenumber-question.vue deleted file mode 100644 index 7f2525bcb..000000000 --- a/src/digital-components/phonenumber-question/phonenumber-question.vue +++ /dev/null @@ -1,119 +0,0 @@ - - - - - diff --git a/src/digital-components/textarea-question/textarea-question.spec.js b/src/digital-components/textarea-question/textarea-question.spec.js index 3d0843e10..26c0b21ef 100644 --- a/src/digital-components/textarea-question/textarea-question.spec.js +++ b/src/digital-components/textarea-question/textarea-question.spec.js @@ -1 +1,61 @@ -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 maska = jest.fn(); + +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, { + global: { + directives: { + maska: maska, + }, + }, + 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, { + global: { + directives: { + maska: maska, + }, + }, + propsData: { + modelValue: "val", + }, + mixins: [mockMixin], + }); + + await wrapper.find("textarea").setValue("val2"); + + // Assert + expect(wrapper.emitted("update:modelValue")).toEqual([["val2"]]); + }); +}); 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 @@