2022-05-06 15:50:20 +01:00
|
|
|
// Copyright (C) 2022 Storj Labs, Inc.
|
2018-11-27 10:51:33 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2022-05-06 15:50:20 +01:00
|
|
|
import VInput from '@/components/common/VInput.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
|
|
|
|
2022-05-06 15:50:20 +01:00
|
|
|
describe('VInput.vue', () => {
|
2019-02-20 13:33:56 +00:00
|
|
|
it('renders correctly with default props', () => {
|
2018-11-05 15:26:18 +00:00
|
|
|
|
2022-05-06 15:50:20 +01:00
|
|
|
const wrapper = shallowMount(VInput);
|
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
|
|
|
|
2022-05-06 15:50:20 +01:00
|
|
|
const wrapper = shallowMount(VInput, {
|
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();
|
2020-09-15 18:05:26 +01:00
|
|
|
expect(wrapper.findAll('textarea').length).toBe(1);
|
|
|
|
expect(wrapper.findAll('input').length).toBe(0);
|
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 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
|
|
|
|
2022-05-06 15:50:20 +01:00
|
|
|
const wrapper = shallowMount(VInput, {
|
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
|
|
|
|
2022-04-07 12:04:24 +01:00
|
|
|
const el = wrapper.find('input').element as HTMLElement;
|
|
|
|
expect(el.style.width).toMatch(width);
|
|
|
|
expect(el.style.height).toMatch(height);
|
|
|
|
|
2019-02-20 13:33:56 +00:00
|
|
|
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
|
|
|
|
2022-05-06 15:50:20 +01:00
|
|
|
const wrapper = shallowMount(VInput, {
|
2019-02-20 13:33:56 +00:00
|
|
|
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
|
|
|
|
2022-05-06 15:50:20 +01:00
|
|
|
const wrapper = shallowMount(VInput, {
|
2019-02-20 13:33:56 +00:00
|
|
|
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
|
|
|
|
2022-05-06 15:50:20 +01:00
|
|
|
const wrapper = mount(VInput);
|
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
|
|
|
|
2020-09-15 18:05:26 +01:00
|
|
|
let emittedSetData = wrapper.emitted('setData');
|
|
|
|
if (emittedSetData) expect(emittedSetData.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
|
|
|
|
2020-09-15 18:05:26 +01:00
|
|
|
emittedSetData = wrapper.emitted('setData');
|
|
|
|
if (emittedSetData) expect(emittedSetData[1][0]).toEqual(testData);
|
2019-02-20 13:33:56 +00:00
|
|
|
});
|
2018-11-05 15:26:18 +00:00
|
|
|
|
2018-12-18 14:43:23 +00:00
|
|
|
});
|