hezarfen_frontend
Clone
https://git.tahinli.com/Hezarfen/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import { describe, expect, it } from "vitest"; |
| 2 | import type { SchoolSettings } from "@/api/client"; |
| 3 | import { dirtySettingsPatch, formatTry, mealCutoffAt, minuteToUtcTime, nextCourseWork, utcTimeToMinute } from "./meals"; |
| 4 | |
| 5 | describe("meal helpers", () => { |
| 6 | it("formats minor units as TRY", () => { |
| 7 | expect(formatTry(4550, "tr-TR")).toContain("45,50"); |
| 8 | }); |
| 9 | |
| 10 | it("converts UTC minute values", () => { |
| 11 | expect(minuteToUtcTime(540)).toBe("09:00"); |
| 12 | expect(utcTimeToMinute("23:59")).toBe(1439); |
| 13 | expect(utcTimeToMinute("24:00")).toBeNull(); |
| 14 | }); |
| 15 | |
| 16 | it("calculates the booking cutoff in UTC", () => { |
| 17 | expect(mealCutoffAt("2026-07-28", { name: "lunch", serving_minute: 720 }, 120)) |
| 18 | .toBe(Date.parse("2026-07-28T10:00:00Z")); |
| 19 | }); |
| 20 | |
| 21 | it("selects nearest course work for one instance", () => { |
| 22 | expect(nextCourseWork( |
| 23 | "i1", |
| 24 | [{ class_course: "i1", title: "Exam", starts_at: 30 } as never], |
| 25 | [{ class_course: "i1", title: "Homework", due_at: 20 } as never], |
| 26 | )?.title).toBe("Homework"); |
| 27 | }); |
| 28 | |
| 29 | // Two şubeler teaching the same course are two instances; work filed against |
| 30 | // the other one must not surface here. |
| 31 | it("ignores work filed against another instance", () => { |
| 32 | expect(nextCourseWork( |
| 33 | "i1", |
| 34 | [{ class_course: "i2", title: "Exam", starts_at: 30 } as never], |
| 35 | [{ class_course: "i2", title: "Homework", due_at: 20 } as never], |
| 36 | )).toBeNull(); |
| 37 | }); |
| 38 | |
| 39 | it("builds a field-only settings patch", () => { |
| 40 | const before = { |
| 41 | exam_kinds: [], attendance_statuses: [], grade_bands: [], max_file_bytes: 1, |
| 42 | chatbot_history_turns: 1, max_chatbot_threads: 1, max_chatbot_message_len: 100, |
| 43 | meal_slots: [], dietary_tags: [], meal_cancel_cutoff_minutes: null, |
| 44 | branches: [], excuse_kinds: [], max_excused_absent_days: null, |
| 45 | max_unexcused_absent_days: null, timezone: null, |
| 46 | } satisfies SchoolSettings; |
| 47 | expect(dirtySettingsPatch(before, { ...before, max_chatbot_threads: 2 })).toEqual({ max_chatbot_threads: 2 }); |
| 48 | }); |
| 49 | }); |