Extensive UI changes
All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 28s

This commit is contained in:
Elijah 2026-10-20 19:46:08 -07:00
parent 6fc0a01c56
commit ddea7fc512
16 changed files with 675 additions and 493 deletions

67
tests/entry.test.js Normal file
View file

@ -0,0 +1,67 @@
import test from "node:test";
import assert from "node:assert/strict";
import { suggestedMeal, localTime, nextFoodName } from "../shared/entry.js";
import { recordSchema, emptyNutrients } from "../shared/domain.js";
test("meal suggestions follow local time at each meal boundary, including overnight snacks", () => {
for (const [hour, expected] of [
[0, "Snacks"],
[4, "Snacks"],
[5, "Breakfast"],
[7, "Breakfast"],
[10, "Breakfast"],
[11, "Lunch"],
[15, "Lunch"],
[16, "Dinner"],
[21, "Dinner"],
[22, "Snacks"],
[23, "Snacks"],
]) {
assert.equal(suggestedMeal(new Date(2026, 9, 20, hour, 28)), expected);
}
assert.equal(localTime(new Date(2026, 9, 20, 6, 28)), "06:28");
assert.equal(localTime(new Date(2026, 9, 20, 0, 5)), "00:05");
});
test("unnamed entries advance the category sequence without collisions after removals", () => {
assert.equal(nextFoodName("Dinner", []), "Dinner 1");
assert.equal(
nextFoodName("Dinner", ["Dinner 1", "Dinner 3", "Pasta", "Lunch 8"]),
"Dinner 4",
);
assert.equal(
nextFoodName("Breakfast", ["Breakfast 1", "Breakfast toast"]),
"Breakfast 2",
);
assert.equal(nextFoodName("Food", ["Food 1"]), "Food 2");
});
test("entry times validate, while legacy records without a time remain compatible", () => {
const entry = {
id: "e1",
type: "entry",
updatedAt: "2026-10-20T12:00:00.000Z",
deleted: false,
data: {
name: "Dinner 1",
date: "2026-10-20",
meal: "Dinner",
quantity: 1,
serving: "1 serving",
nutrients: emptyNutrients(),
},
};
assert.equal(recordSchema.safeParse(entry).success, true);
for (const time of ["00:00", "06:28", "23:59"])
assert.equal(
recordSchema.safeParse({ ...entry, data: { ...entry.data, time } })
.success,
true,
);
for (const time of ["24:00", "12:60", "6:28", "invalid", ""])
assert.equal(
recordSchema.safeParse({ ...entry, data: { ...entry.data, time } })
.success,
false,
);
});

View file

@ -11,6 +11,7 @@ const record = (id, type, data, deleted = false) => ({
});
const entry = {
date: "2026-10-20",
time: "06:28",
meal: "Lunch",
name: "=danger|\nfood",
serving: "1 bowl",
@ -64,6 +65,7 @@ test("JSON export includes fractional serving totals, chosen dates/metrics, kg w
assert.equal(data.pendingChanges, 2);
assert.equal(data.entries.length, 1);
assert.equal(data.entries[0].calories, 300);
assert.equal(data.entries[0].time, "06:28");
assert.equal(data.entries[0].protein, 30);
assert.equal("fat" in data.entries[0], false);
assert.equal(data.weights[0].valueKg, 75);
@ -74,9 +76,11 @@ test("CSV quotes text and guards spreadsheet formula fields; Markdown keeps clea
assert.match(csv, /"'=danger\|\nfood"/);
assert.match(csv, /"'=untrusted"/);
assert.match(csv, /"daily_total"/);
assert.match(csv, /"06:28"/);
const markdown = await capture("markdown");
assert.match(markdown, /\| 2026-10-20 \| 300 \| 30 \|/);
assert.match(markdown, /=danger\/ food/);
assert.match(markdown, /2026-10-20 06:28/);
assert.doesNotMatch(markdown, /2026-10-19/);
});
test("weight-only exports omit food records; excluding weight omits all weigh-ins", async () => {

View file

@ -17,6 +17,16 @@ test("bubble count tracks calories, remains visible at small amounts, and caps o
assert.equal(bubbleCount(2000, 2000, true), MAX_BUBBLES);
assert.equal(bubbleCount(20000, 2000, true), MAX_BUBBLES);
});
test("an 800 calorie meal drops in with 50 percent more bubbles per second", () => {
const world = createBubbleWorld(0, () => 0.5);
const target = bubbleCount(800, 2000, true);
world.setTarget(target);
for (let i = 0; i < 60; i++) world.step();
assert.equal(world.balls.length, 30);
for (let i = 0; i < target * 2 - 60; i++) world.step();
assert.equal(world.balls.length, target);
world.dispose();
});
test("new bubbles enter at the top, fall, collide and stay inside the calorie vessel", () => {
const world = createBubbleWorld(0, () => 0.5);
world.setTarget(8);