mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 07:42:23 +00:00
fix(insights): hold the scores strip until the cycle ring is decided
For a cycle-tracking account the strip painted Strain first and swapped it for the cycle ring once the calendar read landed, moving the row under the reader. The ring's decision now reports while it is pending, and the strip keeps its skeleton until then.
This commit is contained in:
1 parent
e49997bf97
commit
a15a148667
3 files changed
+61
-24
No files matched your search
@@ -2,14 +2,20 @@
|
||||
* The scores strip gives the cycle ring a cell only when the ring would draw
|
||||
* a dial. The ring renders nothing without an active cycle, and a cell
|
||||
* reserved for it (with Strain dropped to make room) sat empty in the row.
|
||||
*
|
||||
* The decision waits on the calendar read, so the hook also says when it is
|
||||
* still pending: the strip holds its skeleton until then instead of painting
|
||||
* Strain and swapping it for the ring a moment later.
|
||||
*/
|
||||
import { readFileSync } from "node:fs";
|
||||
import { join } from "node:path";
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { queryKeys } from "@/lib/query-keys";
|
||||
|
||||
import { localYmd, useCycleRingHasDial } from "../use-cycle";
|
||||
import { localYmd, useCycleRingDial } from "../use-cycle";
|
||||
|
||||
function window(): [string, string] {
|
||||
const from = new Date();
|
||||
@@ -20,34 +26,56 @@ function window(): [string, string] {
|
||||
}
|
||||
|
||||
function Probe({ enabled }: { enabled: boolean }) {
|
||||
return <span>{String(useCycleRingHasDial(enabled))}</span>;
|
||||
const { dial, pending } = useCycleRingDial(enabled);
|
||||
return <span>{`${dial}:${pending}`}</span>;
|
||||
}
|
||||
|
||||
function hasDial(verdict: unknown, enabled = true): boolean {
|
||||
function probe(verdict: unknown | undefined, enabled = true): string {
|
||||
const client = new QueryClient({
|
||||
defaultOptions: { queries: { staleTime: Infinity, retry: 0 } },
|
||||
});
|
||||
const [from, to] = window();
|
||||
client.setQueryData(queryKeys.cycleCalendar(from, to), { verdict });
|
||||
if (verdict !== undefined) {
|
||||
client.setQueryData(queryKeys.cycleCalendar(from, to), { verdict });
|
||||
}
|
||||
const html = renderToStaticMarkup(
|
||||
<QueryClientProvider client={client}>
|
||||
<Probe enabled={enabled} />
|
||||
</QueryClientProvider>,
|
||||
);
|
||||
return html === "<span>true</span>";
|
||||
return html.replace(/<\/?span>/g, "");
|
||||
}
|
||||
|
||||
describe("useCycleRingHasDial", () => {
|
||||
it("is true while a cycle is active today", () => {
|
||||
expect(hasDial({ phase: "follicular", dayOfCycle: 6 })).toBe(true);
|
||||
describe("useCycleRingDial", () => {
|
||||
it("has a dial while a cycle is active today", () => {
|
||||
expect(probe({ phase: "follicular", dayOfCycle: 6 })).toBe("true:false");
|
||||
});
|
||||
|
||||
it("is false without an active cycle, so no empty cell is reserved", () => {
|
||||
expect(hasDial({ phase: null, dayOfCycle: null })).toBe(false);
|
||||
expect(hasDial(null)).toBe(false);
|
||||
it("has none without an active cycle, so no empty cell is reserved", () => {
|
||||
expect(probe({ phase: null, dayOfCycle: null })).toBe("false:false");
|
||||
expect(probe(null)).toBe("false:false");
|
||||
});
|
||||
|
||||
it("is false while the cycle surface is hidden", () => {
|
||||
expect(hasDial({ phase: "luteal", dayOfCycle: 20 }, false)).toBe(false);
|
||||
it("has none, and is not pending, while the cycle surface is hidden", () => {
|
||||
expect(probe({ phase: "luteal", dayOfCycle: 20 }, false)).toBe(
|
||||
"false:false",
|
||||
);
|
||||
expect(probe(undefined, false)).toBe("false:false");
|
||||
});
|
||||
|
||||
it("is pending until the calendar read lands", () => {
|
||||
expect(probe(undefined)).toBe("false:true");
|
||||
});
|
||||
});
|
||||
|
||||
describe("the scores strip waits for the ring's decision", () => {
|
||||
it("holds its skeleton while the decision is pending", () => {
|
||||
const source = readFileSync(
|
||||
join(process.cwd(), "src/app/insights/page-client.tsx"),
|
||||
"utf8",
|
||||
);
|
||||
expect(source).toMatch(
|
||||
/isLoading=\{\s*dashboardDerived\.isLoading\s*\|\|\s*cycleRing\.pending\s*\}/,
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user