[Improvement] Field: add left-icon prop (#1092)
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`render textarea 1`] = `
|
||||
<div class="van-cell van-hairline van-field">
|
||||
<!---->
|
||||
<!---->
|
||||
<div class="van-cell__value van-cell__value--alone">
|
||||
<textarea class="van-field__control" style="height: auto;"></textarea>
|
||||
<!---->
|
||||
<!---->
|
||||
<!---->
|
||||
</div>
|
||||
<!---->
|
||||
</div>
|
||||
`;
|
||||
@@ -0,0 +1,101 @@
|
||||
import Field from '../';
|
||||
import { mount } from '@vue/test-utils';
|
||||
|
||||
test('input event', () => {
|
||||
const wrapper = mount(Field);
|
||||
const input = wrapper.find('input');
|
||||
|
||||
input.element.value = '1';
|
||||
input.trigger('input');
|
||||
expect(wrapper.emitted('input')[0][0]).toEqual('1');
|
||||
});
|
||||
|
||||
test('click icon event', () => {
|
||||
const onIconClick = jest.fn();
|
||||
const wrapper = mount(Field, {
|
||||
propsData: {
|
||||
icon: 'search',
|
||||
onIconClick
|
||||
}
|
||||
});
|
||||
|
||||
wrapper.find('.van-field__icon').trigger('touchstart');
|
||||
expect(wrapper.emitted('click-icon')).toBeTruthy();
|
||||
expect(onIconClick.mock.calls.length).toBe(1);
|
||||
});
|
||||
|
||||
test('keypress event', () => {
|
||||
const wrapper = mount(Field, {
|
||||
propsData: {
|
||||
value: '',
|
||||
type: 'number'
|
||||
}
|
||||
});
|
||||
|
||||
const fn = jest.fn();
|
||||
const { calls } = fn.mock;
|
||||
const press = keyCode => wrapper.vm.onKeypress({
|
||||
keyCode,
|
||||
preventDefault: fn
|
||||
});
|
||||
|
||||
press(0);
|
||||
expect(calls.length).toBe(1);
|
||||
|
||||
press(50);
|
||||
expect(calls.length).toBe(1);
|
||||
|
||||
wrapper.vm.value = '0.1';
|
||||
press(46);
|
||||
expect(calls.length).toBe(2);
|
||||
|
||||
wrapper.vm.type = 'text';
|
||||
press(0);
|
||||
expect(calls.length).toBe(2);
|
||||
});
|
||||
|
||||
test('render textarea', done => {
|
||||
const wrapper = mount(Field, {
|
||||
propsData: {
|
||||
type: 'textarea',
|
||||
autosize: true
|
||||
}
|
||||
});
|
||||
setTimeout(() => {
|
||||
expect(wrapper.html()).toMatchSnapshot();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
test('autosize textarea field', () => {
|
||||
const wrapper = mount(Field, {
|
||||
propsData: {
|
||||
type: 'textarea',
|
||||
autosize: {}
|
||||
}
|
||||
});
|
||||
|
||||
const longText = '1'.repeat(20);
|
||||
const textarea = wrapper.find('.van-field__control');
|
||||
|
||||
wrapper.vm.value = longText;
|
||||
expect(textarea.element.value).toEqual(longText);
|
||||
});
|
||||
|
||||
test('autosize object', done => {
|
||||
const wrapper = mount(Field, {
|
||||
propsData: {
|
||||
type: 'textarea',
|
||||
autosize: {
|
||||
maxHeight: 100,
|
||||
minHeight: 50
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const textarea = wrapper.find('.van-field__control');
|
||||
setTimeout(() => {
|
||||
expect(textarea.element.style.height).toEqual(('50px'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user