hezarfen_frontend
Clone
https://git.tahinli.com/Hezarfen/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiB5fcd955Burak Boduroğlu2 months ago730 commits
| 1 | import type { Homework, HomeworkRosterEntry } from "@/api/client"; |
| 2 | import { queueCandidates, queueRow } from "./homework-queue"; |
| 3 | |
| 4 | const DAY = 24 * 60 * 60 * 1000; |
| 5 | const now = Date.UTC(2026, 8, 19, 9); |
| 6 | const hw = (id: string, due: number, createdBy = "t-1"): Homework => ({ |
| 7 | id, |
| 8 | class_course: "i-1", |
| 9 | subject: "s-1", |
| 10 | title: id, |
| 11 | description: null, |
| 12 | due_at: due, |
| 13 | assigned: null, |
| 14 | created_by: createdBy, |
| 15 | created_at: now - 30 * DAY, |
| 16 | }); |
| 17 | const row = (state: Partial<HomeworkRosterEntry>): HomeworkRosterEntry => ({ |
| 18 | user: "u", |
| 19 | submission: null, |
| 20 | result: null, |
| 21 | missing: false, |
| 22 | unenrolled: false, |
| 23 | ...state, |
| 24 | }); |
| 25 | |
| 26 | it("keeps the teacher's own homework due around now, closest first", () => { |
| 27 | const picked = queueCandidates( |
| 28 | [hw("old", now - 20 * DAY), hw("yesterday", now - DAY), hw("other-teacher", now - DAY, "t-2"), hw("tomorrow", now + DAY), hw("next-week", now + 7 * DAY), hw("last-week", now - 7 * DAY)], |
| 29 | "t-1", |
| 30 | now, |
| 31 | ); |
| 32 | expect(picked.map((item) => item.id)).toEqual(["yesterday", "tomorrow", "last-week"]); |
| 33 | }); |
| 34 | |
| 35 | it("counts missing and ungraded work, leaving unenrolled rows out", () => { |
| 36 | const submission = { text: "done", submitted_at: now, updated_at: now, late: false, files: [] }; |
| 37 | const counts = queueRow(hw("h", now), [ |
| 38 | row({ missing: true }), |
| 39 | row({ missing: true, unenrolled: true }), |
| 40 | row({ submission }), |
| 41 | row({ submission, result: { mark: 80 } as never }), |
| 42 | row({}), |
| 43 | ]); |
| 44 | expect(counts).toMatchObject({ missing: 1, toGrade: 1 }); |
| 45 | }); |