mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 07:42:23 +00:00
fix(ui): draw no empty frame and say when a read failed
"Since the last visit" was wrapped in a card by the visits section, so the card stayed on screen empty while the window loaded, when it held nothing and when the read failed. The component now owns its card and draws it only with a row; a failed read shows a compact error row. The same shapes elsewhere: the caffeine card and the mood forecast no longer open a loading card that most often collapses, and a failed read on them, the mood tag catalogue, the usual-range strip, the cycle ring and the measurement drill-down now says so with a retry instead of passing for no data. The scores strip keeps the ring's cell on a failed calendar read. The mental-health card no longer draws an empty action slot for a viewer without the right to start. The frame guard now also flags a frame whose only content sits behind a condition. Refs #1241
This commit is contained in:
1 parent
d00281f35a
commit
38c106e358
23 files changed
+816
-193
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
|
||||
@@ -47,9 +47,12 @@ vi.mock("@/lib/api/api-fetch", async () => {
|
||||
};
|
||||
});
|
||||
|
||||
import { dateKeyOfInstant, todayKeyInZone } from "@/components/day/day-url";
|
||||
import type { DayNotableWindowResponse } from "@/lib/day/contract";
|
||||
import { I18nProvider } from "@/lib/i18n/context";
|
||||
import { queryKeys } from "@/lib/query-keys";
|
||||
import type { EncounterDTO } from "@/lib/encounters/dto";
|
||||
import { DEFAULT_TIMEZONE } from "@/lib/tz/format";
|
||||
import { VisitsSection } from "../visits-section";
|
||||
|
||||
function visit(over: Partial<EncounterDTO> & { id: string }): EncounterDTO {
|
||||
@@ -69,10 +72,14 @@ function visit(over: Partial<EncounterDTO> & { id: string }): EncounterDTO {
|
||||
};
|
||||
}
|
||||
|
||||
function render(list: { upcoming: EncounterDTO[]; past: EncounterDTO[] }) {
|
||||
function render(
|
||||
list: { upcoming: EncounterDTO[]; past: EncounterDTO[] },
|
||||
seed?: (queryClient: QueryClient) => void,
|
||||
) {
|
||||
const queryClient = new QueryClient({
|
||||
defaultOptions: { queries: { retry: false } },
|
||||
});
|
||||
seed?.(queryClient);
|
||||
queryClient.setQueryData(
|
||||
queryKeys.encounterList(null, null, undefined, undefined),
|
||||
list,
|
||||
@@ -160,3 +167,120 @@ describe("<VisitsSection>", () => {
|
||||
expect(html).toContain('href="/checkups/practitioners"');
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* #1241 — "since the last visit" under the next appointment. The caller used
|
||||
* to wrap it in a card, so whenever it had nothing to list (still loading, a
|
||||
* quiet window, a failed read) an empty bordered card sat under the visit.
|
||||
* It now draws its own card, and only once it has a row.
|
||||
*/
|
||||
describe("<VisitsSection> since the last visit", () => {
|
||||
const next = visit({
|
||||
id: "next",
|
||||
status: "PLANNED",
|
||||
occurredAt: "2026-09-20T09:00:00.000Z",
|
||||
});
|
||||
const last = visit({ id: "last", occurredAt: "2026-08-01T09:00:00.000Z" });
|
||||
|
||||
/** Cards painted inside the upcoming list. */
|
||||
function upcomingCards(html: string): number {
|
||||
const start = html.indexOf('data-slot="visits-upcoming"');
|
||||
const end = html.indexOf('data-slot="visits-past"');
|
||||
expect(start).toBeGreaterThan(-1);
|
||||
return html.slice(start, end).split('data-slot="card"').length - 1;
|
||||
}
|
||||
|
||||
function seedWindow(window: DayNotableWindowResponse | null) {
|
||||
return (queryClient: QueryClient) => {
|
||||
if (!window) return;
|
||||
const tz = DEFAULT_TIMEZONE;
|
||||
queryClient.setQueryData(
|
||||
queryKeys.dayNotable(
|
||||
dateKeyOfInstant(last.occurredAt, tz),
|
||||
todayKeyInZone(tz),
|
||||
),
|
||||
window,
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
const emptyWindow = {
|
||||
observations: [],
|
||||
changes: [],
|
||||
} as unknown as DayNotableWindowResponse;
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers({ toFake: ["Date"] });
|
||||
vi.setSystemTime(new Date("2026-09-15T12:00:00.000Z"));
|
||||
});
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("draws no card while the window is still loading", () => {
|
||||
const withLast = render({ upcoming: [next], past: [last] });
|
||||
const withoutLast = render({ upcoming: [next], past: [] });
|
||||
expect(withLast).not.toContain('data-slot="since-last-visit"');
|
||||
expect(upcomingCards(withLast)).toBe(upcomingCards(withoutLast));
|
||||
});
|
||||
|
||||
it("draws no card when the window holds nothing worth listing", () => {
|
||||
const html = render(
|
||||
{ upcoming: [next], past: [last] },
|
||||
seedWindow(emptyWindow),
|
||||
);
|
||||
const baseline = render({ upcoming: [next], past: [] });
|
||||
expect(html).not.toContain('data-slot="since-last-visit"');
|
||||
expect(upcomingCards(html)).toBe(upcomingCards(baseline));
|
||||
});
|
||||
|
||||
it("says a failed read failed, rather than passing it off as a quiet window", () => {
|
||||
const html = render({ upcoming: [next], past: [last] }, (queryClient) => {
|
||||
const tz = DEFAULT_TIMEZONE;
|
||||
const queryKey = queryKeys.dayNotable(
|
||||
dateKeyOfInstant(last.occurredAt, tz),
|
||||
todayKeyInZone(tz),
|
||||
);
|
||||
// The state the section sees once the real read has given up: a mount
|
||||
// does not retry it.
|
||||
queryClient.setQueryDefaults(queryKey, { retryOnMount: false });
|
||||
queryClient
|
||||
.getQueryCache()
|
||||
.build(queryClient, { queryKey })
|
||||
.setState({
|
||||
status: "error",
|
||||
error: new Error("window read failed"),
|
||||
fetchStatus: "idle",
|
||||
});
|
||||
});
|
||||
const baseline = render({ upcoming: [next], past: [] });
|
||||
expect(html).toContain('data-slot="since-last-visit-error"');
|
||||
expect(html).toContain('role="alert"');
|
||||
expect(html).not.toContain('data-slot="since-last-visit"');
|
||||
expect(upcomingCards(html)).toBe(upcomingCards(baseline));
|
||||
});
|
||||
|
||||
it("draws one card with the rows once there is something to list", () => {
|
||||
const html = render(
|
||||
{ upcoming: [next], past: [last] },
|
||||
seedWindow({
|
||||
...emptyWindow,
|
||||
changes: [
|
||||
{
|
||||
date: "2026-08-03",
|
||||
kind: "doseChange",
|
||||
section: "medications",
|
||||
id: "d1",
|
||||
title: "Example 5 mg",
|
||||
count: 1,
|
||||
href: null,
|
||||
},
|
||||
],
|
||||
} as unknown as DayNotableWindowResponse),
|
||||
);
|
||||
const baseline = render({ upcoming: [next], past: [] });
|
||||
expect(html).toContain('data-slot="since-last-visit"');
|
||||
expect(html).toContain('data-slot="since-last-visit-row"');
|
||||
expect(upcomingCards(html)).toBe(upcomingCards(baseline) + 1);
|
||||
});
|
||||
});
|
||||
@@ -18,7 +18,6 @@ import { Fragment, useState } from "react";
|
||||
|
||||
import { SinceLastVisit } from "@/components/day/since-last-visit";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent } from "@/components/ui/card";
|
||||
import { EmptyState } from "@/components/ui/empty-state";
|
||||
import { PageHeader } from "@/components/ui/page-header";
|
||||
import { QueryErrorCard } from "@/components/ui/query-error-card";
|
||||
@@ -142,13 +141,11 @@ export function VisitsSection({ enabled = true }: { enabled?: boolean }) {
|
||||
onOpen={canManageVisits ? openSheet : undefined}
|
||||
/>
|
||||
{/* v1.42 — the next appointment carries what happened
|
||||
since the last one, each date opening its day. */}
|
||||
since the last one, each date opening its day. The
|
||||
component draws its own card, and none when it has
|
||||
nothing to list. */}
|
||||
{i === 0 && lastDone ? (
|
||||
<Card className="gap-3 py-3 md:gap-3 md:py-4">
|
||||
<CardContent>
|
||||
<SinceLastVisit next={encounter} last={lastDone} />
|
||||
</CardContent>
|
||||
</Card>
|
||||
<SinceLastVisit next={encounter} last={lastDone} />
|
||||
) : null}
|
||||
</Fragment>
|
||||
))}
|
||||
|
||||
Reference in new issue
Block a user