2019-01-24 20:15:10 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-27 10:51:33 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2018-11-14 14:00:01 +00:00
|
|
|
import HeaderedInput from '@/components/common/HeaderedInput.vue';
|
2018-11-05 15:26:18 +00:00
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
import { mount, shallowMount } from '@vue/test-utils';
|
2018-12-18 14:43:23 +00:00
|
|
|
|
2019-09-09 11:33:39 +01:00
|
|
|
describe('HeaderedInput.vue', () => {
|
2019-02-20 13:33:56 +00:00
|
|
|
it('renders correctly with default props', () => {
|
2018-11-05 15:26:18 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
const wrapper = shallowMount(HeaderedInput);
|
2018-11-05 15:26:18 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
});
|
2018-11-05 15:26:18 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
it('renders correctly with isMultiline props', () => {
|
2018-11-05 15:26:18 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
const wrapper = shallowMount(HeaderedInput, {
|
2019-09-13 15:58:18 +01:00
|
|
|
propsData: {isMultiline: true},
|
2019-02-20 13:33:56 +00:00
|
|
|
});
|
2018-11-05 15:26:18 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
expect(wrapper.contains('textarea')).toBe(true);
|
|
|
|
expect(wrapper.contains('input')).toBe(false);
|
|
|
|
});
|
2018-11-05 15:26:18 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
it('renders correctly with props', () => {
|
2019-09-09 11:33:39 +01:00
|
|
|
const label = 'testLabel';
|
|
|
|
const additionalLabel = 'addLabel';
|
|
|
|
const width = '30px';
|
|
|
|
const height = '20px';
|
2018-11-05 15:26:18 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
const wrapper = shallowMount(HeaderedInput, {
|
2019-09-13 15:58:18 +01:00
|
|
|
propsData: {label, width, height, additionalLabel},
|
2019-02-20 13:33:56 +00:00
|
|
|
});
|
2018-11-05 15:26:18 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
expect(wrapper.find('input').element.style.width).toMatch(width);
|
|
|
|
expect(wrapper.find('input').element.style.height).toMatch(height);
|
|
|
|
expect(wrapper.find('.label-container').text()).toMatch(label);
|
2019-09-26 14:36:12 +01:00
|
|
|
expect(wrapper.find('.add-label').text()).toMatch(additionalLabel);
|
2019-02-20 13:33:56 +00:00
|
|
|
});
|
2018-11-05 15:26:18 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
it('renders correctly with isOptional props', () => {
|
2018-11-05 15:26:18 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
const wrapper = shallowMount(HeaderedInput, {
|
|
|
|
propsData: {
|
2019-09-13 15:58:18 +01:00
|
|
|
isOptional: true,
|
|
|
|
},
|
2019-02-20 13:33:56 +00:00
|
|
|
});
|
2018-11-05 15:26:18 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
expect(wrapper.find('h4').text()).toMatch('Optional');
|
|
|
|
});
|
2018-12-18 14:43:23 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
it('renders correctly with input error', () => {
|
2019-09-09 11:33:39 +01:00
|
|
|
const error = 'testError';
|
2018-11-05 15:26:18 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
const wrapper = shallowMount(HeaderedInput, {
|
|
|
|
propsData: {
|
2019-09-13 15:58:18 +01:00
|
|
|
error,
|
|
|
|
},
|
2019-02-20 13:33:56 +00:00
|
|
|
});
|
2018-11-05 15:26:18 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
expect(wrapper).toMatchSnapshot();
|
|
|
|
expect(wrapper.find('.label-container').text()).toMatch(error);
|
|
|
|
});
|
2018-12-18 14:43:23 +00:00
|
|
|
|
2020-01-08 15:58:28 +00:00
|
|
|
it('emit setData on input correctly', async () => {
|
2019-09-09 11:33:39 +01:00
|
|
|
const testData = 'testData';
|
2018-11-05 15:26:18 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
const wrapper = mount(HeaderedInput);
|
2018-11-05 15:26:18 +00:00
|
|
|
|
2020-01-08 15:58:28 +00:00
|
|
|
await wrapper.find('input').trigger('input');
|
2018-12-18 14:43:23 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
expect(wrapper.emitted('setData').length).toEqual(1);
|
2018-11-05 15:26:18 +00:00
|
|
|
|
2020-01-08 15:58:28 +00:00
|
|
|
await wrapper.vm.$emit('setData', testData);
|
2018-11-05 15:26:18 +00:00
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
expect(wrapper.emitted('setData')[1][0]).toEqual(testData);
|
|
|
|
});
|
2018-11-05 15:26:18 +00:00
|
|
|
|
2018-12-18 14:43:23 +00:00
|
|
|
});
|