mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-19 00:12:18 +00:00
feat(timeline): fit the default window to the record
Without a zoom in the URL the window now follows the record: one that starts inside the last three months opens on three months clamped to its first entry (at least four weeks up to today), an older one with entries there opens on three months, an older one without opens on everything, and an empty one keeps the empty state. The choice is made from the first answer before anything is drawn, so the page does not jump between windows.
This commit is contained in:
1 parent
0ff1340ff4
commit
dc86c42bef
7 files changed
+156
-12
No files matched your search
@@ -108,6 +108,28 @@ test("only old data opens on everything, and an empty window offers it", async (
|
||||
await setTimelineModule(page, false);
|
||||
});
|
||||
|
||||
test("a young record opens on three months starting at its first entry", async ({
|
||||
page,
|
||||
}) => {
|
||||
await setTimelineModuleOn(page);
|
||||
// The record starts ten days ago: the window spans the four-week minimum.
|
||||
const day = (offset: number) => {
|
||||
const [y, m, d] = TODAY.split("-").map(Number);
|
||||
return new Date(Date.UTC(y, m - 1, d + offset)).toISOString().slice(0, 10);
|
||||
};
|
||||
await mockTimeline(page, "full", TODAY, { dataFrom: day(-10) });
|
||||
await page.goto("/timeline");
|
||||
await expect(
|
||||
page.locator('[data-slot="timeline-zoom"] [data-value="quarter"]'),
|
||||
).toHaveAttribute("aria-checked", "true", { timeout: 20_000 });
|
||||
await expect(page.locator('[data-slot="timeline-chart"]')).toHaveAttribute(
|
||||
"data-window-from",
|
||||
day(-27),
|
||||
);
|
||||
// The next test starts from the module switched off.
|
||||
await setTimelineModule(page, false);
|
||||
});
|
||||
|
||||
test("switching it on opens the readiness inventory, which leads to the timeline", async ({
|
||||
page,
|
||||
}) => {
|
||||
|
||||
@@ -826,12 +826,15 @@ export interface TimelineMockLog {
|
||||
* `onlyOld`: the record's entries all lie before the last year, so a
|
||||
* quarter or year window answers empty (with the record's `dataFrom`) and
|
||||
* only everything, or a chosen range, carries them.
|
||||
*
|
||||
* `dataFrom`: the record's first entry as the answers name it, to stand in
|
||||
* for a young record.
|
||||
*/
|
||||
export async function mockTimeline(
|
||||
page: Page,
|
||||
state: "full" | "ready",
|
||||
today: string,
|
||||
options: { onlyOld?: boolean } = {},
|
||||
options: { onlyOld?: boolean; dataFrom?: string } = {},
|
||||
): Promise<TimelineMockLog> {
|
||||
const log: TimelineMockLog = { timelineQueries: [], lifeEventPosts: [] };
|
||||
await page.route(/\/api\/timeline\/readiness(\?|$)/, (route) =>
|
||||
@@ -848,7 +851,8 @@ export async function mockTimeline(
|
||||
const from = url.searchParams.get("from");
|
||||
const to = url.searchParams.get("to");
|
||||
const bucket = bucketFor(zoom, from, to);
|
||||
const dataFrom = state === "full" ? "2019-01-01" : "2024-05-01";
|
||||
const dataFrom =
|
||||
options.dataFrom ?? (state === "full" ? "2019-01-01" : "2024-05-01");
|
||||
if (options.onlyOld && (zoom === "quarter" || zoom === "year")) {
|
||||
return json(route, 200, {
|
||||
...body,
|
||||
@@ -870,7 +874,11 @@ export async function mockTimeline(
|
||||
...body,
|
||||
zoom,
|
||||
bucket,
|
||||
...(chosen ? { range: { from, to, dataFrom } } : {}),
|
||||
...(chosen
|
||||
? { range: { from, to, dataFrom } }
|
||||
: options.dataFrom
|
||||
? { range: { ...body.range, dataFrom } }
|
||||
: {}),
|
||||
// Any other value the menu offers answers a flat line of its own.
|
||||
series: values.map(
|
||||
(key) =>
|
||||
|
||||
Reference in new issue
Block a user