Files
speaking-practice/tests/practice-helpers.test.mjs
T

137 lines
4.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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."), "im 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("dont stop", "Don’t stop."), {
status: "correct",
isCorrect: true,
reference: "Don’t stop.",
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: "",
});