test: 添加核心服务回归测试
- 为存储、词库、记忆调度、MIME 解析、单词提取、测验生成及备份处理添加 Node.js 测试 - 添加可复用的浏览器环境与 localStorage 测试辅助工具 - 修复移除 HTML 时单词边界丢失的问题,并拒绝无效的测验答案 - 校验导入备份中的日期,并添加 npm 测试脚本
This commit is contained in:
@@ -99,6 +99,13 @@ export function handleImportBackup(input) {
|
||||
reader.readAsText(file);
|
||||
}
|
||||
|
||||
function isValidBackupDate(value) {
|
||||
if (typeof value !== 'string' || !/^\d{4}-\d{2}-\d{2}$/.test(value)) return false;
|
||||
const [year, month, day] = value.split('-').map(Number);
|
||||
const date = new Date(year, month - 1, day);
|
||||
return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day;
|
||||
}
|
||||
|
||||
function normalizeBackupCategory(value) {
|
||||
return typeof value === 'string' ? value.trim().slice(0, 100) : '';
|
||||
}
|
||||
@@ -153,9 +160,7 @@ function normalizeBackupSchedule(value) {
|
||||
const numericCount = Number(count);
|
||||
return Number.isFinite(numericCount) ? Math.max(0, Math.trunc(numericCount)) : 0;
|
||||
};
|
||||
const nextReview = typeof raw.nextReview === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(raw.nextReview)
|
||||
? raw.nextReview
|
||||
: getToday();
|
||||
const nextReview = isValidBackupDate(raw.nextReview) ? raw.nextReview : getToday();
|
||||
schedule[numericWordId] = {
|
||||
stage,
|
||||
nextReview,
|
||||
@@ -192,7 +197,7 @@ function normalizeBackupRecords(value) {
|
||||
return {
|
||||
...raw,
|
||||
wordId,
|
||||
date: typeof raw.date === 'string' && /^\d{4}-\d{2}-\d{2}$/.test(raw.date) ? raw.date : getToday(),
|
||||
date: isValidBackupDate(raw.date) ? raw.date : getToday(),
|
||||
time: Number.isFinite(time) && time >= 0 ? time : Date.now(),
|
||||
isCorrect: raw.isCorrect,
|
||||
type: raw.type,
|
||||
|
||||
Reference in New Issue
Block a user