mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-22 22:49:15 +08:00
[bugfix] Area: fix test cases (#1392)
This commit is contained in:
parent
7f4ad6a28d
commit
541299ccd5
@ -30,9 +30,12 @@ export default create({
|
|||||||
value: String,
|
value: String,
|
||||||
title: String,
|
title: String,
|
||||||
loading: Boolean,
|
loading: Boolean,
|
||||||
areaList: Object,
|
|
||||||
itemHeight: Number,
|
itemHeight: Number,
|
||||||
visibleItemCount: Number,
|
visibleItemCount: Number,
|
||||||
|
areaList: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({})
|
||||||
|
},
|
||||||
columnsNum: {
|
columnsNum: {
|
||||||
type: [String, Number],
|
type: [String, Number],
|
||||||
default: 3
|
default: 3
|
||||||
@ -67,21 +70,21 @@ export default create({
|
|||||||
watch: {
|
watch: {
|
||||||
value() {
|
value() {
|
||||||
this.code = this.value;
|
this.code = this.value;
|
||||||
},
|
|
||||||
|
|
||||||
code() {
|
|
||||||
this.setValues();
|
this.setValues();
|
||||||
},
|
},
|
||||||
|
|
||||||
areaList: {
|
areaList: {
|
||||||
deep: true,
|
deep: true,
|
||||||
immediate: true,
|
|
||||||
handler() {
|
handler() {
|
||||||
this.$nextTick(this.setValues);
|
this.setValues();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
mounted() {
|
||||||
|
this.setValues();
|
||||||
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
// get list by code
|
// get list by code
|
||||||
getList(type, code) {
|
getList(type, code) {
|
||||||
@ -120,9 +123,8 @@ export default create({
|
|||||||
|
|
||||||
onChange(picker, values, index) {
|
onChange(picker, values, index) {
|
||||||
this.code = values[index].code;
|
this.code = values[index].code;
|
||||||
this.$nextTick(() => {
|
this.setValues();
|
||||||
this.$emit('change', picker, values, index);
|
this.$emit('change', picker, values, index);
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
setValues() {
|
setValues() {
|
||||||
@ -143,13 +145,11 @@ export default create({
|
|||||||
}
|
}
|
||||||
|
|
||||||
picker.setColumnValues(2, this.getList('county', code.slice(0, 4)));
|
picker.setColumnValues(2, this.getList('county', code.slice(0, 4)));
|
||||||
this.$nextTick(() => {
|
|
||||||
picker.setIndexes([
|
picker.setIndexes([
|
||||||
this.getIndex('province', code),
|
this.getIndex('province', code),
|
||||||
this.getIndex('city', code),
|
this.getIndex('city', code),
|
||||||
this.getIndex('county', code)
|
this.getIndex('county', code)
|
||||||
]);
|
]);
|
||||||
});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
getValues() {
|
getValues() {
|
||||||
|
@ -33,13 +33,22 @@ exports[`change option 2`] = `
|
|||||||
<!---->
|
<!---->
|
||||||
<div class="van-picker__columns" style="height: 220px;">
|
<div class="van-picker__columns" style="height: 220px;">
|
||||||
<div class="van-picker-column" style="height: 220px;">
|
<div class="van-picker-column" style="height: 220px;">
|
||||||
<ul style="line-height: 44px;"></ul>
|
<ul style="line-height: 44px;">
|
||||||
|
<li class="van-ellipsis van-picker-column__item">北京市</li>
|
||||||
|
<li class="van-ellipsis van-picker-column__item van-picker-column__item--selected">天津市</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="van-picker-column" style="height: 220px;">
|
<div class="van-picker-column" style="height: 220px;">
|
||||||
<ul style="line-height: 44px;"></ul>
|
<ul style="line-height: 44px;">
|
||||||
|
<li class="van-ellipsis van-picker-column__item van-picker-column__item--selected">天津市</li>
|
||||||
|
<li class="van-ellipsis van-picker-column__item">县</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="van-picker-column" style="height: 220px;">
|
<div class="van-picker-column" style="height: 220px;">
|
||||||
<ul style="line-height: 44px;"></ul>
|
<ul style="line-height: 44px;">
|
||||||
|
<li class="van-ellipsis van-picker-column__item van-picker-column__item--selected">和平区</li>
|
||||||
|
<li class="van-ellipsis van-picker-column__item">河东区</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="van-hairline--top-bottom van-picker__frame" style="height: 44px;"></div>
|
<div class="van-hairline--top-bottom van-picker__frame" style="height: 44px;"></div>
|
||||||
</div>
|
</div>
|
||||||
@ -56,20 +65,29 @@ exports[`change option 3`] = `
|
|||||||
<!---->
|
<!---->
|
||||||
<div class="van-picker__columns" style="height: 220px;">
|
<div class="van-picker__columns" style="height: 220px;">
|
||||||
<div class="van-picker-column" style="height: 220px;">
|
<div class="van-picker-column" style="height: 220px;">
|
||||||
<ul style="line-height: 44px;"></ul>
|
<ul style="line-height: 44px;">
|
||||||
|
<li class="van-ellipsis van-picker-column__item">北京市</li>
|
||||||
|
<li class="van-ellipsis van-picker-column__item van-picker-column__item--selected">天津市</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="van-picker-column" style="height: 220px;">
|
<div class="van-picker-column" style="height: 220px;">
|
||||||
<ul style="line-height: 44px;"></ul>
|
<ul style="line-height: 44px;">
|
||||||
|
<li class="van-ellipsis van-picker-column__item van-picker-column__item--selected">天津市</li>
|
||||||
|
<li class="van-ellipsis van-picker-column__item">县</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="van-picker-column" style="height: 220px;">
|
<div class="van-picker-column" style="height: 220px;">
|
||||||
<ul style="line-height: 44px;"></ul>
|
<ul style="line-height: 44px;">
|
||||||
|
<li class="van-ellipsis van-picker-column__item">和平区</li>
|
||||||
|
<li class="van-ellipsis van-picker-column__item van-picker-column__item--selected">河东区</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="van-hairline--top-bottom van-picker__frame" style="height: 44px;"></div>
|
<div class="van-hairline--top-bottom van-picker__frame" style="height: 44px;"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`watch code 1`] = `
|
exports[`watch areaList & code 1`] = `
|
||||||
<div class="van-picker van-area">
|
<div class="van-picker van-area">
|
||||||
<div class="van-hairline--top-bottom van-picker__toolbar">
|
<div class="van-hairline--top-bottom van-picker__toolbar">
|
||||||
<div class="van-picker__cancel">取消</div>
|
<div class="van-picker__cancel">取消</div>
|
||||||
@ -92,7 +110,7 @@ exports[`watch code 1`] = `
|
|||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`watch code 2`] = `
|
exports[`watch areaList & code 2`] = `
|
||||||
<div class="van-picker van-area">
|
<div class="van-picker van-area">
|
||||||
<div class="van-hairline--top-bottom van-picker__toolbar">
|
<div class="van-hairline--top-bottom van-picker__toolbar">
|
||||||
<div class="van-picker__cancel">取消</div>
|
<div class="van-picker__cancel">取消</div>
|
||||||
@ -115,7 +133,7 @@ exports[`watch code 2`] = `
|
|||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`watch code 3`] = `
|
exports[`watch areaList & code 3`] = `
|
||||||
<div class="van-picker van-area">
|
<div class="van-picker van-area">
|
||||||
<div class="van-hairline--top-bottom van-picker__toolbar">
|
<div class="van-hairline--top-bottom van-picker__toolbar">
|
||||||
<div class="van-picker__cancel">取消</div>
|
<div class="van-picker__cancel">取消</div>
|
||||||
@ -131,17 +149,23 @@ exports[`watch code 3`] = `
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="van-picker-column" style="height: 220px;">
|
<div class="van-picker-column" style="height: 220px;">
|
||||||
<ul style="line-height: 44px;"></ul>
|
<ul style="line-height: 44px;">
|
||||||
|
<li class="van-ellipsis van-picker-column__item van-picker-column__item--selected">北京市</li>
|
||||||
|
<li class="van-ellipsis van-picker-column__item">县</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="van-picker-column" style="height: 220px;">
|
<div class="van-picker-column" style="height: 220px;">
|
||||||
<ul style="line-height: 44px;"></ul>
|
<ul style="line-height: 44px;">
|
||||||
|
<li class="van-ellipsis van-picker-column__item van-picker-column__item--selected">东城区</li>
|
||||||
|
<li class="van-ellipsis van-picker-column__item">西城区</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="van-hairline--top-bottom van-picker__frame" style="height: 44px;"></div>
|
<div class="van-hairline--top-bottom van-picker__frame" style="height: 44px;"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
exports[`watch code 4`] = `
|
exports[`watch areaList & code 4`] = `
|
||||||
<div class="van-picker van-area">
|
<div class="van-picker van-area">
|
||||||
<div class="van-hairline--top-bottom van-picker__toolbar">
|
<div class="van-hairline--top-bottom van-picker__toolbar">
|
||||||
<div class="van-picker__cancel">取消</div>
|
<div class="van-picker__cancel">取消</div>
|
||||||
@ -157,10 +181,16 @@ exports[`watch code 4`] = `
|
|||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="van-picker-column" style="height: 220px;">
|
<div class="van-picker-column" style="height: 220px;">
|
||||||
<ul style="line-height: 44px;"></ul>
|
<ul style="line-height: 44px;">
|
||||||
|
<li class="van-ellipsis van-picker-column__item van-picker-column__item--selected">北京市</li>
|
||||||
|
<li class="van-ellipsis van-picker-column__item">县</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="van-picker-column" style="height: 220px;">
|
<div class="van-picker-column" style="height: 220px;">
|
||||||
<ul style="line-height: 44px;"></ul>
|
<ul style="line-height: 44px;">
|
||||||
|
<li class="van-ellipsis van-picker-column__item van-picker-column__item--selected">东城区</li>
|
||||||
|
<li class="van-ellipsis van-picker-column__item">西城区</li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<div class="van-hairline--top-bottom van-picker__frame" style="height: 44px;"></div>
|
<div class="van-hairline--top-bottom van-picker__frame" style="height: 44px;"></div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -2,6 +2,12 @@ import Area from '..';
|
|||||||
import areaList from '../demo/area.simple';
|
import areaList from '../demo/area.simple';
|
||||||
import { mount, later, triggerDrag } from '../../../test/utils';
|
import { mount, later, triggerDrag } from '../../../test/utils';
|
||||||
|
|
||||||
|
const firstOption = [
|
||||||
|
{ code: '110000', name: '北京市' },
|
||||||
|
{ code: '110100', name: '北京市' },
|
||||||
|
{ code: '110101', name: '东城区' }
|
||||||
|
];
|
||||||
|
|
||||||
test('confirm & cancel event', async() => {
|
test('confirm & cancel event', async() => {
|
||||||
const wrapper = mount(Area, {
|
const wrapper = mount(Area, {
|
||||||
propsData: {
|
propsData: {
|
||||||
@ -14,11 +20,11 @@ test('confirm & cancel event', async() => {
|
|||||||
wrapper.find('.van-picker__confirm').trigger('click');
|
wrapper.find('.van-picker__confirm').trigger('click');
|
||||||
wrapper.find('.van-picker__cancel').trigger('click');
|
wrapper.find('.van-picker__cancel').trigger('click');
|
||||||
|
|
||||||
expect(wrapper.emitted('confirm')).toBeTruthy();
|
expect(wrapper.emitted('confirm')[0][0]).toEqual(firstOption);
|
||||||
expect(wrapper.emitted('cancel')[0][0]).toBeTruthy();
|
expect(wrapper.emitted('cancel')[0][0]).toEqual(firstOption);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('watch code', async() => {
|
test('watch areaList & code', async() => {
|
||||||
const wrapper = mount(Area, {
|
const wrapper = mount(Area, {
|
||||||
propsData: {
|
propsData: {
|
||||||
areaList
|
areaList
|
||||||
@ -57,9 +63,9 @@ test('change option', () => {
|
|||||||
test('getValues method', () => {
|
test('getValues method', () => {
|
||||||
const wrapper = mount(Area, {
|
const wrapper = mount(Area, {
|
||||||
propsData: {
|
propsData: {
|
||||||
areaList: {}
|
areaList
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(wrapper.vm.getValues()).toBeTruthy();
|
expect(wrapper.vm.getValues()).toEqual(firstOption);
|
||||||
});
|
});
|
||||||
|
@ -144,7 +144,7 @@ export default create({
|
|||||||
},
|
},
|
||||||
|
|
||||||
setIndex(index, userAction) {
|
setIndex(index, userAction) {
|
||||||
index = this.adjustIndex(index);
|
index = this.adjustIndex(index) || 0;
|
||||||
this.offset = -index * this.itemHeight;
|
this.offset = -index * this.itemHeight;
|
||||||
|
|
||||||
if (index !== this.currentIndex) {
|
if (index !== this.currentIndex) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user