mirror of
https://github.com/tenrok/vue2-datepicker.git
synced 2026-06-25 00:01:33 +03:00
fix: unable set value later when range is ture (#209)
This commit is contained in:
+6
-2
@@ -258,12 +258,16 @@ export default {
|
|||||||
return date.getTime()
|
return date.getTime()
|
||||||
},
|
},
|
||||||
inBefore (time, startAt) {
|
inBefore (time, startAt) {
|
||||||
startAt = startAt || this.startAt
|
if (startAt === undefined) {
|
||||||
|
startAt = this.startAt
|
||||||
|
}
|
||||||
return (this.notBeforeTime && time < this.notBeforeTime) ||
|
return (this.notBeforeTime && time < this.notBeforeTime) ||
|
||||||
(startAt && time < this.getCriticalTime(startAt))
|
(startAt && time < this.getCriticalTime(startAt))
|
||||||
},
|
},
|
||||||
inAfter (time, endAt) {
|
inAfter (time, endAt) {
|
||||||
endAt = endAt || this.endAt
|
if (endAt === undefined) {
|
||||||
|
endAt = this.endAt
|
||||||
|
}
|
||||||
return (this.notAfterTime && time > this.notAfterTime) ||
|
return (this.notAfterTime && time > this.notAfterTime) ||
|
||||||
(endAt && time > this.getCriticalTime(endAt))
|
(endAt && time > this.getCriticalTime(endAt))
|
||||||
},
|
},
|
||||||
|
|||||||
+31
-12
@@ -247,24 +247,43 @@ describe('datepicker', () => {
|
|||||||
input.trigger('input')
|
input.trigger('input')
|
||||||
input.trigger('change')
|
input.trigger('change')
|
||||||
const expectDate = new Date(2018, 8, 10)
|
const expectDate = new Date(2018, 8, 10)
|
||||||
wrapper.setProps({
|
|
||||||
range: true
|
|
||||||
})
|
|
||||||
Vue.nextTick(() => {
|
Vue.nextTick(() => {
|
||||||
input.setValue('2018-09-10 ~ 2018-09-11')
|
|
||||||
input.trigger('input')
|
|
||||||
input.trigger('change')
|
|
||||||
const expectRange = [new Date(2018, 8, 10), new Date(2018, 8, 11)]
|
|
||||||
input.setValue('2018-09-10 ~ 2018-08-10')
|
|
||||||
input.trigger('input')
|
|
||||||
input.trigger('change')
|
|
||||||
const emitted = wrapper.emitted()
|
const emitted = wrapper.emitted()
|
||||||
expect(emitted.input).toEqual([[expectDate], [expectRange]])
|
expect(emitted.input).toEqual([[expectDate]])
|
||||||
expect(emitted['input-error']).toEqual([['2018-09-10 ~ 2018-08-10']])
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('type range input should be right', (done) => {
|
||||||
|
wrapper = mount(DatePicker, {
|
||||||
|
propsData: {
|
||||||
|
format: 'YYYY-MM-DD',
|
||||||
|
range: true
|
||||||
|
},
|
||||||
|
sync: false
|
||||||
|
})
|
||||||
|
const input = wrapper.find('input')
|
||||||
|
input.setValue('2018-09-10 ~ 2018-09-11')
|
||||||
|
input.trigger('change')
|
||||||
|
const expectRange = [new Date(2018, 8, 10), new Date(2018, 8, 11)]
|
||||||
|
Vue.nextTick(() => {
|
||||||
|
input.setValue('2018-09-09 ~ 2018-09-12')
|
||||||
|
input.trigger('input')
|
||||||
|
input.trigger('change')
|
||||||
|
const expectRange2 = [new Date(2018, 8, 9), new Date(2018, 8, 12)]
|
||||||
|
Vue.nextTick(() => {
|
||||||
|
input.setValue('2018-09-10 ~ 2018-08-10')
|
||||||
|
input.trigger('input')
|
||||||
|
input.trigger('change')
|
||||||
|
const expectError = '2018-09-10 ~ 2018-08-10'
|
||||||
|
const emitted = wrapper.emitted()
|
||||||
|
expect(emitted.input).toEqual([[expectRange], [expectRange2]])
|
||||||
|
expect(emitted['input-error']).toEqual([[expectError]])
|
||||||
|
done()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it('prop: dateFormat', () => {
|
it('prop: dateFormat', () => {
|
||||||
wrapper = mount(DatePicker, {
|
wrapper = mount(DatePicker, {
|
||||||
propsData: {
|
propsData: {
|
||||||
|
|||||||
Reference in New Issue
Block a user