DatePicker: support literal (#15525)

This commit is contained in:
Zhi Cun
2019-05-30 14:43:17 +08:00
committed by luckyCao
parent fa802b893f
commit a7d3f69f95
6 changed files with 117 additions and 30 deletions

View File

@@ -489,6 +489,37 @@ describe('DatePicker', () => {
}, DELAY);
});
it('with literal string', done => {
vm = createVue({
template: `
<el-date-picker
ref="compo"
v-model="value"
type="date"
value-format="dd/MM yyyy [Element]" />`,
data() {
return {
value: ''
};
}
}, true);
vm.$refs.compo.$el.querySelector('input').focus();
setTimeout(_ => {
vm.$refs.compo.picker.$el.querySelector('.el-date-table td.available').click();
setTimeout(_ => {
const today = new Date();
const yyyy = today.getFullYear();
const MM = ('0' + (today.getMonth() + 1)).slice(-2);
const dd = '01'; // first available one should be first day of month
const expectValue = `${dd}/${MM} ${yyyy} Element`;
expect(vm.value).to.equal(expectValue);
done();
}, DELAY);
}, DELAY);
});
it('accepts', done => {
vm = createVue({
template: `
@@ -549,6 +580,34 @@ describe('DatePicker', () => {
}, DELAY);
});
it('translates format to value-format with literal string', done => {
vm = createVue({
template: `
<el-date-picker
ref="compo"
v-model="value"
type="date"
format="[Element] yyyy-MM-dd"
value-format="dd/MM yyyy [UI]" />`,
data() {
return {
value: ''
};
}
}, true);
const input = vm.$refs.compo.$el.querySelector('input');
input.focus();
setTimeout(_ => {
input.value = 'Element 2000-10-01';
triggerEvent(input, 'input');
keyDown(input, ENTER);
setTimeout(_ => {
expect(vm.value).to.equal('01/10 2000 UI');
done();
}, DELAY);
}, DELAY);
});
it('works for daterange', done => {
vm = createVue({
template: `