🩹 a withheld trend slope says why instead of vanishing
Browse files at this commit6d123ba5528ffef1fa58b008e5052c3de709474bParent: 37ac68d- fix
- 🩹 a withheld trend slope says why instead of vanishing
2 changed files +67 -0
- src/components/insights/insight-detail.test.tsx +61 -0
- src/components/insights/insight-module-views.tsx +6 -0
src/components/insights/insight-detail.test.tsxmodified+61 -0
| @@ -2,6 +2,7 @@ import { cleanup, fireEvent, render, screen } from "@solidjs/testing-library"; | |||
| 2 | import { afterEach, describe, expect, it } from "vitest"; | 2 | import { afterEach, describe, expect, it } from "vitest"; |
| 3 | import type { StudentInsight } from "@/api/client"; | 3 | import type { StudentInsight } from "@/api/client"; |
| 4 | import { InsightDetail } from "@/components/insights/insight-detail"; | 4 | import { InsightDetail } from "@/components/insights/insight-detail"; |
| 5 | +import { isRecord, type UnknownRecord } from "@/lib/is-record"; | ||
| 5 | import { PreferencesProvider } from "@/stores/preferences-context"; | 6 | import { PreferencesProvider } from "@/stores/preferences-context"; |
| 6 | 7 | ||
| 7 | /** | 8 | /** |
| @@ -270,6 +271,25 @@ const renderDrawer = (props: { mode?: "full" | "cards" } = {}) => | |||
| 270 | </PreferencesProvider> | 271 | </PreferencesProvider> |
| 271 | )); | 272 | )); |
| 272 | 273 | ||
| 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 | + | ||
| 273 | describe("InsightDetail", () => { | 293 | describe("InsightDetail", () => { |
| 274 | afterEach(cleanup); | 294 | afterEach(cleanup); |
| 275 | 295 | ||
| @@ -393,6 +413,47 @@ describe("InsightDetail", () => { | |||
| 393 | expect(screen.getByTestId("insight-technical").textContent).toContain("dikkat_tuzagi"); | 413 | expect(screen.getByTestId("insight-technical").textContent).toContain("dikkat_tuzagi"); |
| 394 | }); | 414 | }); |
| 395 | 415 | ||
| 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 | + | ||
| 396 | it("keeps the cards-only mode free of the drawer's full-view sections", () => { | 457 | it("keeps the cards-only mode free of the drawer's full-view sections", () => { |
| 397 | renderDrawer({ mode: "cards" }); | 458 | renderDrawer({ mode: "cards" }); |
| 398 | const human = screen.getByTestId("insight-human").textContent ?? ""; | 459 | 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 | |||
| 341 | /> | 341 | /> |
| 342 | </Show> | 342 | </Show> |
| 343 | </dl> | 343 | </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> | ||
| 344 | </Show> | 350 | </Show> |
| 345 | </div> | 351 | </div> |
| 346 | </div> | 352 | </div> |