forge
Explore
Log in

Don't you dare go Hollow

🩹 a withheld trend slope says why instead of vanishing

Browse files at this commit

6d123ba5528ffef1fa58b008e5052c3de709474bAhmet Kaan GümüşParent: 37ac68d
  • fix
    • 🩹 a withheld trend slope says why instead of vanishing
Show full message
fix: 🩹 a withheld trend slope says why instead of vanishing

ZEKA now suppresses `slope_per_30d` when the mark series spans fewer than the
regression window and sends a reason with it — but the drawer only rendered
`trend.reason` inside the unavailable fallback, so an *available* trend with a
null slope silently lost its "30 günlük değişim" row with no explanation. The
reason is rendered in the row's place, as a note line in the same style as the
other honest-absence lines; the row itself stays absent (no 0, no "—").

Tests: an available trend with `slope_per_30d: null` + reason renders the
sentence and no scoring row; an available trend with a slope renders the row
("+3,4 puan / 30 gün") and no reason line. 9/9 pass; deleting the note turns
exactly the first one red.
src/components/insights/insight-detail.test.tsxmodified+61 -0
@@ -2,6 +2,7 @@ import { cleanup, fireEvent, render, screen } from "@solidjs/testing-library";
22 import { afterEach, describe, expect, it } from "vitest";
33 import type { StudentInsight } from "@/api/client";
44 import { InsightDetail } from "@/components/insights/insight-detail";
5+import { isRecord, type UnknownRecord } from "@/lib/is-record";
56 import { PreferencesProvider } from "@/stores/preferences-context";
67
78 /**
@@ -270,6 +271,25 @@ const renderDrawer = (props: { mode?: "full" | "cards" } = {}) =>
270271 </PreferencesProvider>
271272 ));
272273
274+const renderInsight = (value: StudentInsight) =>
275+ render(() => (
276+ <PreferencesProvider>
277+ <InsightDetail insight={value} />
278+ </PreferencesProvider>
279+ ));
280+
281+/** The fixture's single course with its `trend` member swapped. */
282+const marksWith = (trend: UnknownRecord): StudentInsight => {
283+ const summary = insight.summary ?? { confidence: "none", computed_at: NOW, retain_until: NOW + WEEK };
284+ const marks = isRecord(summary.marks) ? summary.marks : {};
285+ const courses = isRecord(marks.courses) ? marks.courses : {};
286+ const course = isRecord(courses[COURSE_ID]) ? courses[COURSE_ID] : {};
287+ return {
288+ ...insight,
289+ summary: { ...summary, marks: { ...marks, courses: { ...courses, [COURSE_ID]: { ...course, trend } } } },
290+ };
291+};
292+
273293 describe("InsightDetail", () => {
274294 afterEach(cleanup);
275295
@@ -393,6 +413,47 @@ describe("InsightDetail", () => {
393413 expect(screen.getByTestId("insight-technical").textContent).toContain("dikkat_tuzagi");
394414 });
395415
416+ it("explains a withheld slope instead of dropping its row silently", () => {
417+ const reason = "not dizisi 7 günden kısa olduğu için eğim hesaplanmadı";
418+ renderInsight(
419+ marksWith({
420+ available: true,
421+ reason,
422+ n: 8,
423+ slope_per_30d: null,
424+ recent_mean: 70,
425+ previous_mean: 66,
426+ delta: 4,
427+ dropped: false,
428+ rising: false,
429+ }),
430+ );
431+ const human = screen.getByTestId("insight-human").textContent ?? "";
432+
433+ expect(human).toContain(reason);
434+ expect(human).not.toContain("/ 30 gün");
435+ });
436+
437+ it("shows the slope row when the trend computed one", () => {
438+ renderInsight(
439+ marksWith({
440+ available: true,
441+ reason: null,
442+ n: 8,
443+ slope_per_30d: 3.4,
444+ recent_mean: 70,
445+ previous_mean: 66,
446+ delta: 4,
447+ dropped: false,
448+ rising: false,
449+ }),
450+ );
451+ const human = screen.getByTestId("insight-human").textContent ?? "";
452+
453+ expect(human).toContain("+3,4 puan / 30 gün");
454+ expect(human).not.toContain("eğim hesaplanmadı");
455+ });
456+
396457 it("keeps the cards-only mode free of the drawer's full-view sections", () => {
397458 renderDrawer({ mode: "cards" });
398459 const human = screen.getByTestId("insight-human").textContent ?? "";
src/components/insights/insight-module-views.tsxmodified+6 -0
@@ -341,6 +341,12 @@ function MarksCourseCard(props: { id: string; statRaw: unknown; courseTitle: Cou
341341 />
342342 </Show>
343343 </dl>
344+ {/* An available trend can still withhold its slope (a series shorter
345+ than the regression window). The row would vanish silently; the
346+ service's reason is rendered in its place instead. */}
347+ <Show when={num(trend().slope_per_30d) === null && str(trend().reason)}>
348+ {(reason) => <NoteLine label={detailText("marks.trendSlope")}>{reason()}</NoteLine>}
349+ </Show>
344350 </Show>
345351 </div>
346352 </div>