mirror of
https://github.com/margrop/wrong-notebook.git
synced 2026-12-05 08:09:38 +08:00
merge: 清理前端硬编码文案并按语言显示年级与分值括号
This commit is contained in:
73
e2e/i18n-consistency.spec.ts
Normal file
73
e2e/i18n-consistency.spec.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { test, expect, type Page } from './support/fixtures';
|
||||
import { ADMIN_PASSWORD } from './helpers';
|
||||
|
||||
async function login(page: Page) {
|
||||
const hydrated = page.waitForResponse((response) => response.url().endsWith('/api/register/status'));
|
||||
await page.goto('/login');
|
||||
await hydrated;
|
||||
await page.getByLabel(/邮箱|Email/).fill('admin@localhost');
|
||||
await page.getByLabel(/^密码$|^Password$/).fill(ADMIN_PASSWORD);
|
||||
await page.getByRole('button', { name: /登录|Login/ }).click();
|
||||
await page.waitForURL('**/', { timeout: 15000 });
|
||||
}
|
||||
|
||||
/** 详情页中标题为 title 的卡片 */
|
||||
function card(page: Page, title: string) {
|
||||
return page.locator('[data-slot="card"]').filter({ has: page.locator('[data-slot="card-title"]', { hasText: title }) });
|
||||
}
|
||||
|
||||
test('错题详情编辑占位文案随界面语言切换,不再固定英文', async ({ page }) => {
|
||||
test.setTimeout(60000);
|
||||
await login(page);
|
||||
const notebookRes = await page.request.post('/api/notebooks', {
|
||||
data: { name: `语言文案测试-${Date.now()}`, stage: 'junior_high', subjectKey: 'physics' },
|
||||
});
|
||||
expect(notebookRes.ok()).toBeTruthy();
|
||||
const notebook = await notebookRes.json();
|
||||
const itemRes = await page.request.post('/api/error-items', {
|
||||
data: {
|
||||
subjectId: notebook.id,
|
||||
questionText: `语言文案题目 ${Date.now() % 1000}`,
|
||||
answerText: 's = vt',
|
||||
analysis: '路程等于速度乘以时间。',
|
||||
knowledgePoints: ['匀速直线运动'],
|
||||
},
|
||||
});
|
||||
expect(itemRes.ok()).toBeTruthy();
|
||||
const item = await itemRes.json();
|
||||
|
||||
await page.goto(`/error-items/${item.id}`);
|
||||
await expect(page.getByRole('heading', { name: '错题详情' })).toBeVisible({ timeout: 15000 });
|
||||
|
||||
await page.getByTitle('编辑 题目').click();
|
||||
expect(await card(page, '题目').locator('textarea').getAttribute('placeholder')).toBe('输入题目内容...');
|
||||
await card(page, '题目').getByRole('button', { name: '取消' }).click();
|
||||
|
||||
await page.getByTitle('编辑 参考答案').click();
|
||||
expect(await card(page, '参考答案').locator('textarea').getAttribute('placeholder')).toBe('输入答案...');
|
||||
await card(page, '参考答案').getByRole('button', { name: '取消' }).click();
|
||||
|
||||
await page.getByTitle('编辑 解析').click();
|
||||
expect(await card(page, '解析').locator('textarea').getAttribute('placeholder')).toBe('输入解析...');
|
||||
await card(page, '解析').getByRole('button', { name: '取消' }).click();
|
||||
|
||||
await page.evaluate(() => localStorage.setItem('app-language', 'en'));
|
||||
await page.reload();
|
||||
await expect(page.getByRole('heading', { name: 'Wrong Answer Detail' })).toBeVisible({ timeout: 15000 });
|
||||
|
||||
await page.getByTitle('Edit Question', { exact: true }).click();
|
||||
expect(await card(page, 'Question').locator('textarea').getAttribute('placeholder')).toBe('Enter question text...');
|
||||
await card(page, 'Question').getByRole('button', { name: 'Cancel' }).click();
|
||||
|
||||
await page.getByTitle('Edit Correct Answer', { exact: true }).click();
|
||||
expect(await card(page, 'Correct Answer').locator('textarea').getAttribute('placeholder')).toBe('Enter answer...');
|
||||
await card(page, 'Correct Answer').getByRole('button', { name: 'Cancel' }).click();
|
||||
|
||||
await page.getByTitle('Edit Analysis', { exact: true }).click();
|
||||
expect(await card(page, 'Analysis').locator('textarea').getAttribute('placeholder')).toBe('Enter analysis...');
|
||||
await card(page, 'Analysis').getByRole('button', { name: 'Cancel' }).click();
|
||||
|
||||
await page.evaluate(() => localStorage.setItem('app-language', 'zh'));
|
||||
expect((await page.request.delete(`/api/error-items/${item.id}/delete`)).ok()).toBeTruthy();
|
||||
expect((await page.request.delete(`/api/notebooks/${notebook.id}`)).ok()).toBeTruthy();
|
||||
});
|
||||
@@ -218,7 +218,7 @@ export default function ErrorDetailPage() {
|
||||
onSave={(answerText) => saveFields({ answerText })}
|
||||
logLabel="answer"
|
||||
rows={5}
|
||||
placeholder="Enter answer..."
|
||||
placeholder={t.detail.answerPlaceholder}
|
||||
cardClassName="border-primary/20"
|
||||
titleClassName="text-primary"
|
||||
contentClassName="font-semibold"
|
||||
@@ -241,7 +241,7 @@ export default function ErrorDetailPage() {
|
||||
onSave={(analysis) => saveFields({ analysis })}
|
||||
logLabel="analysis"
|
||||
rows={12}
|
||||
placeholder="Enter analysis..."
|
||||
placeholder={t.detail.analysisPlaceholder}
|
||||
readOnly={readOnly}
|
||||
headerActions={<GenerateAnalysisFigureButton errorItemId={item.id} onDone={(analysisFigureSvg) => updateItem({ analysisFigureSvg })} onReload={reload} />}
|
||||
>
|
||||
|
||||
@@ -47,7 +47,7 @@ function SectionHeader({ section }: { section: ExamSection<ExamQuestionDetail> }
|
||||
<span className="text-sm text-muted-foreground">
|
||||
{summary}
|
||||
{section.scoreTotal !== null && section.unscored > 0 && (
|
||||
<span>({t.exam.sectionSummaryUnscored.replace("{count}", String(section.unscored))})</span>
|
||||
<span>{t.exam.parenthesizedUnscored.replace("{count}", String(section.unscored))}</span>
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -247,7 +247,7 @@ export default function ExamDetailPage() {
|
||||
<span>
|
||||
{t.exam.totalScore.replace("{total}", formatExamScore(readyScoreSummary.total))}
|
||||
{readyScoreSummary.unscored > 0 && (
|
||||
<span className="text-xs">({t.exam.totalScoreUnscored.replace("{count}", String(readyScoreSummary.unscored))})</span>
|
||||
<span className="text-xs">{t.exam.parenthesizedUnscored.replace("{count}", String(readyScoreSummary.unscored))}</span>
|
||||
)}
|
||||
</span>
|
||||
)}
|
||||
|
||||
@@ -68,7 +68,7 @@ function ExamPrintQuestion({
|
||||
<div className="exam-question-head">
|
||||
<span>
|
||||
{displayNumber}.
|
||||
{typeof question.score === 'number' && `(${formatExamScore(question.score)} ${scoreUnit})`}
|
||||
{typeof question.score === 'number' && t.exam.parenthesizedScore.replace("{score}", formatExamScore(question.score)).replace("{unit}", scoreUnit)}
|
||||
</span>
|
||||
<span className="exam-source">{t.exam.sourceLabel}: {sourceNo}</span>
|
||||
{showMarkers && <ExamQuestionQrMarker paperId={paperId} questionId={question.id} />}
|
||||
@@ -124,7 +124,7 @@ function ExamPrintSectionHeader({ section }: { section: ExamSection<ExamQuestion
|
||||
<span className="exam-section-summary">
|
||||
{summary}
|
||||
{section.scoreTotal !== null && section.unscored > 0 && (
|
||||
<span>({t.exam.sectionSummaryUnscored.replace("{count}", String(section.unscored))})</span>
|
||||
<span>{t.exam.parenthesizedUnscored.replace("{count}", String(section.unscored))}</span>
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
@@ -149,7 +149,7 @@ export const ExamPrintSheet = forwardRef<HTMLDivElement, ExamPrintSheetProps>(fu
|
||||
const questions = paper.questions.filter((question) => question.status === "ready" && question.questionText);
|
||||
// 满分只统计已设分值的题目;全部未设时不显示满分行,打印与旧版一致
|
||||
const fullScore = summarizeExamScores(questions.map((question) => question.score ?? null)).total;
|
||||
const scoreUnit = language === "en" ? "pts" : "分";
|
||||
const scoreUnit = t.exam.scoreUnit;
|
||||
// 按题型分大题:开启且全卷均为就绪题目时才分组(与非分组打印的过滤口径一致)
|
||||
const sections = paper.groupByType ? groupExamQuestions(questions, language, customTypes) : null;
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import { apiClient } from "@/lib/api-client";
|
||||
import { confirmDialog, toast } from "@/lib/feedback";
|
||||
import { getApiErrorMessage } from "@/lib/error-message";
|
||||
import { frontendLogger } from "@/lib/frontend-logger";
|
||||
import { GRADE_NAMES } from "@/lib/grade-options";
|
||||
import { BankQuestionCard } from "@/components/banks/bank-question-card";
|
||||
import type { QuestionBankDetail } from "@/lib/question-bank/types";
|
||||
import type { Notebook } from "@/types/api";
|
||||
@@ -205,7 +204,7 @@ export function BankDetail({ bankId, notebooks, onChanged, onDeleted, canManage
|
||||
>
|
||||
<option value="">{t.banks.allGrades}</option>
|
||||
{grades.map((value) => (
|
||||
<option key={value} value={value}>{GRADE_NAMES[value - 1]}</option>
|
||||
<option key={value} value={value}>{t.gradeSelection.names[value - 1]}</option>
|
||||
))}
|
||||
</select>
|
||||
</label>
|
||||
|
||||
@@ -10,7 +10,6 @@ import { useLanguage } from "@/contexts/LanguageContext";
|
||||
import { apiClient } from "@/lib/api-client";
|
||||
import { confirmDialog, toast } from "@/lib/feedback";
|
||||
import { getApiErrorMessage } from "@/lib/error-message";
|
||||
import { GRADE_NAMES } from "@/lib/grade-options";
|
||||
import { QUESTION_TYPE_NAMES_EN, QUESTION_TYPE_NAMES_ZH } from "@/lib/question/question-type";
|
||||
import type { QuestionType } from "@/lib/question/question-type";
|
||||
import type { BankQuestionRow } from "@/lib/question-bank/types";
|
||||
@@ -69,12 +68,13 @@ export function BankQuestionCard({ bankId, question, notebooks, onChanged, canMa
|
||||
};
|
||||
|
||||
const questionTypeNames = language === "zh" ? QUESTION_TYPE_NAMES_ZH : QUESTION_TYPE_NAMES_EN;
|
||||
const gradeName = question.grade ? GRADE_NAMES[question.grade - 1] : null;
|
||||
const gradeName = question.grade ? t.gradeSelection.names[question.grade - 1] : null;
|
||||
const semesterName = question.semester === "上" ? t.gradeSelection.firstSemester : question.semester === "下" ? t.gradeSelection.secondSemester : question.semester ?? "";
|
||||
|
||||
return (
|
||||
<div className="space-y-3 rounded-lg border border-border p-4">
|
||||
<div className="flex flex-wrap items-center gap-2 text-xs text-muted-foreground">
|
||||
{gradeName && <span>{gradeName}{question.semester ?? ""}</span>}
|
||||
{gradeName && <span>{gradeName}{semesterName}</span>}
|
||||
{question.questionType && <span>{questionTypeNames[question.questionType as QuestionType] ?? question.questionType}</span>}
|
||||
<DifficultyStars value={question.difficultyStars} showUnrated={false} />
|
||||
{question.source && <span className="truncate">{question.source}</span>}
|
||||
|
||||
@@ -48,7 +48,7 @@ export function QuestionCard({ item, educationStage, saveFields, onUpdate, reloa
|
||||
<CardContent className="space-y-4">
|
||||
{question.editing ? (
|
||||
<div className="space-y-3">
|
||||
<MarkdownEditor value={question.value} onChange={question.setValue} textareaRef={questionTextRef} placeholder="Enter question text..." rows={8} className="w-full font-mono text-base md:text-sm" />
|
||||
<MarkdownEditor value={question.value} onChange={question.setValue} textareaRef={questionTextRef} placeholder={t.detail.questionPlaceholder} rows={8} className="w-full font-mono text-base md:text-sm" />
|
||||
<PinyinToolbar value={question.value} onChange={question.setValue} textareaRef={questionTextRef} subject={item.subject?.name} />
|
||||
<SaveCancelButtons onSave={question.submit} onCancel={question.cancel} />
|
||||
</div>
|
||||
|
||||
@@ -44,6 +44,7 @@ interface DraftItemCardProps {
|
||||
|
||||
/** 题目原图缩略图:点击放大,可删除 */
|
||||
function ItemImageThumbnail({ image, alt, onRemove }: { image: string; alt: string; onRemove: () => void }) {
|
||||
const { t } = useLanguage();
|
||||
const [enlarged, setEnlarged] = useState(false);
|
||||
return (
|
||||
<div className="relative inline-block">
|
||||
@@ -61,7 +62,7 @@ function ItemImageThumbnail({ image, alt, onRemove }: { image: string; alt: stri
|
||||
variant="ghost"
|
||||
className="absolute -right-2 -top-2 h-6 w-6 rounded-full bg-background border shadow-sm"
|
||||
onClick={onRemove}
|
||||
aria-label="删除图片"
|
||||
aria-label={t.importBatch.removeImage}
|
||||
>
|
||||
<X className="h-3 w-3" />
|
||||
</Button>
|
||||
@@ -70,7 +71,7 @@ function ItemImageThumbnail({ image, alt, onRemove }: { image: string; alt: stri
|
||||
type="button"
|
||||
className="fixed inset-0 z-50 flex items-center justify-center bg-black/80 p-4"
|
||||
onClick={() => setEnlarged(false)}
|
||||
aria-label="关闭大图"
|
||||
aria-label={t.importBatch.closeImage}
|
||||
>
|
||||
<img src={image} alt={alt} className="max-h-full max-w-full object-contain" />
|
||||
</button>
|
||||
|
||||
@@ -91,7 +91,7 @@ export function ImportTaskCard({ task, now, onReview, onViewItem, onRetry, onDis
|
||||
{task.attempts > 1 && <span>{t.importTasks.attempts.replace("{count}", String(task.attempts))}</span>}
|
||||
</div>
|
||||
{stages.length > 0 && (
|
||||
<ul className="flex flex-wrap gap-x-3 gap-y-1 text-xs text-muted-foreground tabular-nums" aria-label="timings">
|
||||
<ul className="flex flex-wrap gap-x-3 gap-y-1 text-xs text-muted-foreground tabular-nums" aria-label={t.importTasks.timingsLabel}>
|
||||
{stages.map(({ stage, ms }) => (
|
||||
<li key={stage}>{t.importTasks.timings[stage]} {formatDuration(ms)}</li>
|
||||
))}
|
||||
|
||||
@@ -40,12 +40,12 @@ export function MobileNavPreferenceSetting() {
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="exams">{t.settings?.general?.mobileNavFourthOptions?.exams || "试卷"}</SelectItem>
|
||||
<SelectItem value="review">{t.settings?.general?.mobileNavFourthOptions?.review || "复习"}</SelectItem>
|
||||
<SelectItem value="exams">{t.settings?.general?.mobileNavFourthOptions?.exams || "Exams"}</SelectItem>
|
||||
<SelectItem value="review">{t.settings?.general?.mobileNavFourthOptions?.review || "Review"}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t.settings?.general?.mobileNavFourthDesc || "选择手机底部导航栏的第 4 个入口,默认为试卷。"}
|
||||
{t.settings?.general?.mobileNavFourthDesc || "Choose the 4th entry in the mobile bottom navigation. Exams is the default."}
|
||||
</p>
|
||||
{message && <p className="text-xs text-muted-foreground" role="status">{message}</p>}
|
||||
</div>
|
||||
|
||||
@@ -62,7 +62,7 @@ export function CustomTags({ tagSet }: CustomTagsProps) {
|
||||
await fetchCustomTags();
|
||||
} catch (error) {
|
||||
frontendLogger.error('[Tags]', 'Failed to delete tag', { error });
|
||||
toast.error("Failed to delete tag");
|
||||
toast.error(t.tags?.custom?.deleteFailed || "Failed to delete tag");
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -692,6 +692,9 @@ export const en = {
|
||||
wrongAnswerImageAlt: "My answer image",
|
||||
title: "Wrong Answer Detail",
|
||||
question: "Question",
|
||||
questionPlaceholder: "Enter question text...",
|
||||
answerPlaceholder: "Enter answer...",
|
||||
analysisPlaceholder: "Enter analysis...",
|
||||
originalProblem: "Original Problem",
|
||||
yourNotes: "Your Answer / Notes",
|
||||
noNotes: "No notes added yet.",
|
||||
@@ -880,6 +883,7 @@ export const en = {
|
||||
success: "Tag added successfully!",
|
||||
exists: "Tag already exists",
|
||||
deleteConfirm: "Are you sure you want to delete tag \"{tag}\"?",
|
||||
deleteFailed: "Failed to delete tag",
|
||||
selectGrade: "Select Grade",
|
||||
noGrade: "No Grade",
|
||||
},
|
||||
@@ -1816,6 +1820,7 @@ export const en = {
|
||||
savedTo: "Saved to \"{notebook}\" (ID: {id})",
|
||||
duplicateSaved: "Duplicate question: recorded in the existing question's practice history",
|
||||
itemDeleted: "Saved, but the question has since been deleted",
|
||||
timingsLabel: "Timings",
|
||||
timings: {
|
||||
read: "Read",
|
||||
convert: "Convert",
|
||||
@@ -1968,6 +1973,7 @@ export const en = {
|
||||
imageTextHint: "The text here only helps you recognize each question. After you start, each question is recognized again from its area on the photo.",
|
||||
questionImage: "Question image",
|
||||
removeImage: "Remove image",
|
||||
closeImage: "Close image",
|
||||
submitting: "Submitting…",
|
||||
discard: "Discard batch",
|
||||
discardConfirm: "Discard this batch? Questions already imported are kept; unfinished results will be deleted.",
|
||||
@@ -2192,6 +2198,9 @@ export const en = {
|
||||
sectionSummary: "{count} question(s)",
|
||||
sectionSummaryScored: "{count} question(s), {total} pts in total",
|
||||
sectionSummaryUnscored: "{count} question(s) without score",
|
||||
parenthesizedUnscored: " ({count} question(s) without score)",
|
||||
parenthesizedScore: "({score} {unit})",
|
||||
scoreUnit: "pts",
|
||||
answerKey: "Answer Key",
|
||||
answerLabel: "Answer",
|
||||
analysisLabel: "Analysis",
|
||||
|
||||
@@ -692,6 +692,9 @@ export const zh = {
|
||||
wrongAnswerImageAlt: "我的答案图片",
|
||||
title: "错题详情",
|
||||
question: "题目",
|
||||
questionPlaceholder: "输入题目内容...",
|
||||
answerPlaceholder: "输入答案...",
|
||||
analysisPlaceholder: "输入解析...",
|
||||
originalProblem: "原始问题",
|
||||
yourNotes: "你的笔记 / 答案",
|
||||
noNotes: "暂无笔记",
|
||||
@@ -880,6 +883,7 @@ export const zh = {
|
||||
success: "标签添加成功!",
|
||||
exists: "标签已存在",
|
||||
deleteConfirm: "确定要删除标签 \"{tag}\" 吗?",
|
||||
deleteFailed: "删除标签失败",
|
||||
selectGrade: "选择年级",
|
||||
noGrade: "不选择年级",
|
||||
},
|
||||
@@ -1815,6 +1819,7 @@ export const zh = {
|
||||
savedTo: "已保存到「{notebook}」,题目 ID:{id}",
|
||||
duplicateSaved: "重复题:已记入原题的做错记录",
|
||||
itemDeleted: "已保存,但该错题之后已被删除",
|
||||
timingsLabel: "耗时明细",
|
||||
timings: {
|
||||
read: "读取",
|
||||
convert: "转换",
|
||||
@@ -1967,6 +1972,7 @@ export const zh = {
|
||||
imageTextHint: "这里的文字仅用于辨认题目;开始后会按每道题在原图上的区域重新识别。",
|
||||
questionImage: "题目原图",
|
||||
removeImage: "删除图片",
|
||||
closeImage: "关闭大图",
|
||||
submitting: "正在提交…",
|
||||
discard: "放弃这批",
|
||||
discardConfirm: "确定放弃这批题目?已导入的错题不受影响,未完成的结果将被删除。",
|
||||
@@ -2191,6 +2197,9 @@ export const zh = {
|
||||
sectionSummary: "共 {count} 题",
|
||||
sectionSummaryScored: "共 {count} 题,共 {total} 分",
|
||||
sectionSummaryUnscored: "{count} 题未设分值",
|
||||
parenthesizedUnscored: "({count} 题未设分值)",
|
||||
parenthesizedScore: "({score} {unit})",
|
||||
scoreUnit: "分",
|
||||
answerKey: "参考答案与解析",
|
||||
answerLabel: "答案",
|
||||
analysisLabel: "解析",
|
||||
|
||||
Reference in New Issue
Block a user