fix(Picker): update cascade after setColumnIndex (#5807)

This commit is contained in:
chenjiahan 2020-03-17 20:01:15 +08:00
parent 9c55056b0a
commit 68f5d3d69b
2 changed files with 63 additions and 31 deletions

View File

@ -176,7 +176,14 @@ export default createComponent({
// set column option index by column index
setColumnIndex(columnIndex, optionIndex) {
const column = this.getColumn(columnIndex);
column && column.setIndex(optionIndex);
if (column) {
column.setIndex(optionIndex);
if (this.dataType === 'cascade') {
this.onCascadeChange(columnIndex);
}
}
},
// @exposed-api

View File

@ -1,59 +1,84 @@
import Picker from '..';
import { mount, triggerDrag } from '../../../test';
import { cascadeColumns } from '../demo/data';
const COLUMNS = [
{
text: 'A1',
children: [
{
text: 'B1',
children: [{ text: 'C1' }, { text: 'C2' }],
},
{
text: 'B2',
children: [{ text: 'C3' }, { text: 'C4' }],
},
],
},
{
text: 'A2',
children: [
{
text: 'B3',
children: [{ text: 'C5' }, { text: 'C6' }],
},
{
text: 'B4',
children: [{ text: 'C7' }, { text: 'C8' }],
},
],
},
];
test('cascade columns', () => {
const wrapper = mount(Picker, {
propsData: {
showToolbar: true,
columns: cascadeColumns['en-US'],
columns: COLUMNS,
},
});
wrapper.find('.van-picker__confirm').trigger('click');
expect(wrapper.emitted('confirm')[0][0]).toEqual([
'Zhejiang',
'Hangzhou',
'Xihu',
]);
expect(wrapper.emitted('confirm')[0][0]).toEqual(['A1', 'B1', 'C1']);
triggerDrag(wrapper.find('.van-picker-column'), 0, -100);
wrapper.find('.van-picker-column ul').trigger('transitionend');
expect(wrapper.emitted('change')[0][1]).toEqual([
'Fujian',
'Fuzhou',
'Gulou',
]);
expect(wrapper.emitted('change')[0][1]).toEqual(['A2', 'B3', 'C5']);
wrapper.find('.van-picker__confirm').trigger('click');
expect(wrapper.emitted('confirm')[1][0]).toEqual([
'Fujian',
'Fuzhou',
'Gulou',
]);
expect(wrapper.emitted('confirm')[1][0]).toEqual(['A2', 'B3', 'C5']);
});
test('setColumnValue of cascade columns', () => {
const wrapper = mount(Picker, {
propsData: {
showToolbar: true,
columns: cascadeColumns['en-US'],
columns: COLUMNS,
},
});
wrapper.vm.setColumnValue(0, 'Fujian');
wrapper.vm.setColumnValue(0, 'A2');
wrapper.find('.van-picker__confirm').trigger('click');
expect(wrapper.emitted('confirm')[0][0]).toEqual([
'Fujian',
'Fuzhou',
'Gulou',
]);
expect(wrapper.emitted('confirm')[0][0]).toEqual(['A2', 'B3', 'C5']);
wrapper.vm.setColumnValue(1, 'Xiamen');
wrapper.vm.setColumnValue(1, 'B4');
wrapper.find('.van-picker__confirm').trigger('click');
expect(wrapper.emitted('confirm')[1][0]).toEqual([
'Fujian',
'Xiamen',
'Siming',
]);
expect(wrapper.emitted('confirm')[1][0]).toEqual(['A2', 'B4', 'C7']);
});
test('setColumnIndex of cascade columns', () => {
const wrapper = mount(Picker, {
propsData: {
showToolbar: true,
columns: COLUMNS,
},
});
wrapper.vm.setColumnIndex(0, 1);
wrapper.find('.van-picker__confirm').trigger('click');
expect(wrapper.emitted('confirm')[0][0]).toEqual(['A2', 'B3', 'C5']);
wrapper.vm.setColumnIndex(1, 1);
wrapper.find('.van-picker__confirm').trigger('click');
expect(wrapper.emitted('confirm')[1][0]).toEqual(['A2', 'B4', 'C7']);
});