mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 16:12:11 +00:00
refactor(charts): decide in the overlays hook where a chart's labels go
The narrow-chart rule lived in HealthChart's body and grew it past its size baseline. The overlays hook, which already sizes the room beside the plot, now takes the chart's width, keeps no room on a narrow chart and marks each target zone whose label sits inside it; the x axis helper works out its own tick layout. The tiered series unit test mocks the lookup for readings older than the rollups and covers the head the read puts in front of them.
This commit is contained in:
1 parent
f4cb15d823
commit
444ff66086
7 files changed
+98
-34
No files matched your search
@@ -12,6 +12,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
findMany: vi.fn(),
|
||||
findFirst: vi.fn(),
|
||||
queryRaw: vi.fn(),
|
||||
readTieredRollupSeries: vi.fn(),
|
||||
}));
|
||||
@@ -19,6 +20,7 @@ const mocks = vi.hoisted(() => ({
|
||||
vi.mock("@/lib/db", () => ({
|
||||
prisma: {
|
||||
measurementRollup: { findMany: mocks.findMany },
|
||||
measurement: { findFirst: mocks.findFirst },
|
||||
$queryRaw: mocks.queryRaw,
|
||||
},
|
||||
}));
|
||||
@@ -33,6 +35,9 @@ const DAY_MS = 86_400_000;
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.findMany.mockReset();
|
||||
mocks.findFirst.mockReset();
|
||||
// No reading older than the rollups unless a case says so.
|
||||
mocks.findFirst.mockResolvedValue(null);
|
||||
mocks.queryRaw.mockReset();
|
||||
mocks.readTieredRollupSeries.mockReset();
|
||||
// The daily path folds live, one row per local day.
|
||||
@@ -75,6 +80,7 @@ describe("readDailySeries — long-range tier step-up", () => {
|
||||
mocks.readTieredRollupSeries.mockResolvedValueOnce({
|
||||
granularity: "MONTH",
|
||||
rows: tieredRows,
|
||||
firstDay: new Date("2017-01-01T00:00:00.000Z"),
|
||||
});
|
||||
|
||||
const result = await readDailySeries({
|
||||
@@ -98,6 +104,51 @@ describe("readDailySeries — long-range tier step-up", () => {
|
||||
expect(mocks.queryRaw).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("folds the readings older than the rollups live and puts them first", async () => {
|
||||
const to = new Date("2026-06-03T12:00:00.000Z");
|
||||
const from = new Date(to.getTime() - 3650 * DAY_MS);
|
||||
mocks.readTieredRollupSeries.mockResolvedValueOnce({
|
||||
granularity: "MONTH",
|
||||
rows: [
|
||||
{
|
||||
type: "WEIGHT",
|
||||
value: 79,
|
||||
measuredAt: "2021-07-01T12:00:00.000Z",
|
||||
count: 30,
|
||||
},
|
||||
],
|
||||
firstDay: new Date("2021-07-04T00:00:00.000Z"),
|
||||
});
|
||||
mocks.findFirst.mockResolvedValueOnce({ id: "older" });
|
||||
mocks.queryRaw.mockResolvedValueOnce([
|
||||
{
|
||||
type: "WEIGHT",
|
||||
bucket_start: new Date("2018-03-01T00:00:00.000Z"),
|
||||
avg: 84,
|
||||
cnt: 4,
|
||||
min_value: 83,
|
||||
max_value: 85,
|
||||
},
|
||||
]);
|
||||
|
||||
const result = await readDailySeries({
|
||||
userId: "u",
|
||||
type: "WEIGHT",
|
||||
from,
|
||||
to,
|
||||
priorityJson: null,
|
||||
timeZone: TZ,
|
||||
});
|
||||
|
||||
// The head reads before the first tier bucket (July 2021) only.
|
||||
expect(mocks.findFirst.mock.calls[0][0].where.measuredAt.lt).toEqual(
|
||||
new Date("2021-07-01T00:00:00.000Z"),
|
||||
);
|
||||
expect(result).toHaveLength(2);
|
||||
expect(result[0].value).toBe(84);
|
||||
expect(result[1].measuredAt).toBe("2021-07-01T12:00:00.000Z");
|
||||
});
|
||||
|
||||
it("falls through to the daily path on a tiered coverage miss (no silent empty)", async () => {
|
||||
const to = new Date("2026-06-21T00:00:00.000Z");
|
||||
const from = new Date(to.getTime() - 3650 * DAY_MS);
|
||||
|
||||
Reference in new issue
Block a user