Initial speaking practice site
This commit is contained in:
commit
bcebeaef82
38 files changed
+10698
No files matched your search
@@ -0,0 +1,24 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { getFileInputState } from "../admin.js";
|
||||
|
||||
function run() {
|
||||
assert.deepEqual(getFileInputState(null, "选择视频文件"), {
|
||||
text: "选择视频文件",
|
||||
title: "选择视频文件",
|
||||
isSelected: false,
|
||||
});
|
||||
|
||||
assert.deepEqual(getFileInputState({ name: "lesson-one-shadowing.mp4" }, "选择视频文件"), {
|
||||
text: "已选:lesson-one-shadowing.mp4",
|
||||
title: "lesson-one-shadowing.mp4",
|
||||
isSelected: true,
|
||||
});
|
||||
|
||||
assert.deepEqual(getFileInputState({ name: "a-very-long-subtitle-file-name-for-practice.vtt" }, "英文字幕 .srt/.vtt"), {
|
||||
text: "已选:a-very-long-subtitle-file-name-for-practice.vtt",
|
||||
title: "a-very-long-subtitle-file-name-for-practice.vtt",
|
||||
isSelected: true,
|
||||
});
|
||||
}
|
||||
|
||||
run();
|
||||
@@ -0,0 +1,40 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { buildWebVtt, parseSubtitleBlocks } from "../admin.js";
|
||||
|
||||
const cues = parseSubtitleBlocks(`WEBVTT
|
||||
|
||||
00:00:00.000 --> 00:00:04.000
|
||||
First line
|
||||
|
||||
00:00:04.000 --> 00:00:08.000
|
||||
Second line
|
||||
continued
|
||||
`);
|
||||
|
||||
assert.equal(cues.length, 2);
|
||||
assert.equal(cues[0].timeRange, "00:00:00.000 --> 00:00:04.000");
|
||||
assert.equal(cues[0].text, "First line");
|
||||
assert.equal(cues[1].text, "Second line\ncontinued");
|
||||
|
||||
const malformedCues = parseSubtitleBlocks(`WEBVTT
|
||||
|
||||
00:00:00.000 --> 00:00:00.001
|
||||
\u00a0
|
||||
00:00:00.872 --> 00:00:04.959
|
||||
My first job as an investor
|
||||
was when I was 24 years old,
|
||||
`);
|
||||
|
||||
assert.equal(malformedCues.length, 1);
|
||||
assert.equal(malformedCues[0].timeRange, "00:00:00.872 --> 00:00:04.959");
|
||||
assert.equal(malformedCues[0].text, "My first job as an investor\nwas when I was 24 years old,");
|
||||
assert.equal(malformedCues[0].text.includes("-->"), false);
|
||||
|
||||
cues.splice(0, 1);
|
||||
assert.equal(buildWebVtt(cues), `WEBVTT
|
||||
|
||||
1
|
||||
00:00:04.000 --> 00:00:08.000
|
||||
Second line
|
||||
continued
|
||||
`);
|
||||
@@ -0,0 +1,19 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
||||
|
||||
from backend.db import repair_mojibake_text
|
||||
|
||||
|
||||
def test_repairs_chinese_mojibake():
|
||||
assert repair_mojibake_text("æªåç±»") == "未分类"
|
||||
|
||||
|
||||
def test_repairs_english_punctuation_mojibake():
|
||||
assert repair_mojibake_text("employeesâ lives") == "employees’ lives"
|
||||
|
||||
|
||||
def test_keeps_normal_text_unchanged():
|
||||
assert repair_mojibake_text("未分类") == "未分类"
|
||||
assert repair_mojibake_text("English") == "English"
|
||||
@@ -0,0 +1,94 @@
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
createEmptyProgress,
|
||||
getVideoProgress,
|
||||
toggleLineIndex,
|
||||
calculatePracticeSummary,
|
||||
formatProgressSummary,
|
||||
getSubtitleModeConfig,
|
||||
parseSubtitle,
|
||||
} from "../app.js";
|
||||
|
||||
const empty = createEmptyProgress();
|
||||
assert.deepEqual(empty, {
|
||||
currentTime: 0,
|
||||
activeLineIndex: 0,
|
||||
practicedLineIndexes: [],
|
||||
difficultLineIndexes: [],
|
||||
updatedAt: "",
|
||||
});
|
||||
|
||||
const user = { progress: {} };
|
||||
const progress = getVideoProgress(user, "video-1");
|
||||
assert.deepEqual(progress.practicedLineIndexes, []);
|
||||
assert.equal(user.progress["video-1"], progress);
|
||||
|
||||
assert.deepEqual(toggleLineIndex([0, 2], 1), [0, 1, 2]);
|
||||
assert.deepEqual(toggleLineIndex([0, 1, 2], 1), [0, 2]);
|
||||
assert.deepEqual(toggleLineIndex([2, 2, 0], 1), [0, 1, 2]);
|
||||
|
||||
assert.deepEqual(calculatePracticeSummary({
|
||||
practicedLineIndexes: [0, 2],
|
||||
}, 5), {
|
||||
practiced: 2,
|
||||
total: 5,
|
||||
percent: 40,
|
||||
});
|
||||
|
||||
assert.equal(formatProgressSummary({
|
||||
practicedLineIndexes: [0, 2],
|
||||
currentTime: 124.4,
|
||||
}, 5), "已练 2/5 · 40%");
|
||||
|
||||
assert.equal(formatProgressSummary({
|
||||
practicedLineIndexes: [],
|
||||
currentTime: 124.4,
|
||||
}, 0), "看到 02:04");
|
||||
|
||||
assert.equal(formatProgressSummary({
|
||||
practicedLineIndexes: [],
|
||||
currentTime: 0,
|
||||
}, 0), "");
|
||||
|
||||
assert.deepEqual(getSubtitleModeConfig("bilingual", { en: {}, zh: {} }), {
|
||||
primaryCode: "en",
|
||||
secondaryCode: "zh",
|
||||
showSecondary: true,
|
||||
message: "",
|
||||
});
|
||||
|
||||
assert.deepEqual(getSubtitleModeConfig("english", { en: {}, zh: {} }), {
|
||||
primaryCode: "en",
|
||||
secondaryCode: "",
|
||||
showSecondary: false,
|
||||
message: "",
|
||||
});
|
||||
|
||||
assert.deepEqual(getSubtitleModeConfig("chinese", { en: {}, zh: {} }), {
|
||||
primaryCode: "zh",
|
||||
secondaryCode: "",
|
||||
showSecondary: false,
|
||||
message: "",
|
||||
});
|
||||
|
||||
assert.deepEqual(getSubtitleModeConfig("chinese", { en: {} }), {
|
||||
primaryCode: "en",
|
||||
secondaryCode: "",
|
||||
showSecondary: false,
|
||||
message: "当前素材没有中文字幕。",
|
||||
});
|
||||
|
||||
const malformedVtt = `WEBVTT
|
||||
|
||||
00:00:00.000 --> 00:00:00.001
|
||||
\u00a0
|
||||
00:00:00.872 --> 00:00:04.959
|
||||
My first job as an investor
|
||||
was when I was 24 years old,
|
||||
`;
|
||||
|
||||
const parsedCues = parseSubtitle(malformedVtt);
|
||||
assert.equal(parsedCues.length, 1);
|
||||
assert.equal(parsedCues[0].start, 0.872);
|
||||
assert.equal(parsedCues[0].text, "My first job as an investor was when I was 24 years old,");
|
||||
assert.equal(parsedCues[0].text.includes("-->"), false);
|
||||
Reference in new issue
Block a user