178 lines
4.1 KiB
Text
178 lines
4.1 KiB
Text
import { shallowMount } from "@vue/test-utils";
|
||
import textboxQuestion from "./textbox-question";
|
||
import { maska } from 'maska';
|
||
|
||
describe("textboxQuestion.vue", () => {
|
||
|
||
it("Should return aria-disabled state", async () => {
|
||
// Act
|
||
const wrapper = shallowMount(textboxQuestion, {
|
||
global: {
|
||
directives: {
|
||
maska: maska,
|
||
}
|
||
},
|
||
propsData: {
|
||
isDisabled: true,
|
||
},
|
||
});
|
||
|
||
// Assert
|
||
const input = wrapper.find("input");
|
||
|
||
// Expect
|
||
expect(input.attributes()["aria-disabled"]).toEqual("true");
|
||
|
||
});
|
||
|
||
it("Should render a text input", async () => {
|
||
// Act
|
||
const wrapper = shallowMount(textboxQuestion, {
|
||
global: {
|
||
directives: {
|
||
maska: maska,
|
||
}
|
||
},
|
||
propsData: {
|
||
name: "test",
|
||
label: "unit test label",
|
||
},
|
||
});
|
||
|
||
// Assert
|
||
const input = wrapper.find("input");
|
||
|
||
expect(input.exists()).toBe(true);
|
||
|
||
});
|
||
|
||
it("Should return input id", async () => {
|
||
// Act
|
||
const wrapper = shallowMount(textboxQuestion, {
|
||
global: {
|
||
directives: {
|
||
maska: maska,
|
||
}
|
||
},
|
||
propsData: {
|
||
inputId: "input ID",
|
||
},
|
||
});
|
||
|
||
// Assert
|
||
const input = wrapper.find("input");
|
||
|
||
// Expect
|
||
expect(input.attributes().id).toEqual("input ID");
|
||
|
||
});
|
||
|
||
it("Should render the 'questionText' data value as the aria-label attribute.", async () => {
|
||
// Arrange
|
||
//Mock CMS content
|
||
const questionText = "Question Text";
|
||
const cmsContent = {
|
||
QuestionText: questionText,
|
||
};
|
||
|
||
// Act
|
||
const wrapper = shallowMount(textboxQuestion, {
|
||
global: {
|
||
directives: {
|
||
maska: maska,
|
||
}
|
||
},
|
||
});
|
||
await wrapper.setData({
|
||
questionText: questionText,
|
||
});
|
||
wrapper.vm.initializeComponent(cmsContent);
|
||
|
||
// Assert
|
||
expect(wrapper.find("label").attributes('aria-label')).toBe(questionText);
|
||
wrapper.unmount();
|
||
|
||
});
|
||
|
||
it("Should render the 'questionText' data value as the label text when disableAutoFill is false.", async () => {
|
||
// Arrange
|
||
//Mock CMS content
|
||
const questionText = "Question Text";
|
||
const cmsContent = {
|
||
QuestionText: questionText,
|
||
};
|
||
|
||
// Act
|
||
const wrapper = shallowMount(textboxQuestion, {
|
||
global: {
|
||
directives: {
|
||
maska: maska,
|
||
}
|
||
},
|
||
});
|
||
await wrapper.setData({
|
||
questionText: questionText,
|
||
});
|
||
wrapper.vm.initializeComponent(cmsContent);
|
||
|
||
// Assert
|
||
expect(wrapper.find("label").text()).toContain(questionText);
|
||
wrapper.unmount();
|
||
|
||
});
|
||
|
||
it("Should render the 'questionText' data value with '⁠' after the first character as the label text when disableAutoFill is true.", async () => {
|
||
// Arrange
|
||
//Mock CMS content
|
||
const originalQuestionText = "Question Text";
|
||
// Trust me, the below instance of the string "Question Text" actually has the ⁠ in it. You just can't see it
|
||
// Don't believe me? Copy it and paste it into Google. Then inspect the search field element in Dev Tools,
|
||
// you will see "Q&uestion Text"
|
||
const expectedQuestionText = "Question Text";
|
||
const cmsContent = {
|
||
QuestionText: originalQuestionText,
|
||
};
|
||
|
||
// Act
|
||
const wrapper = shallowMount(textboxQuestion, {
|
||
global: {
|
||
directives: {
|
||
maska: maska,
|
||
}
|
||
},
|
||
propsData: {
|
||
disableAutoFill: true,
|
||
},
|
||
});
|
||
await wrapper.setData({
|
||
questionText: originalQuestionText,
|
||
});
|
||
wrapper.vm.initializeComponent(cmsContent);
|
||
|
||
// Assert
|
||
expect(wrapper.vm.$el.children[0].innerHTML).toBe(expectedQuestionText);
|
||
wrapper.unmount();
|
||
|
||
});
|
||
|
||
it("Should emit new value when modelValue is changed", async () => {
|
||
// Act
|
||
const wrapper = shallowMount(textboxQuestion, {
|
||
global: {
|
||
directives: {
|
||
maska: maska,
|
||
}
|
||
},
|
||
propsData: {
|
||
modelValue: "val",
|
||
},
|
||
});
|
||
|
||
await wrapper.find("input").setValue("val2");
|
||
|
||
// Assert
|
||
expect(wrapper.emitted()).toHaveProperty('change')
|
||
|
||
});
|
||
|
||
});
|