daily-report-edit-state.test.mjs
2.2 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
const require = createRequire(import.meta.url)
const {
isDailyReportSubmitted,
isDailyReportFormDisabled,
resolveReportSubmittedPatch
} = require('../utils/daily-report-edit-state.js')
describe('daily-report-edit-state', () => {
it('isDailyReportSubmitted: reportStatus=1', () => {
assert.equal(
isDailyReportSubmitted({
reportStatus: '1',
reportDate: '2026-06-15',
weeklyList: []
}),
true
)
})
it('isDailyReportSubmitted: weeklyList includes reportDate', () => {
assert.equal(
isDailyReportSubmitted({
reportStatus: '0',
reportDate: '2026-06-15',
weeklyList: ['2026-06-14', '2026-06-15']
}),
true
)
})
it('isDailyReportSubmitted: draft not in weeklyList', () => {
assert.equal(
isDailyReportSubmitted({
reportStatus: '0',
reportDate: '2026-06-15',
weeklyList: []
}),
false
)
})
it('isDailyReportFormDisabled: unlock when isEditReport', () => {
assert.equal(
isDailyReportFormDisabled({
isDateWithinEditableWindow: true,
isReportSubmitted: true,
isEditReport: true
}),
false
)
})
it('isDailyReportFormDisabled: locked when submitted and not editing', () => {
assert.equal(
isDailyReportFormDisabled({
isDateWithinEditableWindow: true,
isReportSubmitted: true,
isEditReport: false
}),
true
)
})
it('isDailyReportFormDisabled: locked outside editable window', () => {
assert.equal(
isDailyReportFormDisabled({
isDateWithinEditableWindow: false,
isReportSubmitted: false,
isEditReport: false
}),
true
)
})
it('isDailyReportFormDisabled: editable within 7-day window', () => {
assert.equal(
isDailyReportFormDisabled({
isDateWithinEditableWindow: true,
isReportSubmitted: false,
isEditReport: false
}),
false
)
})
it('resolveReportSubmittedPatch merges reportStatus and weeklyList', () => {
const patch = resolveReportSubmittedPatch({
detail: { reportStatus: 0 },
reportDate: '2026-06-15',
weeklyList: ['2026-06-15']
})
assert.equal(patch.reportStatus, '0')
assert.equal(patch.isReportSubmitted, true)
})
})