2
0
mirror of https://github.com/tenrok/vue2-datepicker.git synced 2026-06-23 09:40: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
+43 -19
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, {
@@ -22,7 +21,7 @@ describe('datepicker', () => {
}) })
// 2018-05-03 // 2018-05-03
const vm = wrapper.vm const vm = wrapper.vm
let td = wrapper.find('.mx-panel-date td:nth-child(5)') let td = wrapper.find('.mx-panel-date td:nth-child(5)')
expect(td.classes()).not.toContain('actived') expect(td.classes()).not.toContain('actived')
expect(vm.text).toBe('2018-05-02') expect(vm.text).toBe('2018-05-02')
@@ -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', () => {
@@ -62,7 +60,7 @@ describe('datepicker', () => {
}, },
sync: false // sync bug sync: false // sync bug
}) })
const calendars = wrapper.findAll(CalendarPanel) const calendars = wrapper.findAll(CalendarPanel)
const calendar1 = calendars.at(0) const calendar1 = calendars.at(0)
const calendar2 = calendars.at(1) const calendar2 = calendars.at(1)
@@ -71,29 +69,29 @@ describe('datepicker', () => {
const td2 = calendar2.findAll('.mx-panel-date tbody td') const td2 = calendar2.findAll('.mx-panel-date tbody td')
td1.at(14).trigger('click') td1.at(14).trigger('click')
Vue.nextTick(() => { Vue.nextTick(() => {
let emitted = wrapper.emittedByOrder() let emitted = wrapper.emittedByOrder()
expect(emitted).toHaveLength(0) expect(emitted).toHaveLength(0)
expect(td1.at(14).classes()).toContain('actived') expect(td1.at(14).classes()).toContain('actived')
expect(td2.at(13).classes()).toContain('disabled') expect(td2.at(13).classes()).toContain('disabled')
expect(td2.at(14).classes()).not.toContain('disabled') expect(td2.at(14).classes()).not.toContain('disabled')
const date1 = new Date(td1.at(14).element.title) const date1 = new Date(td1.at(14).element.title)
td2.at(16).trigger('click') td2.at(16).trigger('click')
Vue.nextTick(() => { Vue.nextTick(() => {
emitted = wrapper.emittedByOrder() emitted = wrapper.emittedByOrder()
const date2 = new Date(td2.at(16).element.title) const date2 = new Date(td2.at(16).element.title)
expect(td2.at(16).classes()).toContain('actived') expect(td2.at(16).classes()).toContain('actived')
expect(td1.at(15).classes()).toContain('inrange') expect(td1.at(15).classes()).toContain('inrange')
expect(td1.at(16).classes()).toContain('inrange') expect(td1.at(16).classes()).toContain('inrange')
expect(td1.at(17).classes()).toContain('disabled') expect(td1.at(17).classes()).toContain('disabled')
expect(emitted).toHaveLength(2) expect(emitted).toHaveLength(2)
expect(emitted[0].args[0]).toEqual([date1, date2]) expect(emitted[0].args[0]).toEqual([date1, date2])
done() done()
}) })
}) })
}) })
@@ -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', () => {
@@ -140,7 +137,7 @@ describe('datepicker', () => {
const btn = wrapper.find('.mx-datepicker-btn-confirm') const btn = wrapper.find('.mx-datepicker-btn-confirm')
expect(btn.text()).toBe('确定') expect(btn.text()).toBe('确定')
}) })
it('prop: width', () => { it('prop: width', () => {
wrapper = shallowMount(DatePicker, { wrapper = shallowMount(DatePicker, {
propsData: { propsData: {
@@ -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)]]
}) })
}) })
}) })