2018-11-05 15:26:18 +00:00
|
|
|
import { shallowMount, mount } from '@vue/test-utils';
|
2018-11-14 14:00:01 +00:00
|
|
|
import HeaderedInput from '@/components/common/HeaderedInput.vue';
|
2018-11-05 15:26:18 +00:00
|
|
|
|
|
|
|
describe('HeaderedInput.vue', () => {
|
|
|
|
|
|
|
|
it('renders correctly with default props', () => {
|
|
|
|
|
|
|
|
const wrapper = shallowMount(HeaderedInput);
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders correctly with isMultiline props', () => {
|
|
|
|
|
|
|
|
const wrapper = shallowMount(HeaderedInput, {
|
|
|
|
propsData: { isMultiline: true }
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
expect(wrapper.contains("textarea")).toBe(true);
|
|
|
|
expect(wrapper.contains("input")).toBe(false);
|
|
|
|
});
|
|
|
|
|
2018-11-14 14:00:01 +00:00
|
|
|
it('renders correctly with props', () => {
|
2018-11-05 15:26:18 +00:00
|
|
|
let label = "testLabel";
|
2018-11-14 14:00:01 +00:00
|
|
|
let additionalLabel = "addLabel";
|
2018-11-05 15:26:18 +00:00
|
|
|
let width = "30px";
|
|
|
|
let height = "20px";
|
|
|
|
|
|
|
|
const wrapper = shallowMount(HeaderedInput, {
|
2018-11-14 14:00:01 +00:00
|
|
|
propsData: { label, width, height, additionalLabel }
|
2018-11-05 15:26:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.find("input").element.style.width).toMatch(width);
|
|
|
|
expect(wrapper.find("input").element.style.height).toMatch(height);
|
|
|
|
expect(wrapper.find(".labelContainer").text()).toMatch(label);
|
2018-11-14 14:00:01 +00:00
|
|
|
expect(wrapper.find(".hiAddLabel").text()).toMatch(additionalLabel);
|
2018-11-05 15:26:18 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('renders correctly with isOptional props', () => {
|
|
|
|
|
|
|
|
const wrapper = shallowMount(HeaderedInput, {
|
|
|
|
propsData: {
|
|
|
|
isOptional: true
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper.find("h4").text()).toMatch("Optional");
|
|
|
|
});
|
|
|
|
|
|
|
|
it('renders correctly with input error', () => {
|
|
|
|
let error = "testError";
|
|
|
|
|
|
|
|
const wrapper = shallowMount(HeaderedInput, {
|
|
|
|
propsData: {
|
|
|
|
error
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
expect(wrapper.find(".labelContainer").text()).toMatch(error);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('emit setData on input correctly', () => {
|
|
|
|
let testData = "testData";
|
|
|
|
|
|
|
|
const wrapper = mount(HeaderedInput);
|
|
|
|
|
|
|
|
wrapper.find("input").trigger('input');
|
|
|
|
|
|
|
|
expect(wrapper.emitted("setData").length).toEqual(1);
|
|
|
|
|
|
|
|
wrapper.vm.$emit('setData', testData);
|
|
|
|
|
|
|
|
expect(wrapper.emitted("setData")[1][0]).toEqual(testData);
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|