test: add practice mode helper coverage

This commit is contained in:
TTlaji committed 2026-06-08 14:50:32 +08:00
1 parent 35e0665e7a
commit 2e62600b0d
1 file changed
+129
+129
View File
@@ -0,0 +1,129 @@
import assert from "node:assert/strict";
import {
normalizePracticeAnswer,
comparePracticeAnswer,
getPracticeViewState,
getSubtitleModeConfig,
} from "../app.js";
assert.equal(normalizePracticeAnswer(" Hello, WORLD! "), "hello world");
assert.equal(normalizePracticeAnswer("I’m ready."), "i'm ready");
assert.equal(normalizePracticeAnswer("Are you ok? Yes!"), "are you ok yes");
assert.equal(normalizePracticeAnswer("Listen--then write"), "listen then write");
assert.deepEqual(comparePracticeAnswer("", "Good technology should help."), {
status: "empty",
isCorrect: false,
reference: "Good technology should help.",
message: "请输入答案后再核对。",
});
assert.deepEqual(comparePracticeAnswer("good technology should help", "Good technology should help."), {
status: "correct",
isCorrect: true,
reference: "Good technology should help.",
message: "完全匹配。",
});
assert.deepEqual(comparePracticeAnswer("Good technology should help!", "Good technology should help."), {
status: "correct",
isCorrect: true,
reference: "Good technology should help.",
message: "完全匹配。",
});
assert.deepEqual(comparePracticeAnswer("Good tools help.", "Good technology should help."), {
status: "incorrect",
isCorrect: false,
reference: "Good technology should help.",
message: "还不完全一致,参考答案如下。",
});
assert.deepEqual(comparePracticeAnswer("anything", ""), {
status: "missing-reference",
isCorrect: false,
reference: "",
message: "当前句没有可核对的英文参考。",
});
const cuePair = {
english: {
start: 0,
end: 3.5,
text: "Good technology should make people feel more capable.",
},
chinese: {
start: 0,
end: 3.5,
text: "好的技术应该让人感觉自己更有能力。",
},
};
assert.deepEqual(getPracticeViewState("bilingual", cuePair), {
mode: "bilingual",
label: "双语",
promptText: "Good technology should make people feel more capable.",
referenceText: "好的技术应该让人感觉自己更有能力。",
expectedText: "Good technology should make people feel more capable.",
inputVisible: false,
canCheck: false,
feedbackHint: "",
});
assert.deepEqual(getPracticeViewState("dictation", cuePair), {
mode: "dictation",
label: "听写",
promptText: "听音频,写出当前英文句子。",
referenceText: "",
expectedText: "Good technology should make people feel more capable.",
inputVisible: true,
canCheck: true,
feedbackHint: "",
});
assert.deepEqual(getPracticeViewState("translation", cuePair), {
mode: "translation",
label: "中译英",
promptText: "好的技术应该让人感觉自己更有能力。",
referenceText: "根据中文写出英文句子。",
expectedText: "Good technology should make people feel more capable.",
inputVisible: true,
canCheck: true,
feedbackHint: "",
});
assert.deepEqual(getPracticeViewState("translation", { english: cuePair.english, chinese: null }), {
mode: "translation",
label: "中译英",
promptText: "当前句没有中文字幕。",
referenceText: "根据中文写出英文句子。",
expectedText: "Good technology should make people feel more capable.",
inputVisible: true,
canCheck: true,
feedbackHint: "",
});
assert.deepEqual(getPracticeViewState("dictation", { english: null, chinese: cuePair.chinese }), {
mode: "dictation",
label: "听写",
promptText: "听音频,写出当前英文句子。",
referenceText: "",
expectedText: "",
inputVisible: true,
canCheck: false,
feedbackHint: "当前句没有可核对的英文参考。",
});
assert.deepEqual(getSubtitleModeConfig("dictation", { en: {}, zh: {} }), {
primaryCode: "en",
secondaryCode: "",
showSecondary: false,
message: "",
});
assert.deepEqual(getSubtitleModeConfig("translation", { en: {}, zh: {} }), {
primaryCode: "zh",
secondaryCode: "",
showSecondary: false,
message: "",
});