calendar.spec.js
3.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { createVue, destroyVM, waitImmediate } from '../util';
describe('Calendar', () => {
let vm;
afterEach(() => {
destroyVM(vm);
});
it('create', async() => {
vm = createVue({
template: `
<el-calendar v-model="value"></el-calendar>
`,
data() {
return {
value: new Date('2019-04-01')
};
}
}, true);
const titleEl = vm.$el.querySelector('.el-calendar__title');
expect(/2019.*4/.test(titleEl.innerText)).to.be.true;
expect(vm.$el.querySelectorAll('thead th').length).to.equal(7);
const rows = vm.$el.querySelectorAll('.el-calendar-table__row');
expect(rows.length).to.equal(6);
rows[5].firstElementChild.click();
await waitImmediate();
expect(/2019.*5/.test(titleEl.innerText)).to.be.true;
const value = vm.value;
expect(value.getFullYear()).to.be.equal(2019);
expect(value.getMonth()).to.be.equal(4);
expect(vm.$el.querySelector('.is-selected span').innerText).to.be.equal('6');
});
it('range', () => {
vm = createVue({
template: `
<el-calendar :range="['2019-03-04', '2019-03-24']"></el-calendar>
`
}, true);
const titleEl = vm.$el.querySelector('.el-calendar__title');
expect(/2019.*3/.test(titleEl.innerText)).to.be.true;
const rows = vm.$el.querySelectorAll('.el-calendar-table__row');
expect(rows.length).to.equal(3);
expect(vm.$el.querySelector('.el-calendar__button-group')).to.be.a('null');
});
it('range tow monthes', async() => {
vm = createVue({
template: `
<el-calendar :range="['2019-04-15', '2019-05-19']"></el-calendar>
`
}, true);
const titleEl = vm.$el.querySelector('.el-calendar__title');
expect(/2019.*4/.test(titleEl.innerText)).to.be.true;
const dateTables = vm.$el.querySelectorAll('.el-calendar-table.is-range');
expect(dateTables.length).to.be.equal(2);
const rows = vm.$el.querySelectorAll('.el-calendar-table__row');
expect(rows.length).to.equal(5);
const cell = rows[rows.length - 1].firstElementChild;
cell.click();
await waitImmediate();
expect(/2019.*5/.test(titleEl.innerText)).to.be.true;
expect(cell.classList.contains('is-selected')).to.be.true;
});
it('firstDayOfWeek', async() => {
vm = createVue({
template: `
<el-calendar v-model="value" :first-day-of-week="0"></el-calendar>
`,
data() {
return {
value: new Date('2019-04-01')
};
}
}, true);
const head = vm.$el.querySelector('.el-calendar-table thead');
expect(head.firstElementChild.innerText).to.be.equal('日');
expect(head.lastElementChild.innerText).to.be.equal('六');
const firstRow = vm.$el.querySelector('.el-calendar-table__row');
expect(firstRow.firstElementChild.innerText).to.be.equal('31');
expect(firstRow.lastElementChild.innerText).to.be.equal('6');
});
it('firstDayOfWeek in range mode', async() => {
vm = createVue({
template: `
<el-calendar v-model="value" :first-day-of-week="7" :range="['2019-02-03', '2019-03-23']"></el-calendar>
`,
data() {
return {
value: new Date('2019-03-04')
};
}
}, true);
const head = vm.$el.querySelector('.el-calendar-table thead');
expect(head.firstElementChild.innerText).to.be.equal('日');
expect(head.lastElementChild.innerText).to.be.equal('六');
const firstRow = vm.$el.querySelector('.el-calendar-table__row');
expect(firstRow.firstElementChild.innerText).to.be.equal('3');
expect(firstRow.lastElementChild.innerText).to.be.equal('9');
});
});