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

test: fix snapshot inconsistency due to time zone

This commit is contained in:
mengxiong10
2019-11-11 11:16:09 +08:00
parent e2b24fa833
commit 0ff10e170a
6 changed files with 209 additions and 198 deletions
File diff suppressed because it is too large Load Diff
+34 -28
View File
@@ -24,11 +24,12 @@ exports[`TimeRange render: correct classes of the columns 1`] = `
style="overflow: hidden scroll; height: 100%; margin-right: -0px;" style="overflow: hidden scroll; height: 100%; margin-right: -0px;"
> >
<ul <ul
data-index="0"
data-type="hour" data-type="hour"
> >
<li <li
class="cell" class="cell"
data-value="1570163400000" data-index="0"
> >
12 12
@@ -36,15 +37,15 @@ exports[`TimeRange render: correct classes of the columns 1`] = `
</li> </li>
<li <li
class="cell" class="cell"
data-value="1570170600000" data-index="1"
> >
02 02
</li> </li>
<li <li
class="cell active" class="cell"
data-value="1570177800000" data-index="2"
> >
04 04
@@ -52,15 +53,15 @@ exports[`TimeRange render: correct classes of the columns 1`] = `
</li> </li>
<li <li
class="cell" class="cell"
data-value="1570185000000" data-index="3"
> >
06 06
</li> </li>
<li <li
class="cell" class="cell active"
data-value="1570192200000" data-index="4"
> >
08 08
@@ -68,7 +69,7 @@ exports[`TimeRange render: correct classes of the columns 1`] = `
</li> </li>
<li <li
class="cell" class="cell"
data-value="1570199400000" data-index="5"
> >
10 10
@@ -94,11 +95,12 @@ exports[`TimeRange render: correct classes of the columns 1`] = `
style="overflow: hidden scroll; height: 100%; margin-right: -0px;" style="overflow: hidden scroll; height: 100%; margin-right: -0px;"
> >
<ul <ul
data-index="1"
data-type="minute" data-type="minute"
> >
<li <li
class="cell" class="cell"
data-value="1570176000000" data-index="0"
> >
00 00
@@ -106,7 +108,7 @@ exports[`TimeRange render: correct classes of the columns 1`] = `
</li> </li>
<li <li
class="cell active" class="cell active"
data-value="1570177800000" data-index="1"
> >
30 30
@@ -132,19 +134,20 @@ exports[`TimeRange render: correct classes of the columns 1`] = `
style="overflow: hidden scroll; height: 100%; margin-right: -0px;" style="overflow: hidden scroll; height: 100%; margin-right: -0px;"
> >
<ul <ul
data-index="2"
data-type="ampm" data-type="ampm"
> >
<li <li
class="cell" class="cell active"
data-value="1570134600000" data-index="0"
> >
AM AM
</li> </li>
<li <li
class="cell active" class="cell"
data-value="1570177800000" data-index="1"
> >
PM PM
@@ -184,19 +187,20 @@ exports[`TimeRange render: correct classes of the columns 1`] = `
style="overflow: hidden scroll; height: 100%; margin-right: -0px;" style="overflow: hidden scroll; height: 100%; margin-right: -0px;"
> >
<ul <ul
data-index="0"
data-type="hour" data-type="hour"
> >
<li <li
class="cell" class="cell"
data-value="1570206600000" data-index="0"
> >
12 12
</li> </li>
<li <li
class="cell active" class="cell"
data-value="1570213800000" data-index="1"
> >
02 02
@@ -204,15 +208,15 @@ exports[`TimeRange render: correct classes of the columns 1`] = `
</li> </li>
<li <li
class="cell" class="cell"
data-value="1570221000000" data-index="2"
> >
04 04
</li> </li>
<li <li
class="cell" class="cell active"
data-value="1570228200000" data-index="3"
> >
06 06
@@ -220,7 +224,7 @@ exports[`TimeRange render: correct classes of the columns 1`] = `
</li> </li>
<li <li
class="cell" class="cell"
data-value="1570235400000" data-index="4"
> >
08 08
@@ -228,7 +232,7 @@ exports[`TimeRange render: correct classes of the columns 1`] = `
</li> </li>
<li <li
class="cell" class="cell"
data-value="1570242600000" data-index="5"
> >
10 10
@@ -254,11 +258,12 @@ exports[`TimeRange render: correct classes of the columns 1`] = `
style="overflow: hidden scroll; height: 100%; margin-right: -0px;" style="overflow: hidden scroll; height: 100%; margin-right: -0px;"
> >
<ul <ul
data-index="1"
data-type="minute" data-type="minute"
> >
<li <li
class="cell" class="cell"
data-value="1570212000000" data-index="0"
> >
00 00
@@ -266,7 +271,7 @@ exports[`TimeRange render: correct classes of the columns 1`] = `
</li> </li>
<li <li
class="cell active" class="cell active"
data-value="1570213800000" data-index="1"
> >
30 30
@@ -292,19 +297,20 @@ exports[`TimeRange render: correct classes of the columns 1`] = `
style="overflow: hidden scroll; height: 100%; margin-right: -0px;" style="overflow: hidden scroll; height: 100%; margin-right: -0px;"
> >
<ul <ul
data-index="2"
data-type="ampm" data-type="ampm"
> >
<li <li
class="cell active" class="cell disabled"
data-value="1570213800000" data-index="0"
> >
AM AM
</li> </li>
<li <li
class="cell" class="cell active"
data-value="1570257000000" data-index="1"
> >
PM PM
+1 -1
View File
@@ -56,7 +56,7 @@ describe('CalendarPanel', () => {
wrapper = shallowMount(CalendarPanel, { wrapper = shallowMount(CalendarPanel, {
propsData: { propsData: {
type, type,
value: new Date(Date.UTC(2019, 9, 1, 10)), value: new Date(2019, 9, 1, 10),
}, },
}); });
expect(wrapper.element).toMatchSnapshot(); expect(wrapper.element).toMatchSnapshot();
+4 -4
View File
@@ -11,7 +11,7 @@ describe('TimePanel', () => {
it('render: correct classes of the columns', () => { it('render: correct classes of the columns', () => {
wrapper = mount(TimePanel, { wrapper = mount(TimePanel, {
propsData: { propsData: {
value: new Date(Date.UTC(2019, 9, 4, 12, 30, 30)), value: new Date(2019, 9, 4, 12, 30, 30),
disabledTime: date => date.getHours() < 10, disabledTime: date => date.getHours() < 10,
}, },
}); });
@@ -21,7 +21,7 @@ describe('TimePanel', () => {
it('render: correct columns by format', () => { it('render: correct columns by format', () => {
wrapper = mount(TimePanel, { wrapper = mount(TimePanel, {
propsData: { propsData: {
value: new Date(Date.UTC(2019, 9, 4)), value: new Date(2019, 9, 4),
format: 'hh:mm a', format: 'hh:mm a',
minuteStep: 30, minuteStep: 30,
hourOptions: Array.from({ length: 10 }).map((_, i) => i + 8), hourOptions: Array.from({ length: 10 }).map((_, i) => i + 8),
@@ -33,7 +33,7 @@ describe('TimePanel', () => {
it('render: correct classes of the fixed time list', () => { it('render: correct classes of the fixed time list', () => {
wrapper = mount(TimePanel, { wrapper = mount(TimePanel, {
propsData: { propsData: {
value: new Date(Date.UTC(2019, 10, 9, 12, 30)), value: new Date(2019, 10, 9, 12, 30),
disabledTime: date => date.getHours() < 10, disabledTime: date => date.getHours() < 10,
timePickerOptions: { timePickerOptions: {
start: '08:30', start: '08:30',
@@ -49,7 +49,7 @@ describe('TimePanel', () => {
it('render: correct 12hours in the fixed time list', () => { it('render: correct 12hours in the fixed time list', () => {
wrapper = mount(TimePanel, { wrapper = mount(TimePanel, {
propsData: { propsData: {
value: new Date(Date.UTC(2019, 10, 9, 12, 30)), value: new Date(2019, 10, 9, 12, 30),
timePickerOptions: { timePickerOptions: {
start: '08:30', start: '08:30',
step: '00:30', step: '00:30',
+1 -4
View File
@@ -14,10 +14,7 @@ describe('TimeRange', () => {
format: 'hh:mm a', format: 'hh:mm a',
minuteStep: 30, minuteStep: 30,
hourStep: 2, hourStep: 2,
value: [ value: [new Date(2019, 9, 4, 8, 30, 0), new Date(2019, 9, 4, 18, 30, 0)],
new Date(Date.UTC(2019, 9, 4, 8, 30, 0)),
new Date(Date.UTC(2019, 9, 4, 18, 30, 0)),
],
}, },
}); });
expect(wrapper.element).toMatchSnapshot(); expect(wrapper.element).toMatchSnapshot();
+6 -4
View File
@@ -1,12 +1,12 @@
<template> <template>
<div class="mx-time-columns"> <div class="mx-time-columns">
<scrollbar-vertical v-for="(col, i) in columns" :key="i" class="mx-time-column"> <scrollbar-vertical v-for="(col, i) in columns" :key="i" class="mx-time-column">
<ul :data-type="col.type" @click="handleSelect"> <ul :data-type="col.type" :data-index="i" @click="handleSelect">
<li <li
v-for="item in col.list" v-for="(item, j) in col.list"
:key="item.value" :key="item.value"
class="cell" class="cell"
:data-value="item.value" :data-index="j"
:class="getClasses(item.value)" :class="getClasses(item.value)"
> >
{{ item.text }} {{ item.text }}
@@ -177,7 +177,9 @@ export default {
const { target, currentTarget } = evt; const { target, currentTarget } = evt;
if (target.tagName.toUpperCase() !== 'LI') return; if (target.tagName.toUpperCase() !== 'LI') return;
const type = currentTarget.getAttribute('data-type'); const type = currentTarget.getAttribute('data-type');
const value = parseInt(target.getAttribute('data-value'), 10); const colIndex = parseInt(currentTarget.getAttribute('data-index'), 10);
const cellIndex = parseInt(target.getAttribute('data-index'), 10);
const { value } = this.columns[colIndex].list[cellIndex];
this.$emit('select', value, type); this.$emit('select', value, type);
}, },
}, },