forge
Explore
Log in

Don't you dare go Hollow

🔀 merge remote main before publishing

Browse files at this commit

4bea99d092e70e14c0e6a7c1e1cb918959e8d4dcBurak BoduroğluParent: 451cb58aaafb32
  • chore
    • 🔀 merge remote main before publishing
Show full message
chore: 🔀 merge remote main before publishing

- include the upstream instance detail crash fix

- preserve the local UI and picker improvements
src/pages/instance-detail-page.test.tsxadded+96 -0
@@ -0,0 +1,96 @@
1+import { cleanup, render, screen } from "@solidjs/testing-library";
2+import InstanceDetailPage from "@/pages/instance-detail-page";
3+
4+const instance = {
5+ id: "instance-1",
6+ class: "class-1",
7+ course: "course-1",
8+ offering: "offering-1",
9+ title: "Matematik",
10+ title_overridden: false,
11+ description: "",
12+ description_overridden: false,
13+ ders_saati: 4,
14+ ders_saati_overridden: false,
15+ counts_toward_karne: true,
16+ counts_toward_karne_overridden: false,
17+ subjects_inherited: true,
18+ subjects: [],
19+ exam_weights_inherited: true,
20+ exam_weights: [],
21+ weekly_plan_inherited: true,
22+ weekly_plan: [],
23+ enrollment_count: 0,
24+ teachers: [],
25+};
26+
27+vi.mock("@tanstack/solid-router", () => ({
28+ Link: (props: { children: unknown }) => <a>{props.children}</a>,
29+ Navigate: () => <span>redirect</span>,
30+ useNavigate: () => vi.fn(),
31+ useParams: () => () => ({ id: "instance-1" }),
32+ useLocation: () => () => ({ pathname: "/instances/instance-1", search: {}, hash: "" }),
33+}));
34+
35+vi.mock("@/stores/auth-context", () => ({
36+ useAuth: () => ({
37+ user: () => ({ id: "u-1", username: "admin", role: "manager", name: "Admin", surname: "User" }),
38+ loading: () => false,
39+ error: () => undefined,
40+ refresh: async () => undefined,
41+ }),
42+}));
43+
44+vi.mock("@/stores/modules-context", () => ({
45+ useModules: () => ({
46+ enabled: () => null,
47+ loading: () => false,
48+ isEnabled: () => true,
49+ refresh: () => {},
50+ }),
51+}));
52+
53+vi.mock("@/stores/preferences-context", () => ({
54+ useT: () => (key: string) => key,
55+}));
56+
57+vi.mock("@/api/classes", () => ({
58+ getClassById: async () => ({ id: "class-1", name: "9-A", teacher: null }),
59+}));
60+
61+vi.mock("@/api/courses", () => ({
62+ getCourseById: async () => ({ id: "course-1", title: "Matematik" }),
63+ getCourseSubjects: async () => ({ items: [], total: 0 }),
64+}));
65+
66+vi.mock("@/api/limits", () => ({
67+ getLimits: async () => ({}),
68+}));
69+
70+vi.mock("@/api/instances", () => ({
71+ getInstanceById: async () => instance,
72+ getInstanceEnrollments: async () => ({ items: [], total: 0 }),
73+ getInstanceExams: async () => ({ items: [], total: 0 }),
74+ patchInstanceById: async () => instance,
75+ postInstanceEnrollment: async () => ({ id: "enroll-1" }),
76+ postInstanceExam: async () => ({ id: "exam-1" }),
77+ deleteInstanceEnrollmentByUserId: async () => undefined,
78+}));
79+
80+vi.mock("@/api/settings", () => ({
81+ getSettings: async () => ({ exam_kinds: [] }),
82+}));
83+
84+vi.mock("@/api/exams", () => ({
85+ patchExamById: async () => ({ id: "exam-1" }),
86+}));
87+
88+afterEach(() => {
89+ cleanup();
90+});
91+
92+test("instance page renders instead of reading canManage before it exists", async () => {
93+ render(() => <InstanceDetailPage />);
94+ expect(await screen.findByText("weeklyPlan.tab")).toBeTruthy();
95+ expect(screen.getByText("Matematik")).toBeTruthy();
96+});
src/pages/instance-detail-page.tsxmodified+10 -9
@@ -104,15 +104,8 @@ function InstanceDetailContent() {
104104 const [course] = createResource(() => instance()?.course ?? null, (courseId) => getCourseById(courseId));
105105 const [klass] = createResource(() => instance()?.class ?? null, (classId) => getClassById(classId).catch(() => null));
106106 const [settings] = createResource(() => getSettings());
107- const [limits] = createResource(() => (canManage() ? true : null), () => getLimits());
108- // Only the settings tab edits the topic set, so only it loads the catalog's.
109- const [courseSubjects] = createResource(
110- () => (canManage() && tab() === "settings" ? instance()?.course ?? null : null),
111- async (courseId) => (courseId ? (await getCourseSubjects(courseId)).items : []),
112- );
113- // The section's resolved weight map, in the shape examWeight() reads.
114- const sectionWeights = () => instance()?.exam_weights.map((entry) => ({ name: entry.kind, weight: entry.weight })) ?? settings()?.exam_kinds;
115-
107+ // Must sit above any createResource that reads it: the source runs now, and a
108+ // later const is still in the temporal dead zone.
116109 // Manager+, an assigned teacher, or the şube's homeroom teacher may run it.
117110 const canManage = () => {
118111 const i = instance();
@@ -123,6 +116,14 @@ function InstanceDetailContent() {
123116 return klass.latest?.teacher?.id === u.id;
124117 };
125118 const canStaff = () => hasMinRole(auth.user()?.role ?? "student", "manager");
119+ const [limits] = createResource(() => (canManage() ? true : null), () => getLimits());
120+ // Only the settings tab edits the topic set, so only it loads the catalog's.
121+ const [courseSubjects] = createResource(
122+ () => (canManage() && tab() === "settings" ? instance()?.course ?? null : null),
123+ async (courseId) => (courseId ? (await getCourseSubjects(courseId)).items : []),
124+ );
125+ // The section's resolved weight map, in the shape examWeight() reads.
126+ const sectionWeights = () => instance()?.exam_weights.map((entry) => ({ name: entry.kind, weight: entry.weight })) ?? settings()?.exam_kinds;
126127
127128 const [exams, { refetch: refetchExams }] = createResource(
128129 () => (tabOn.exams() ? id() : null),