DatePicker: fix, add test for default-value

pull/4986/head
wacky6 2017-05-03 17:32:38 +08:00 committed by 杨奕
parent ca0ea3ca4f
commit 6ee73f7715
2 changed files with 40 additions and 2 deletions

View File

@ -354,7 +354,7 @@ export default {
handleClickIcon() {
if (this.readonly || this.disabled) return;
if (this.showClose) {
this.currentValue = '';
this.currentValue = this.$options.defaultValue || '';
this.showClose = false;
} else {
this.pickerVisible = !this.pickerVisible;
@ -431,7 +431,7 @@ export default {
},
mountPicker() {
this.panel.defaultValue = this.currentValue;
this.panel.defaultValue = this.defaultValue || this.currentValue;
this.picker = new Vue(this.panel).$mount();
this.picker.popperClass = this.popperClass;
this.popperElm = this.picker.$el;

View File

@ -202,6 +202,44 @@ describe('DatePicker', () => {
}, DELAY);
});
it('default value', done => {
const toDateStr = date => {
let d = new Date(date);
return `${d.getFullYear()}-${d.getMonth()}-${d.getDate()}`;
};
let today = new Date();
let nextMonth = new Date(today);
nextMonth.setDate(1);
if (nextMonth.getMonth() === 12) {
nextMonth.setFullYear(today.getFullYear + 1);
nextMonth.setMonth(1);
} else {
nextMonth.setMonth(today.getMonth() + 1);
}
let nextMonthStr = toDateStr(nextMonth);
vm = createVue({
template: `<el-date-picker v-model="value" ref="compo" default-value="${nextMonthStr}" />`,
data() {
return {
value: ''
};
}
}, true);
const input = vm.$el.querySelector('input');
input.focus();
setTimeout(_ => {
const $el = vm.$refs.compo.picker.$el;
$el.querySelector('td.current').click();
setTimeout(_ => {
expect(vm.value).to.equal(nextMonthStr);
});
done();
});
});
describe('keydown', () => {
let input;
let keyDown = function(el, keyCode) {