feat(qa-ops): 增加北京时间自然周年份与周次筛选
build / build (push) Successful in 1m8s

按确认口径展示周次及起止日期,处理跨年、52/53周和本周截至当前。保留自定义时间及查询操作,固定UTC+8边界,不改后端源查询。

验证:目标日期、非法53周、北京时间解析、本周截止及渲染回归均先红后绿;前端266通过,完整make verify成功;洛杉矶时区真实浏览器核对查询UTC边界、切年、自定义和390px布局通过,JS异常0。
This commit is contained in:
姚章浩
2026-10-18 16:10:24 +08:00
parent 2ea2111420
commit 3566f208e0
7 changed files with 251 additions and 16 deletions
+57
View File
@@ -0,0 +1,57 @@
import { describe, expect, it } from 'vitest'
import { currentQAWeek, qaDateTimeToISO, qaWeek, qaWeeksInYear, qaWeekQueryRange } from './qaWeeks'
describe('QA natural-week query ranges', () => {
it('caps the in-progress week at now but leaves completed weeks intact', () => {
const now = new Date('2026-10-18T06:00:00Z')
expect(qaWeekQueryRange(2026, 42, now).end).toBe('2026-10-18T14:00')
expect(qaWeekQueryRange(2026, 40, now).end).toBe('2026-10-05T00:00')
expect(qaWeekQueryRange(2026, 53, now).start).toBe('2026-12-28T00:00')
})
it('resolves the current ISO week at the Beijing midnight boundary', () => {
expect(currentQAWeek(new Date('2026-10-18T15:59:00Z'))).toMatchObject({ year: 2026, week: 42 })
expect(currentQAWeek(new Date('2026-10-18T16:01:00Z'))).toMatchObject({ year: 2026, week: 43 })
expect(currentQAWeek(new Date('2027-01-01T12:00:00Z'))).toMatchObject({ year: 2026, week: 53 })
})
it('converts Beijing form input to UTC without relying on the browser timezone', () => {
expect(qaDateTimeToISO('2026-09-28T00:00')).toBe('2026-09-27T16:00:00.000Z')
expect(qaDateTimeToISO('2026-10-05T00:00')).toBe('2026-10-04T16:00:00.000Z')
for (const input of ['', '2026-02-30T00:00', '2026-10-04', '2026-10-04T24:00', 'invalid']) {
expect(() => qaDateTimeToISO(input)).toThrow()
}
})
it('counts only the valid weeks for each year', () => {
expect(qaWeeksInYear(2026)).toBe(53)
expect(qaWeeksInYear(2027)).toBe(52)
expect(qaWeeksInYear(2020)).toBe(53)
expect(qaWeeksInYear(2021)).toBe(52)
})
it('shows week dates inclusively and queries through the exclusive next Monday', () => {
expect(qaWeek(2026, 40)).toEqual({
year: 2026,
week: 40,
start: '2026-09-28T00:00',
end: '2026-10-05T00:00',
label: '第40周(09-28 到 10-04)',
})
})
it('rejects nonexistent weeks instead of spilling into the next year', () => {
expect(() => qaWeek(2027, 53)).toThrow()
for (const week of [0, -1, 54, 1.5, Number.NaN]) expect(() => qaWeek(2026, week)).toThrow()
for (const year of [0, 2026.5, Number.NaN]) expect(() => qaWeek(year, 1)).toThrow()
})
it('keeps the ISO week-year and shows years on crossing ranges', () => {
expect(qaWeek(2026, 1)).toMatchObject({
start: '2025-12-29T00:00',
end: '2026-01-05T00:00',
label: '第1周(2025-12-29 到 2026-01-04)',
})
expect(qaWeek(2026, 53)).toMatchObject({
start: '2026-12-28T00:00',
end: '2027-01-04T00:00',
label: '第53周(2026-12-28 到 2027-01-03)',
})
expect(qaWeek(2024, 9)).toMatchObject({ start: '2024-02-26T00:00', end: '2024-03-04T00:00' })
})
})