From 6d123ba5528ffef1fa58b008e5052c3de709474b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Fri, 18 Sep 2026 10:27:33 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=A9=B9=20a=20withheld=20trend=20sl?= =?UTF-8?q?ope=20says=20why=20instead=20of=20vanishing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../insights/insight-detail.test.tsx | 61 +++++++++++++++++++ .../insights/insight-module-views.tsx | 6 ++ 2 files changed, 67 insertions(+) diff --git a/src/components/insights/insight-detail.test.tsx b/src/components/insights/insight-detail.test.tsx index bd093eb..37de571 100644 --- a/src/components/insights/insight-detail.test.tsx +++ b/src/components/insights/insight-detail.test.tsx @@ -2,6 +2,7 @@ import { cleanup, fireEvent, render, screen } from "@solidjs/testing-library"; import { afterEach, describe, expect, it } from "vitest"; import type { StudentInsight } from "@/api/client"; import { InsightDetail } from "@/components/insights/insight-detail"; +import { isRecord, type UnknownRecord } from "@/lib/is-record"; import { PreferencesProvider } from "@/stores/preferences-context"; /** @@ -270,6 +271,25 @@ const renderDrawer = (props: { mode?: "full" | "cards" } = {}) => )); +const renderInsight = (value: StudentInsight) => + render(() => ( + + + + )); + +/** The fixture's single course with its `trend` member swapped. */ +const marksWith = (trend: UnknownRecord): StudentInsight => { + const summary = insight.summary ?? { confidence: "none", computed_at: NOW, retain_until: NOW + WEEK }; + const marks = isRecord(summary.marks) ? summary.marks : {}; + const courses = isRecord(marks.courses) ? marks.courses : {}; + const course = isRecord(courses[COURSE_ID]) ? courses[COURSE_ID] : {}; + return { + ...insight, + summary: { ...summary, marks: { ...marks, courses: { ...courses, [COURSE_ID]: { ...course, trend } } } }, + }; +}; + describe("InsightDetail", () => { afterEach(cleanup); @@ -393,6 +413,47 @@ describe("InsightDetail", () => { expect(screen.getByTestId("insight-technical").textContent).toContain("dikkat_tuzagi"); }); + it("explains a withheld slope instead of dropping its row silently", () => { + const reason = "not dizisi 7 günden kısa olduğu için eğim hesaplanmadı"; + renderInsight( + marksWith({ + available: true, + reason, + n: 8, + slope_per_30d: null, + recent_mean: 70, + previous_mean: 66, + delta: 4, + dropped: false, + rising: false, + }), + ); + const human = screen.getByTestId("insight-human").textContent ?? ""; + + expect(human).toContain(reason); + expect(human).not.toContain("/ 30 gün"); + }); + + it("shows the slope row when the trend computed one", () => { + renderInsight( + marksWith({ + available: true, + reason: null, + n: 8, + slope_per_30d: 3.4, + recent_mean: 70, + previous_mean: 66, + delta: 4, + dropped: false, + rising: false, + }), + ); + const human = screen.getByTestId("insight-human").textContent ?? ""; + + expect(human).toContain("+3,4 puan / 30 gün"); + expect(human).not.toContain("eğim hesaplanmadı"); + }); + it("keeps the cards-only mode free of the drawer's full-view sections", () => { renderDrawer({ mode: "cards" }); const human = screen.getByTestId("insight-human").textContent ?? ""; diff --git a/src/components/insights/insight-module-views.tsx b/src/components/insights/insight-module-views.tsx index 47353f2..fd380e9 100644 --- a/src/components/insights/insight-module-views.tsx +++ b/src/components/insights/insight-module-views.tsx @@ -341,6 +341,12 @@ function MarksCourseCard(props: { id: string; statRaw: unknown; courseTitle: Cou /> + {/* An available trend can still withhold its slope (a series shorter + than the regression window). The row would vanish silently; the + service's reason is rendered in its place instead. */} + + {(reason) => {reason()}} +