Every area — courses, rooms, boards, topics, tasks, files, quizzes, teams,
groups, submissions, grades — was checked for data the instance has and the
tools did not show.
Grades and feedback. A teacher's /homework page is a different page from a
student's: grade and comment live in the grading form, one block per
submission, so a teacher account reported every graded submission as having
neither. parseTeacherGrading reads the form, and list_submissions can now
include the written feedback and who handed the work in.
Names. /api/v1 is partly served: courses, users and classes survive in the
deployment's ingress table, and users/{id} is the only route from an id to a
name. Submitters, file creators and course teachers resolve through it, and
degrade to "not visible to this account" where a student may not read them.
Courses, rooms and classes. get_course adds the description, teachers,
member count and weekly timetable from /api/v1/courses. list_classes is new.
get_room reports what the account may do — allowedOperations is an object of
booleans, not the list it was typed as — and applicants and invitation links
where it may manage them.
Board and topic content. Link descriptions, image alt text, drawing and
video-conference titles, the ids behind external tools and H5P content (the
only thing resembling a quiz), and what a deleted element used to be. Topic
Etherpad pads are read like board pads, and htmlToText keeps table columns
apart and drops template indentation.
Files. A scan with no text layer falls back to the preview endpoint, whose
width and outputFormat are undocumented enums, so Claude gets a picture of
the page; list_files reports counts and sizes. Teams stay documented as
unreadable at any API version; their files come later.
What the crawl missed. Tasks attached to topics (18 of 60 on the live
account), each course's own file area, and — behind INDEX_PERSONAL_FILES —
personal files and submissions with their grade comments, so search and
what_changed cover grading. A submission hit points at get_task.
The local instance's preview profile gets an ImageMagick policy that allows
the coders its 7.1.2 build needs; the image's own denies them all.
110 tests.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
155 lines
7.0 KiB
TypeScript
155 lines
7.0 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import { describe, it } from 'node:test';
|
|
import { parseHomeworkPage, parseTeacherGrading } from '../src/core/homework-page.ts';
|
|
|
|
/**
|
|
* Fixtures mirror the legacy client's templates (feedback.hbs, submission.hbs)
|
|
* as actually served — including the parts that are absent for a student, which
|
|
* is what makes every field optional.
|
|
*/
|
|
const page = (parts: { submission?: string; feedback?: string; afterSubmission?: string }) => `
|
|
<html><body>
|
|
<nav class="nav tab-links"><a href="#activetabid=extended">Details</a></nav>
|
|
<section id="extended" class="tab-content">keine Beschreibung vorhanden</section>
|
|
<section id="submission" class="tab-content">${parts.submission ?? ''}</section>
|
|
${parts.afterSubmission ?? ''}
|
|
${parts.feedback === undefined ? '' : `<section id="feedback" class="tab-content">${parts.feedback}</section>`}
|
|
</body></html>`;
|
|
|
|
const fileCard = (id: string, name: string, size = 1234) =>
|
|
`<div class="card file " data-file-name="${name}" data-file-size="${size}" data-file-id="${id}"></div>`;
|
|
|
|
describe('parseHomeworkPage', () => {
|
|
it("reads the teacher's written feedback, which no API exposes", () => {
|
|
const html = page({
|
|
feedback: `<div class="comment ckcontent" data-testid="feedback-comment"><p>vollständig und nachvollziehbar</p></div>`,
|
|
});
|
|
assert.equal(parseHomeworkPage(html)?.gradeComment, 'vollständig und nachvollziehbar');
|
|
});
|
|
|
|
it('reads a percentage grade from the feedback tab', () => {
|
|
const html = page({ feedback: '<p>Du hast 85% erreicht</p>' });
|
|
assert.equal(parseHomeworkPage(html)?.gradePercent, 85);
|
|
});
|
|
|
|
it('reads the student\'s typed answer from the editable textarea', () => {
|
|
const html = page({
|
|
submission: `<textarea data-testid="submission-text" name="comment"> <p>Meine Lösung</p> </textarea>`,
|
|
});
|
|
assert.equal(parseHomeworkPage(html)?.submittedText, 'Meine Lösung');
|
|
});
|
|
|
|
it('reads the typed answer from the read-only form once submission closed', () => {
|
|
// The read-only `<div class="comment">` is a sibling *after* the closed
|
|
// submission section, not a child of it — verified against a real 33.40
|
|
// page for a past-due submission. A fixture that nested it inside the
|
|
// section (as an earlier one did) hid a bug where every past-due
|
|
// submission lost its text. See src/core/homework-page.ts.
|
|
const html = page({
|
|
submission: `<section class="files" data-testid="submissions-section-files"></section>`,
|
|
afterSubmission: `<div class="comment"><p>Abgegebener Text</p></div>`,
|
|
});
|
|
assert.equal(parseHomeworkPage(html)?.submittedText, 'Abgegebener Text');
|
|
});
|
|
|
|
it('does not confuse the submitted text with the teacher feedback comment', () => {
|
|
// Both are comment divs, distinguished only by the exact class: the
|
|
// student's is `class="comment"`, the teacher's `class="comment ckcontent"`.
|
|
const html = page({
|
|
afterSubmission: `<div class="comment"><p>Meine Abgabe</p></div>`,
|
|
feedback: `<div class="comment ckcontent" data-testid="feedback-comment"><p>Gut gemacht</p></div>`,
|
|
});
|
|
const detail = parseHomeworkPage(html);
|
|
assert.equal(detail?.submittedText, 'Meine Abgabe');
|
|
assert.equal(detail?.gradeComment, 'Gut gemacht');
|
|
});
|
|
|
|
it('separates submitted files from files the teacher returned', () => {
|
|
const html = page({
|
|
submission: fileCard('a'.repeat(24), 'meine-abgabe.pdf'),
|
|
feedback: fileCard('b'.repeat(24), 'korrektur.pdf'),
|
|
});
|
|
const detail = parseHomeworkPage(html);
|
|
assert.deepEqual(detail?.submittedFiles, [{ id: 'a'.repeat(24), name: 'meine-abgabe.pdf' }]);
|
|
assert.deepEqual(detail?.gradingFiles, [{ id: 'b'.repeat(24), name: 'korrektur.pdf' }]);
|
|
});
|
|
|
|
it('returns a result with nothing set when the page carries no submission', () => {
|
|
// The common case for an ungraded task: sections present but empty.
|
|
const detail = parseHomeworkPage(page({}));
|
|
assert.ok(detail);
|
|
assert.equal(detail.submittedText, undefined);
|
|
assert.equal(detail.gradeComment, undefined);
|
|
assert.deepEqual(detail.gradingFiles, []);
|
|
});
|
|
|
|
it('gives up rather than guessing when the markup is not a homework page', () => {
|
|
assert.equal(parseHomeworkPage('<html><body>Anmelden</body></html>'), undefined);
|
|
});
|
|
|
|
it('decodes entities in file names', () => {
|
|
const html = page({ submission: fileCard('c'.repeat(24), 'A&B "final".pdf') });
|
|
assert.equal(parseHomeworkPage(html)?.submittedFiles[0]?.name, 'A&B "final".pdf');
|
|
});
|
|
});
|
|
|
|
/**
|
|
* The teacher's grading form, as the legacy client renders it.
|
|
*
|
|
* Anchored on the `name=` attributes the POST handler reads rather than on
|
|
* layout: one hidden `submissionId` per block, `teamMembers` naming who handed
|
|
* it in, a `grade` number input whose `value` is empty when ungraded (the
|
|
* `placeholder` is a hint, not a grade), and a `gradeComment` textarea whose
|
|
* body arrives HTML-escaped.
|
|
*/
|
|
const gradingBlock = (
|
|
submissionId: string,
|
|
submitterId: string,
|
|
grade: string,
|
|
comment: string,
|
|
) => `
|
|
<input name="submissionId" type="hidden" data-force-value="true" value="${submissionId}" />
|
|
<input name="teamMembers" id="teamMembers" type="hidden" data-force-value="true" value="${submitterId}" />
|
|
<form class="form ${submissionId}" method="post" action="/homework/submit/${submissionId}">
|
|
<input type="hidden" name="graded" value="true"/>
|
|
<label>Bewertung<small> in Prozent</small></label>
|
|
<input data-testid="evaluation_procent" type="number" min="0" max="100" name="grade" placeholder="95" value="${grade}" />
|
|
<label>Kommentar</label>
|
|
<textarea name="gradeComment" data-parent-id="${submissionId}" data-parent-type="gradings" data-testid="submission-comment">
|
|
${comment}
|
|
</textarea>
|
|
</form>`;
|
|
|
|
describe('parseTeacherGrading', () => {
|
|
const a = 'a'.repeat(24);
|
|
const b = 'b'.repeat(24);
|
|
const student1 = '1'.repeat(24);
|
|
const student2 = '2'.repeat(24);
|
|
|
|
it('reads every submission on the form, with its submitter', () => {
|
|
const html = `<section id="submissions">${gradingBlock(a, student1, '', '<p>Alles richtig!</p>')}${gradingBlock(b, student2, '100', '<p>Alles korrekt!</p>')}</section>`;
|
|
const grading = parseTeacherGrading(html);
|
|
assert.equal(grading.length, 2);
|
|
assert.deepEqual(grading[0]?.submitterIds, [student1]);
|
|
assert.deepEqual(grading[1]?.submitterIds, [student2]);
|
|
});
|
|
|
|
it('distinguishes a feedback-only grade from a percentage', () => {
|
|
const html = gradingBlock(a, student1, '', '<p>Alles richtig!</p>');
|
|
const [entry] = parseTeacherGrading(html);
|
|
// An empty value is ungraded; the placeholder "95" must not be read as one.
|
|
assert.equal(entry?.gradePercent, undefined);
|
|
assert.equal(entry?.gradeComment, 'Alles richtig!');
|
|
});
|
|
|
|
it('reads a percentage when one was given', () => {
|
|
const [entry] = parseTeacherGrading(gradingBlock(b, student2, '100', '<p>Gut</p>'));
|
|
assert.equal(entry?.gradePercent, 100);
|
|
assert.equal(entry?.gradeComment, 'Gut');
|
|
});
|
|
|
|
it('returns nothing for the student view, which has no grading form', () => {
|
|
assert.deepEqual(parseTeacherGrading(page({ feedback: '<div data-testid="feedback-comment">Gut</div>' })), []);
|
|
});
|
|
});
|