v1.4.36 — perf, charts, AI payload trim, UX punch

Heavy-aggregate skip on the rollup-fresh + fully-covered path,
daily chart fetches opt into rollup buckets via source=rollup,
Insights extractFeatures swap drops the prompt payload from
double-digit MB to the low hundreds of kB on power-user accounts,
page-level isLoading gate replaced with per-section early-skeleton
paint, trends-row chart slot pinned for CLS, IntakeHistoryListV2
restored on the medication detail page, About card folded into the
Admin Console with an auto-checking update badge, cumulative metric
tiles read the day's running sum, IP-whois fallback surfaces city
+ country when the ASN lookup misses. Migration 0068 adds an
additive users.insights_exclude_metrics column. Unit suite 4354
passing; typecheck + lint clean.
This commit is contained in:
Marc-André Bombeck committed 2026-05-17 13:22:51 +02:00
1 parent 5a3ca330ac
commit 0e2a99f8e7
70 files changed
+4982 -810

No files matched your search

@@ -0,0 +1,147 @@
import { describe, expect, it, vi, beforeEach, afterEach } from "vitest";
import { renderToStaticMarkup } from "react-dom/server";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { I18nProvider } from "@/lib/i18n/context";
import { AboutSection, UpdateBadge } from "../about-section";
/**
* v1.4.36 W4f — AboutSection update-badge contract.
*
* The dedicated "Updates" card with the manual "Check for updates"
* button is gone. The 24 h auto-check still runs on mount and
* surfaces a subtle ArrowUpCircle badge next to the version line
* ONLY when the check returns `{ status: "newer_available", ... }`.
*
* These SSR smoke tests pin the badge presence by seeding the
* react-query cache with a fake version payload (so the version
* line paints synchronously) and exercising the path that decides
* whether the badge mounts. The badge itself owns its own
* `useState`, so its presence is gated on the runCheck branch —
* SSR renders the initial `null` state. The actual badge render
* is therefore covered by the runtime store-set + re-render in
* future Playwright surfaces; here we pin the *baseline* contract
* that the version line + Sources/docs panel still render and
* the legacy manual-check chrome is gone.
*/
function makeClient() {
const client = new QueryClient({
defaultOptions: {
queries: {
retry: false,
staleTime: Number.POSITIVE_INFINITY,
refetchOnMount: false,
},
},
});
// Seed the version query so the section paints inline rather than
// rendering its loader skeleton.
client.setQueryData(["api", "version"], {
version: "1.4.36",
buildSha: "abc1234",
builtAt: "2026-05-17T08:00:00.000Z",
license: "AGPL-3.0",
repository: "https://github.com/MBombeck/HealthLog",
changelog: "https://github.com/MBombeck/HealthLog/blob/main/CHANGELOG.md",
docs: "https://github.com/MBombeck/HealthLog/tree/main/docs",
});
return client;
}
function render(node: React.ReactNode, locale: "en" | "de" = "en") {
const client = makeClient();
return renderToStaticMarkup(
<I18nProvider initialLocale={locale}>
<QueryClientProvider client={client}>{node}</QueryClientProvider>
</I18nProvider>,
);
}
beforeEach(() => {
vi.clearAllMocks();
// Fail the auto-check fetch so the badge stays in its initial
// (no-result) state. This lets the SSR smoke tests assert the
// "no badge" baseline; the badge-visible branch is unit-tested
// separately by toggling `updateResult` via a forced re-render
// in the future Playwright + RTL suite.
vi.stubGlobal(
"fetch",
vi.fn(async () => {
throw new Error("network disabled in tests");
}),
);
});
afterEach(() => {
vi.unstubAllGlobals();
});
describe("<AboutSection> — update badge", () => {
it("renders the version line without a badge by default", () => {
const html = render(<AboutSection />);
expect(html).toContain("v1.4.36");
// No badge — ArrowUpCircle's lucide class name is the unique signal.
expect(html).not.toContain("lucide-arrow-up-circle");
});
it("drops the manual 'Check for updates' button surface entirely", () => {
const html = render(<AboutSection />);
// Pre-v1.4.36 the section carried a "Check for updates" CTA
// alongside a last-checked timestamp. Both are now gone — only
// the 24 h auto-check stays, surfacing through the badge above.
expect(html).not.toContain(">Check for updates<");
expect(html).not.toContain(">Check now<");
expect(html).not.toContain("last-checked-iso");
});
it("preserves the Sources & docs panel", () => {
const html = render(<AboutSection />);
expect(html).toContain("Sources &amp; docs");
});
it("uses a dedicated 'Built' label for the build-time row rather than the gitSha fallback", () => {
const html = render(<AboutSection />);
// Distinct label keeps the dt copy separate from the "Build" gitSha
// header above it; the prior `t('builtAt', { time: '' }).trim()`
// pattern silently leaked the gitSha key as a fallback.
expect(html).toContain(">Built<");
// Only ONE column should ever read "Build" — the gitSha header.
const buildOccurrences = html.match(/>Build</g) ?? [];
expect(buildOccurrences.length).toBe(1);
});
});
describe("<UpdateBadge> — a11y contract", () => {
it("renders an anchor with aria-label, focus-visible ring, and 44 px hit target when a URL is known", () => {
const html = renderToStaticMarkup(
<UpdateBadge
latestTag="v1.4.99"
htmlUrl="https://example.test/releases/v1.4.99"
ariaLabel="A newer version is available: v1.4.99"
/>,
);
expect(html).toContain('aria-label="A newer version is available: v1.4.99"');
expect(html).toContain("min-h-11");
expect(html).toContain("min-w-11");
expect(html).toContain("focus-visible:ring-ring");
expect(html).toContain("focus-visible:ring-2");
expect(html).toContain("focus-visible:ring-offset-2");
expect(html).toContain("text-primary");
expect(html).toContain('href="https://example.test/releases/v1.4.99"');
});
it("falls back to a span with role=img + aria-label when no URL is known", () => {
const html = renderToStaticMarkup(
<UpdateBadge
latestTag="v1.4.99"
htmlUrl={null}
ariaLabel="A newer version is available: v1.4.99"
/>,
);
expect(html).toContain('role="img"');
expect(html).toContain('aria-label="A newer version is available: v1.4.99"');
expect(html).toContain("min-h-11");
expect(html).toContain("min-w-11");
});
});
@@ -132,16 +132,17 @@ describe("settings sections — SSR smoke", () => {
expect(html).not.toContain("onboarding.tour.");
});
it("<AboutSection> renders version + license + check-for-updates button", () => {
it("<AboutSection> renders version + license + sources/docs cards (no Updates panel)", () => {
const html = render(<AboutSection />);
expect(html).toContain("About");
// The new about.* keys resolve. v1.4.3 split the page into three
// titled cards (HealthLog identity, Sources & docs, Updates) and
// shortened the button label from "Check for updates" to "Check now"
// because the surrounding heading already names the section.
expect(html).toContain("Updates");
// v1.4.36 W4f — the dedicated "Updates" card with its manual
// "Check now" button is gone. The 24 h auto-check still runs and
// surfaces a subtle ArrowUpCircle badge next to the version line
// when a newer release is available. The Sources & docs card
// stays put.
expect(html).toContain("Sources &amp; docs");
expect(html).toContain("Check now");
expect(html).not.toContain(">Check now<");
expect(html).not.toContain(">Check for updates<");
expect(html).not.toContain("settings.about.");
});
@@ -198,11 +199,12 @@ describe("settings sections — SSR smoke", () => {
it("<AboutSection> resolves about.* keys in German", () => {
const html = render(<AboutSection />, "de");
// v1.4.3: button label shortened to "Jetzt prüfen" because the
// section heading "Updates" already provides context.
expect(html).toContain("Updates");
expect(html).toContain("Jetzt prüfen");
// v1.4.36 W4f — "Updates" panel + "Jetzt prüfen" button removed;
// the surviving German copy is the section title + the Sources
// & docs heading + the version line.
expect(html).toContain("Über");
expect(html).toContain("Quellen &amp; Dokumentation");
expect(html).not.toContain(">Jetzt prüfen<");
});
it("<ThresholdsSection> renders heading and embeds both editors (v1.4.34 IW-D merge)", () => {