calendarMonthMode.test.mjs
4.39 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
getInitialDayType,
resolveMonthOnly,
resolveDayOnly,
shouldShowDayMonthToggle,
shouldShowMonthPanel,
shouldBuildYearList,
shouldUseSingleMonthView,
buildAllMonthsMeta,
buildDisplayMonthWindow,
getMonthDifference,
shouldRebuildMonthListOnBoundsChange
} from '../components/CalendarMonth/calendarMonth.helpers.js'
describe('calendarMonthMode', () => {
it('CAL-01 monthOnly 初始 dayType 为 0', () => {
assert.equal(getInitialDayType({ monthOnly: true }), 0)
})
it('CAL-02 默认 dayType 为 1', () => {
assert.equal(getInitialDayType({ monthOnly: false }), 1)
})
it('CAL-05 monType 兼容别名', () => {
assert.equal(resolveMonthOnly(false, true), true)
assert.equal(resolveMonthOnly(true, false), true)
})
it('CAL-06 dayOnly 初始 dayType 为 1', () => {
assert.equal(getInitialDayType({ dayOnly: true }), 1)
assert.equal(shouldShowDayMonthToggle(false, true), false)
})
it('CAL-07 全功能模式展示日/月切换', () => {
assert.equal(shouldShowDayMonthToggle(false, false), true)
assert.equal(getInitialDayType({ monthOnly: false, dayOnly: false }), 1)
})
it('CAL-08 monthOnly 优先于 dayOnly', () => {
assert.equal(resolveDayOnly(true, true), false)
assert.equal(getInitialDayType({ monthOnly: true, dayOnly: true }), 0)
assert.equal(shouldShowDayMonthToggle(true, true), false)
})
it('CAL-09 dayOnly 不渲染月份面板', () => {
assert.equal(shouldShowMonthPanel({ dayOnly: true, dayType: 1 }), false)
assert.equal(shouldShowMonthPanel({ dayOnly: false, dayType: 0 }), true)
assert.equal(shouldShowMonthPanel({ dayOnly: false, dayType: 1 }), false)
assert.equal(shouldShowMonthPanel({ monthOnly: true, dayType: 1 }), true)
})
it('CAL-10 buildAllMonthsMeta 一次构建多月份', () => {
const now = new Date(2026, 6, 6)
const built = buildAllMonthsMeta({
minDate: '2026-01-01',
maxDate: '2026-07-06',
nowDate: now
})
assert.ok(built.monthList.length >= 7)
assert.equal(built.dateList.length, built.monthList.length)
assert.ok(built.current >= 0)
assert.equal(getMonthDifference('2026-01-01', '2026-07-06'), 6)
})
it('CAL-11 dayOnly 跳过 yearList 构建判定', () => {
assert.equal(shouldBuildYearList({ dayOnly: true }), false)
assert.equal(shouldBuildYearList({ dayOnly: false }), true)
assert.equal(shouldBuildYearList({ dayOnly: true, monthOnly: true }), true)
})
it('CAL-12 buildDisplayMonthWindow 边界', () => {
const monthList = [
{ mark: 1, data: [{ day: 1, data: '2026-01-01' }] },
{ mark: 2, data: [{ day: 1, data: '2026-02-01' }] },
{ mark: 3, data: [{ day: 1, data: '2026-03-01' }] }
]
const first = buildDisplayMonthWindow(monthList, 0)
assert.equal(first.length, 3)
assert.equal(first[0].monthIndex, 0)
assert.equal(first[1].monthIndex, 0)
assert.equal(first[2].monthIndex, 1)
const last = buildDisplayMonthWindow(monthList, 2)
assert.equal(last[0].monthIndex, 1)
assert.equal(last[2].monthIndex, 2)
const mid = buildDisplayMonthWindow(monthList, 1)
assert.equal(mid[0].monthIndex, 0)
assert.equal(mid[1].monthIndex, 1)
assert.equal(mid[2].monthIndex, 2)
})
it('CAL-13 dayOnly 走单月渲染分支', () => {
assert.equal(shouldUseSingleMonthView(true), true)
assert.equal(shouldUseSingleMonthView(false), false)
assert.equal(shouldUseSingleMonthView(true, true), false)
})
it('CAL-14 shouldRebuildMonthListOnBoundsChange detects bound changes', () => {
assert.equal(
shouldRebuildMonthListOnBoundsChange('', '2026-07-06', '', '2026-07-06'),
false
)
assert.equal(
shouldRebuildMonthListOnBoundsChange('', '', '', '2026-07-06'),
true
)
assert.equal(
shouldRebuildMonthListOnBoundsChange('2026-01-01', '2026-07-06', '2026-01-01', '2026-07-07'),
true
)
})
it('CAL-15 buildAllMonthsMeta disables future days when maxDate is today', () => {
const now = new Date(2026, 6, 6)
const built = buildAllMonthsMeta({
minDate: '2026-01-01',
maxDate: '2026-07-06',
nowDate: now
})
const july = built.monthList.find(m => m.mark === 7)
assert.ok(july)
const futureDay = july.data.find(d => d.data === '2026-07-07')
assert.ok(futureDay)
assert.equal(futureDay.disable, true)
})
})