2
0
mirror of https://github.com/tenrok/vue2-datepicker.git synced 2026-06-23 12:00:35 +03:00

test: add type input test

This commit is contained in:
mxie
2018-07-02 17:12:28 +08:00
parent 626f76946c
commit 5200fe0481
+34 -10
View File
@@ -12,7 +12,6 @@ afterEach(() => {
wrapper.destroy() wrapper.destroy()
}) })
describe('datepicker', () => { describe('datepicker', () => {
it('click: pick date', () => { it('click: pick date', () => {
wrapper = mount(DatePicker, { wrapper = mount(DatePicker, {
@@ -35,7 +34,6 @@ describe('datepicker', () => {
td = wrapper.find('.mx-panel-date td:nth-child(5)') td = wrapper.find('.mx-panel-date td:nth-child(5)')
expect(td.classes()).toContain('actived') expect(td.classes()).toContain('actived')
expect(vm.text).toBe('2018-05-03') expect(vm.text).toBe('2018-05-03')
}) })
it('click: clear icon', () => { it('click: clear icon', () => {
@@ -108,7 +106,6 @@ describe('datepicker', () => {
}) })
const vm = wrapper.vm const vm = wrapper.vm
expect(vm.text).toBe('2018-06-01 至 2018-06-10') expect(vm.text).toBe('2018-06-01 至 2018-06-10')
}) })
it('prop: confirm', () => { it('prop: confirm', () => {
@@ -231,10 +228,40 @@ describe('datepicker', () => {
expect(shortcuts.exists()).toBe(false) expect(shortcuts.exists()).toBe(false)
}) })
it('type input should be right', (done) => {
wrapper = mount(DatePicker, {
propsData: {
format: 'YYYY-MM-DD'
},
sync: false
})
const input = wrapper.find('input')
input.setValue('2018-09-10')
input.trigger('input')
input.trigger('change')
const expectDate = new Date(2018, 8, 10)
wrapper.setProps({
range: true
})
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')
expect(wrapper.emitted()).toEqual({
input: [[expectDate], [expectRange]],
change: [[expectDate], [expectRange]],
'input-error': [['2018-09-10 ~ 2018-08-10']]
})
done()
})
})
}) })
describe('calendar-panel', () => { describe('calendar-panel', () => {
it('click: prev/next month', () => { it('click: prev/next month', () => {
wrapper = mount(CalendarPanel) wrapper = mount(CalendarPanel)
@@ -275,7 +302,7 @@ describe('calendar-panel', () => {
it('click: prev/next year', () => { it('click: prev/next year', () => {
wrapper = mount(CalendarPanel, { wrapper = mount(CalendarPanel, {
value: new Date(2018,4,5) value: new Date(2018, 4, 5)
}) })
const nextBtn = wrapper.find('.mx-icon-next-year') const nextBtn = wrapper.find('.mx-icon-next-year')
const lastBtn = wrapper.find('.mx-icon-last-year') const lastBtn = wrapper.find('.mx-icon-last-year')
@@ -359,7 +386,7 @@ describe('calendar-panel', () => {
} }
}) })
it('feat: when the time panel show, scroll to the right position', () => { it('feat: when the time panel show, scroll to the right position', (done) => {
wrapper = mount(CalendarPanel, { wrapper = mount(CalendarPanel, {
propsData: { propsData: {
value: new Date(2018, 4, 4), value: new Date(2018, 4, 4),
@@ -379,6 +406,7 @@ describe('calendar-panel', () => {
}) })
setTimeout(() => { setTimeout(() => {
expect(list.scrollTop).toBe(0) expect(list.scrollTop).toBe(0)
done()
}, 0) }, 0)
}) })
}) })
@@ -393,7 +421,6 @@ describe('date-panel', () => {
firstDayOfWeek: i firstDayOfWeek: i
} }
}) })
const vm = wrapper.vm
const lastMonth = new Date(2018, 3, 30) const lastMonth = new Date(2018, 3, 30)
const lastMonthDay = 30 const lastMonthDay = 30
const lastMonthLength = (lastMonth.getDay() + 7 - i) % 7 + 1 const lastMonthLength = (lastMonth.getDay() + 7 - i) % 7 + 1
@@ -456,7 +483,6 @@ describe('year-panel', () => {
}) })
describe('time-panel', () => { describe('time-panel', () => {
it('click: pick time emitted the select event', () => { it('click: pick time emitted the select event', () => {
wrapper = mount(TimePanel, { wrapper = mount(TimePanel, {
propsData: { propsData: {
@@ -479,7 +505,6 @@ describe('time-panel', () => {
expect(wrapper.emitted()).toEqual({ expect(wrapper.emitted()).toEqual({
select: [[new Date(2018, 5, 5, 1)], [new Date(2018, 5, 5, 0, 1)], [new Date(2018, 5, 5, 0, 0, 1)]] select: [[new Date(2018, 5, 5, 1)], [new Date(2018, 5, 5, 0, 1)], [new Date(2018, 5, 5, 0, 0, 1)]]
}) })
}) })
it('prop: minuteStep', () => { it('prop: minuteStep', () => {
@@ -516,5 +541,4 @@ describe('time-panel', () => {
select: [[new Date(2018, 5, 5, 1)]] select: [[new Date(2018, 5, 5, 1)]]
}) })
}) })
}) })