AnCao/scripts/import_test.go
yanlongqi de8480a328 重构答题系统:组件拆分、进度跟踪、完成统计
主要改动:
1. 组件拆分:将Question.tsx(605行)拆分为4个子组件(303行)
   - QuestionProgress: 进度条和统计显示
   - QuestionCard: 题目卡片和答题界面
   - AnswerResult: 答案结果展示
   - CompletionSummary: 完成统计摘要

2. 新增功能:
   - 答题进度条:显示当前进度、正确数、错误数
   - 进度保存:使用localStorage持久化答题进度
   - 完成统计:答完所有题目后显示统计摘要和正确率
   - 从第一题开始:改为顺序答题而非随机

3. UI优化:
   - 移除右上角统计按钮
   - 移除底部随机题目、题目列表、筛选按钮
   - 移除"开始xxx答题"提示消息
   - 简化页面布局

4. 代码优化:
   - 提高代码可维护性和可测试性
   - 单一职责原则,每个组件负责一个特定功能

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-04 18:39:15 +08:00

83 lines
2.3 KiB
Go
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.

package main
import (
"encoding/json"
"os"
"testing"
)
// 测试JSON解析
func TestJSONParsing(t *testing.T) {
// 读取JSON文件
data, err := os.ReadFile("../practice_question_pool.json")
if err != nil {
t.Fatalf("读取JSON文件失败: %v", err)
}
// 解析JSON
var groups []JSONQuestionGroup
if err := json.Unmarshal(data, &groups); err != nil {
t.Fatalf("解析JSON失败: %v", err)
}
t.Logf("成功解析 %d 个题目组", len(groups))
// 检查每个题目组的类型信息
for i, group := range groups {
t.Logf("\n题目组 %d:", i+1)
t.Logf(" Type: %s", group.Type)
t.Logf(" TypeName: %s", group.TypeName)
t.Logf(" 题目数量: %d", len(group.List))
// 检查类型映射
t.Logf(" 原始类型: %s", group.Type)
// 检查是否为空
if group.Type == "" {
t.Errorf(" ❌ 题目组 %d 的 Type 为空!", i+1)
}
if group.TypeName == "" {
t.Errorf(" ❌ 题目组 %d 的 TypeName 为空!", i+1)
}
if len(group.List) == 0 {
t.Errorf(" ❌ 题目组 %d 的题目列表为空!", i+1)
}
}
}
// 测试单个题目组解析
func TestSingleGroupParsing(t *testing.T) {
// 测试第一个题目组填空题type在list之后
jsonStr1 := `{
"list": [{"id": "1", "question": "test", "answers": ["answer1"]}],
"type": "fill-in-blank",
"typeName": "填空题"
}`
var group1 JSONQuestionGroup
if err := json.Unmarshal([]byte(jsonStr1), &group1); err != nil {
t.Fatalf("解析题目组1失败: %v", err)
}
t.Logf("题目组1 - Type: %s, TypeName: %s, 题目数: %d", group1.Type, group1.TypeName, len(group1.List))
// 测试第二个题目组type在list之前
jsonStr2 := `{
"type": "fill-in-blank",
"typeName": "填空题",
"list": [{"id": "1", "question": "test", "answers": ["answer1"]}]
}`
var group2 JSONQuestionGroup
if err := json.Unmarshal([]byte(jsonStr2), &group2); err != nil {
t.Fatalf("解析题目组2失败: %v", err)
}
t.Logf("题目组2 - Type: %s, TypeName: %s, 题目数: %d", group2.Type, group2.TypeName, len(group2.List))
// 验证两种顺序解析结果是否一致
if group1.Type != group2.Type || group1.TypeName != group2.TypeName {
t.Errorf("不同字段顺序导致解析结果不一致!")
} else {
t.Log("✓ JSON字段顺序不影响解析结果")
}
}