mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-18 08:02:12 +00:00
Covers the day section, the model projection without the travel country and the two correlation channels; the backup and correlation mocks learn the new delegate. Adds the operator page for DAWARICH_PRIVATE_ORIGINS and regenerates the API contract.
64 lines
1.9 KiB
TypeScript
64 lines
1.9 KiB
TypeScript
/**
|
|
* "On the move" renders the server's values as they come and leaves out what
|
|
* the day has no value for: a null is no coverage, never a zero.
|
|
*/
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
import { I18nProvider } from "@/lib/i18n/context";
|
|
|
|
import { DayMovementSection } from "../day-movement";
|
|
|
|
function render(
|
|
movement: Parameters<typeof DayMovementSection>[0]["movement"],
|
|
) {
|
|
return renderToStaticMarkup(
|
|
<I18nProvider initialLocale="en">
|
|
<DayMovementSection movement={movement} />
|
|
</I18nProvider>,
|
|
);
|
|
}
|
|
|
|
const base = {
|
|
source: "dawarich" as const,
|
|
distance: { unit: "km" as const, total: 48.3, driving: 12, train: 0 },
|
|
placesVisited: 4,
|
|
awayFromHomeMinutes: 600,
|
|
travel: { isTravelDay: true, countryCode: "ES" },
|
|
fetchedAt: "2026-06-16T01:20:00.000Z",
|
|
};
|
|
|
|
describe("DayMovementSection", () => {
|
|
it("shows each value the day has", () => {
|
|
const html = render(base);
|
|
expect(html).toContain('data-movement="total"');
|
|
expect(html).toContain("48.3 km");
|
|
expect(html).toContain('data-movement="driving"');
|
|
expect(html).toContain('data-movement="away"');
|
|
expect(html).toContain("Spain");
|
|
// No train that day: no row, rather than "0 km".
|
|
expect(html).not.toContain('data-movement="train"');
|
|
});
|
|
|
|
it("leaves out time away from home without coverage", () => {
|
|
const html = render({
|
|
...base,
|
|
awayFromHomeMinutes: null,
|
|
travel: null,
|
|
});
|
|
expect(html).not.toContain('data-movement="away"');
|
|
expect(html).not.toContain('data-movement="travel"');
|
|
});
|
|
|
|
it("renders nothing when the day has no value at all", () => {
|
|
const html = render({
|
|
...base,
|
|
distance: { unit: "mi", total: null, driving: null, train: null },
|
|
placesVisited: null,
|
|
awayFromHomeMinutes: null,
|
|
travel: null,
|
|
});
|
|
expect(html).toBe("");
|
|
});
|
|
});
|