任务说明:实验页"任务"面板、布置作业时可改写;先写项目 3 任务 2、项目 6 任务 2 两份
- 每个实验一份 task.md(任务目标、控件名表格、实现步骤、和书上不一样的地方、在平台上怎么试) - 工具栏"评价项"改成"任务":上面是任务说明,下面是评价项和自己检查;不遮挡页面,第一次打开实验时自动打开 - 自己写的 Markdown 子集渲染,先转义全部 HTML(老师可以改写说明) - 作业保存任务说明(新列 task),以前布置的作业用实验现在的说明 - 测试:任务说明表格里的控件名都在示例的 Designer.cs 里 - 修改作业时实验下拉框显示标题而不是编号 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3b9f635c35
commit
90b739a2c7
17 files changed
+759
-219
No files matched your search
+23
-1
@@ -9,7 +9,7 @@ import { openDatabase } from '../src/db'
|
||||
import { createGradingQueue, type GradingQueue } from '../src/grading/queue'
|
||||
import { languageService } from '../src/language-service'
|
||||
import { sqlService } from '../src/sql-service'
|
||||
import { loadSample } from '../src/samples'
|
||||
import { loadSample, loadTask } from '../src/samples'
|
||||
|
||||
let app: ReturnType<typeof createApp>
|
||||
let queue: GradingQueue
|
||||
@@ -287,6 +287,28 @@ describe('作业', () => {
|
||||
return { t, student, classId, assignmentId: created.body.id as number, files: template }
|
||||
}
|
||||
|
||||
test('任务说明:布置时保存,老师可以改;没有保存的作业用实验现在的说明', async () => {
|
||||
const { t, student, classId, assignmentId } = await setup()
|
||||
// setup 没传任务说明(像加这个功能之前布置的作业)
|
||||
expect((await student.get(`/api/assignments/${assignmentId}`)).body.assignment.task).toBe(await loadTask(SAMPLE))
|
||||
|
||||
await t.patch(`/api/teacher/assignments/${assignmentId}`, { title: '控制报警灯', deadline: null, scoring, task: '## 老师要求\n只做前 3 步' })
|
||||
expect((await student.get(`/api/assignments/${assignmentId}`)).body.assignment.task).toBe('## 老师要求\n只做前 3 步')
|
||||
|
||||
const tooLong = await t.post('/api/teacher/assignments', {
|
||||
classId,
|
||||
sampleId: SAMPLE,
|
||||
title: '太长',
|
||||
startMode: 'ui',
|
||||
template: [],
|
||||
scoring,
|
||||
deadline: null,
|
||||
task: 'x'.repeat(20_001),
|
||||
})
|
||||
expect(tooLong.status).toBe(400)
|
||||
expect(tooLong.body.message).toContain('任务说明')
|
||||
})
|
||||
|
||||
test('分值项数要和评分规则一致', async () => {
|
||||
const t = await teacher()
|
||||
const classId = await classWithStudents(t, [])
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
// 示例的任务说明(task.md):表格里写的控件名都要在示例的 Designer.cs 里有,学生照着改名不会被带错。
|
||||
import { expect, test } from 'bun:test'
|
||||
import { listSamples, loadSample, loadTask } from '../src/samples'
|
||||
|
||||
/** 控件表格(表头有"名称")里那一列用 `反引号` 写的名字 */
|
||||
function tableNames(task: string): string[] {
|
||||
const names: string[] = []
|
||||
let column = -1
|
||||
for (const line of task.split('\n')) {
|
||||
if (!line.trim().startsWith('|')) {
|
||||
column = -1
|
||||
continue
|
||||
}
|
||||
const cells = line.trim().replace(/^\||\|$/g, '').split('|')
|
||||
const header = cells.findIndex((c) => c.includes('名称'))
|
||||
if (header >= 0) column = header
|
||||
else if (column >= 0) names.push(...[...(cells[column] ?? '').matchAll(/`([^`]+)`/g)].map((m) => m[1]))
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
test('任务说明里的控件名都在示例的界面里', async () => {
|
||||
let checked = 0
|
||||
for (const { id } of await listSamples()) {
|
||||
const task = await loadTask(id)
|
||||
if (!task) continue
|
||||
const designer = (await loadSample(id))!.filter((f) => f.path.endsWith('.Designer.cs'))
|
||||
const names = tableNames(task)
|
||||
expect(names.length, `${id} 的任务说明没有控件表格`).toBeGreaterThan(0)
|
||||
for (const name of names) {
|
||||
// 窗体本身写的是类名,控件是 this.名字
|
||||
const found = designer.some((f) => f.content.includes(`this.${name} `) || f.content.includes(`partial class ${name}`))
|
||||
expect(found, `${id}:任务说明里的 ${name} 在 Designer.cs 里找不到`).toBe(true)
|
||||
}
|
||||
checked++
|
||||
}
|
||||
expect(checked).toBeGreaterThan(0)
|
||||
})
|
||||
Reference in new issue
Block a user