2
0
mirror of https://github.com/tenrok/vue2-datepicker.git synced 2026-06-24 16:30:36 +03:00

fix: test suites in another timezone failed (#300)

This commit is contained in:
mengxiong10
2019-05-15 10:55:21 +08:00
parent 96812abaf9
commit ec69590bbb
2 changed files with 14 additions and 14 deletions
+2
View File
@@ -122,6 +122,8 @@ export default {
<td <td
class="cell" class="cell"
{...attrs} {...attrs}
data-year={date.year}
data-month={date.month}
title={this.getCellTitle(date)} title={this.getCellTitle(date)}
onClick={this.selectDate.bind(this, date)}> onClick={this.selectDate.bind(this, date)}>
{date.day} {date.day}
+12 -14
View File
@@ -139,13 +139,13 @@ describe('datepicker', () => {
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 el1 = td1.at(14).element
const date1 = new Date(td1.at(14).element.title).setHours(0, 0, 0, 0) const date1 = new Date(+el1.dataset.year, +el1.dataset.month, +el1.textContent)
td2.at(16).trigger('click') td2.at(16).trigger('click')
Vue.nextTick(() => { Vue.nextTick(() => {
const emitted = wrapper.emitted() const emitted = wrapper.emitted()
const date2 = new Date(td2.at(16).element.title).setHours(0, 0, 0, 0) const el2 = td2.at(16).element
const date2 = new Date(+el2.dataset.year, +el2.dataset.month, +el2.textContent)
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')
@@ -161,7 +161,7 @@ describe('datepicker', () => {
wrapper = shallowMount(DatePicker, { wrapper = shallowMount(DatePicker, {
propsData: { propsData: {
range: true, range: true,
value: [new Date('2018-06-01'), new Date('2018-06-10')], value: [new Date(2018, 5, 1), new Date(2018, 5, 10)],
rangeSeparator: '至' rangeSeparator: '至'
} }
}) })
@@ -360,21 +360,18 @@ describe('datepicker', () => {
it('prop: dateFormat', () => { it('prop: dateFormat', () => {
wrapper = mount(DatePicker, { wrapper = mount(DatePicker, {
propsData: { propsData: {
value: new Date('2018-08-08'), value: new Date(2018, 7, 8),
format: '[on] MM-DD-YYYY [at] HH:mm', format: '[on] MM-DD-YYYY [at] HH:mm',
type: 'datetime' type: 'datetime'
} }
}) })
let ss = '08-08-2018' let ss = '08-08-2018'
const cell = wrapper.find('.mx-panel-date .actived')
const timeHeader = wrapper.find('.mx-time-header') const timeHeader = wrapper.find('.mx-time-header')
expect(cell.element.title).toBe(ss)
expect(timeHeader.text()).toBe(ss) expect(timeHeader.text()).toBe(ss)
wrapper.setProps({ wrapper.setProps({
dateFormat: 'YYYY-MM-DD' dateFormat: 'YYYY-MM-DD'
}) })
ss = '2018-08-08' ss = '2018-08-08'
expect(cell.element.title).toBe(ss)
expect(timeHeader.text()).toBe(ss) expect(timeHeader.text()).toBe(ss)
}) })
}) })
@@ -384,7 +381,7 @@ describe('calendar-panel', () => {
wrapper = mount(CalendarPanel, { wrapper = mount(CalendarPanel, {
propsData: { propsData: {
value: null, value: null,
defaultValue: '2018-10-01' defaultValue: new Date(2018, 9, 1)
} }
}) })
const vm = wrapper.vm const vm = wrapper.vm
@@ -500,7 +497,7 @@ describe('calendar-panel', () => {
}) })
it('prop: disabledDays(Array)', () => { it('prop: disabledDays(Array)', () => {
const disabledDays = ['2018-05-01', new Date(2018, 4, 3)] const disabledDays = [new Date(2018, 4, 1), new Date(2018, 4, 3)]
wrapper = mount(CalendarPanel, { wrapper = mount(CalendarPanel, {
propsData: { propsData: {
value: new Date(2018, 4, 2), value: new Date(2018, 4, 2),
@@ -510,9 +507,10 @@ describe('calendar-panel', () => {
const tds = wrapper.findAll('.mx-panel-date td.disabled') const tds = wrapper.findAll('.mx-panel-date td.disabled')
expect(tds.length).toBe(disabledDays.length) expect(tds.length).toBe(disabledDays.length)
for (let i = 0, len = tds.length; i < len; i++) { for (let i = 0, len = tds.length; i < len; i++) {
const tdDate = new Date(tds.at(i).element.title).setHours(0, 0, 0, 0) const el = tds.at(i).element
const expectDate = new Date(disabledDays[i]).setHours(0, 0, 0, 0) const tdDate = new Date(+el.dataset.year, +el.dataset.month, +el.textContent)
expect(tdDate).toBe(expectDate) const expectDate = new Date(disabledDays[i])
expect(tdDate).toEqual(expectDate)
} }
}) })