Merge branch '2.x' into dev
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`should render demo and match snapshot 1`] = `
|
||||
<div>
|
||||
<div class="van-cell van-cell--clickable van-field"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
<div class="van-cell__title van-field__label">
|
||||
<span>
|
||||
Area
|
||||
</span>
|
||||
</div>
|
||||
<div class="van-cell__value van-field__value">
|
||||
<div class="van-field__body">
|
||||
<input type="text"
|
||||
class="van-field__control"
|
||||
readonly
|
||||
placeholder="Select Area"
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
<i class="van-badge__wrapper van-icon van-icon-arrow van-cell__right-icon">
|
||||
</i>
|
||||
</div>
|
||||
<transition-stub>
|
||||
</transition-stub>
|
||||
<transition-stub>
|
||||
</transition-stub>
|
||||
</div>
|
||||
<div>
|
||||
<div class="van-cell van-cell--clickable van-field"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
<div class="van-cell__title van-field__label">
|
||||
<span>
|
||||
Area
|
||||
</span>
|
||||
</div>
|
||||
<div class="van-cell__value van-field__value">
|
||||
<div class="van-field__body">
|
||||
<input type="text"
|
||||
class="van-field__control"
|
||||
readonly
|
||||
placeholder="Select Area"
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
<i class="van-badge__wrapper van-icon van-icon-arrow van-cell__right-icon">
|
||||
</i>
|
||||
</div>
|
||||
<transition-stub>
|
||||
</transition-stub>
|
||||
<transition-stub>
|
||||
</transition-stub>
|
||||
</div>
|
||||
<div>
|
||||
<div class="van-cell van-cell--clickable van-field"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
>
|
||||
<div class="van-cell__title van-field__label">
|
||||
<span>
|
||||
Area
|
||||
</span>
|
||||
</div>
|
||||
<div class="van-cell__value van-field__value">
|
||||
<div class="van-field__body">
|
||||
<input type="text"
|
||||
class="van-field__control"
|
||||
readonly
|
||||
placeholder="Select Area"
|
||||
>
|
||||
</div>
|
||||
</div>
|
||||
<i class="van-badge__wrapper van-icon van-icon-arrow van-cell__right-icon">
|
||||
</i>
|
||||
</div>
|
||||
<transition-stub>
|
||||
</transition-stub>
|
||||
<transition-stub>
|
||||
</transition-stub>
|
||||
</div>
|
||||
`;
|
||||
@@ -0,0 +1,4 @@
|
||||
import Demo from '../demo';
|
||||
import { snapshotDemo } from '../../../test/demo';
|
||||
|
||||
snapshotDemo(Demo);
|
||||
@@ -0,0 +1,124 @@
|
||||
import Cascader from '..';
|
||||
import { mount, later } from '../../../test';
|
||||
import options from '../demo/area-en-US';
|
||||
|
||||
test('should emit change event when active option changed', async () => {
|
||||
const wrapper = mount(Cascader, {
|
||||
propsData: {
|
||||
options,
|
||||
},
|
||||
});
|
||||
|
||||
await later();
|
||||
wrapper.find('.van-cascader__option').trigger('click');
|
||||
|
||||
const firstOption = options[0];
|
||||
expect(wrapper.emitted('change')[0]).toEqual([
|
||||
{
|
||||
value: firstOption.value,
|
||||
tabIndex: 0,
|
||||
selectedOptions: [firstOption],
|
||||
},
|
||||
]);
|
||||
|
||||
await later();
|
||||
wrapper
|
||||
.findAll('.van-cascader__options')
|
||||
.at(1)
|
||||
.find('.van-cascader__option')
|
||||
.trigger('click');
|
||||
const secondOption = options[0].children[0];
|
||||
expect(wrapper.emitted('change')[1]).toEqual([
|
||||
{
|
||||
value: secondOption.value,
|
||||
tabIndex: 1,
|
||||
selectedOptions: [firstOption, secondOption],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test('should emit finish event when all options is selected', async () => {
|
||||
const option = { value: '1', text: 'foo' };
|
||||
const wrapper = mount(Cascader, {
|
||||
propsData: {
|
||||
options: [option],
|
||||
},
|
||||
});
|
||||
|
||||
await later();
|
||||
wrapper.find('.van-cascader__option').trigger('click');
|
||||
expect(wrapper.emitted('finish')[0]).toEqual([
|
||||
{
|
||||
value: option.value,
|
||||
tabIndex: 0,
|
||||
selectedOptions: [option],
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test('should emit close event when close icon is clicked', () => {
|
||||
const wrapper = mount(Cascader);
|
||||
wrapper.find('.van-cascader__close-icon').trigger('click');
|
||||
expect(wrapper.emitted('close')[0]).toBeTruthy();
|
||||
});
|
||||
|
||||
test('should not render close icon when closeable is false', () => {
|
||||
const wrapper = mount(Cascader, {
|
||||
propsData: {
|
||||
closeable: false,
|
||||
},
|
||||
});
|
||||
expect(wrapper.contains('.van-cascader__close-icon')).toBeFalsy();
|
||||
});
|
||||
|
||||
test('should render title slot correctly', () => {
|
||||
const wrapper = mount(Cascader, {
|
||||
scopedSlots: {
|
||||
title: () => 'Custom Title',
|
||||
},
|
||||
});
|
||||
expect(wrapper.find('.van-cascader__title').html()).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should select correct option when value changed', async () => {
|
||||
const wrapper = mount(Cascader, {
|
||||
propsData: {
|
||||
options,
|
||||
},
|
||||
});
|
||||
|
||||
await later();
|
||||
wrapper.setProps({ value: '330304' });
|
||||
await later();
|
||||
const selectedOptions = wrapper.findAll('.van-cascader__option--selected');
|
||||
const lastSelectedOption = selectedOptions.at(selectedOptions.length - 1);
|
||||
expect(lastSelectedOption).toMatchSnapshot();
|
||||
});
|
||||
|
||||
test('should reset selected options when value is set to emtpy', async () => {
|
||||
const wrapper = mount(Cascader, {
|
||||
propsData: {
|
||||
value: '330304',
|
||||
options,
|
||||
},
|
||||
});
|
||||
|
||||
await later();
|
||||
wrapper.setProps({ value: '' });
|
||||
await later();
|
||||
expect(wrapper.contains('.van-cascader__option--selected')).toBeFalsy();
|
||||
});
|
||||
|
||||
test('should update tabs when previous tab is clicked', async () => {
|
||||
const wrapper = mount(Cascader, {
|
||||
propsData: {
|
||||
value: '330304',
|
||||
options,
|
||||
},
|
||||
});
|
||||
|
||||
await later();
|
||||
wrapper.findAll('.van-cascader__option').at(1).trigger('click');
|
||||
await later();
|
||||
expect(wrapper.html()).toMatchSnapshot();
|
||||
});
|
||||
Reference in New Issue
Block a user