Commit 6ee73f77 authored by wacky6's avatar wacky6 Committed by 杨奕

DatePicker: fix, add test for default-value

parent ca0ea3ca
...@@ -354,7 +354,7 @@ export default { ...@@ -354,7 +354,7 @@ export default {
handleClickIcon() { handleClickIcon() {
if (this.readonly || this.disabled) return; if (this.readonly || this.disabled) return;
if (this.showClose) { if (this.showClose) {
this.currentValue = ''; this.currentValue = this.$options.defaultValue || '';
this.showClose = false; this.showClose = false;
} else { } else {
this.pickerVisible = !this.pickerVisible; this.pickerVisible = !this.pickerVisible;
...@@ -431,7 +431,7 @@ export default { ...@@ -431,7 +431,7 @@ export default {
}, },
mountPicker() { mountPicker() {
this.panel.defaultValue = this.currentValue; this.panel.defaultValue = this.defaultValue || this.currentValue;
this.picker = new Vue(this.panel).$mount(); this.picker = new Vue(this.panel).$mount();
this.picker.popperClass = this.popperClass; this.picker.popperClass = this.popperClass;
this.popperElm = this.picker.$el; this.popperElm = this.picker.$el;
......
...@@ -202,6 +202,44 @@ describe('DatePicker', () => { ...@@ -202,6 +202,44 @@ describe('DatePicker', () => {
}, DELAY); }, 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', () => { describe('keydown', () => {
let input; let input;
let keyDown = function(el, keyCode) { let keyDown = function(el, keyCode) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment