Polish PWA gestures, transitions and nutrition averages
All checks were successful
Verify and publish Calio container / build-and-push (push) Successful in 32s

This commit is contained in:
Elijah 2026-10-22 09:16:52 -07:00
parent b19de6f9ea
commit 7288e56c02
16 changed files with 1019 additions and 245 deletions

View file

@ -0,0 +1,81 @@
// Development-only browser regression probe. Run on an unlocked localhost preview
// with Runtime.evaluate (awaitPromise: true). It changes navigation and draft input
// only, restores the draft, and never saves or deletes journal records.
(async () => {
const checks = {};
const pause = (ms = 380) => new Promise(resolve => setTimeout(resolve, ms));
const visible = selector => [...document.querySelectorAll(selector)].filter(e => e.getBoundingClientRect().width > 0);
const page = () => document.querySelector('main').getAttribute('aria-label');
const nav = async label => {
visible('.bottom-nav button').find(e => e.textContent.trim() === label).click();
await pause();
};
const swipe = async (selector, dx, dy = 1, cancel = false) => {
const target = visible(selector)[0];
const rect = target.getBoundingClientRect();
const x = Math.max(30, Math.min(innerWidth - 30, rect.x + rect.width / 2));
const y = rect.y + Math.min(rect.height / 2, 90);
const emit = (type, px, py, ended = false) => {
const touch = new Touch({ identifier: 11, target, clientX: px, clientY: py });
target.dispatchEvent(new TouchEvent(type, { bubbles: true, cancelable: true, touches: ended ? [] : [touch], changedTouches: [touch] }));
};
emit('touchstart', x, y);
emit('touchmove', x + dx / 2, y + dy / 2);
emit('touchmove', x + dx, y + dy);
emit(cancel ? 'touchcancel' : 'touchend', x + dx, y + dy, true);
await pause();
};
await nav('Today');
await swipe('.orb', 150);
checks.firstTabDoesNotWrap = page() === 'Today';
await swipe('.orb', -150, 1, true);
checks.cancelDoesNotNavigate = page() === 'Today';
await swipe('.orb', -150);
checks.leftSwipeNavigates = page() === 'My library';
await swipe('.page-heading h1', 4, -160);
checks.verticalScrollDoesNotNavigate = page() === 'My library';
const libraryTabs = visible('.library-controls .segmented button');
libraryTabs.at(-1).click();
await pause();
visible('.trend-controls .segmented button')[1].click();
await pause();
await swipe('.page-heading h1', -150);
checks.nextTabIsWeight = page() === 'Weight';
await swipe('.page-heading h1', 150);
checks.rightSwipeNavigates = page() === 'My library';
checks.libraryStateIsRetained = visible('.library-controls .segmented .active')[0]?.textContent.trim() === 'Trends' && visible('.trend-controls .segmented .active')[0]?.textContent.trim() === 'Month';
await nav('Settings');
const cutoff = document.querySelector('[aria-label="Minimum calories for averages"]');
const original = cutoff.value;
const changeValue = value => {
Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, 'value').set.call(cutoff, value);
cutoff.dispatchEvent(new Event('input', { bubbles: true }));
};
changeValue('987');
await swipe('[aria-label="Minimum calories for averages"]', -150);
checks.inputsDoNotNavigate = page() === 'Settings';
await swipe('.page-heading h1', -150);
checks.lastTabDoesNotWrap = page() === 'Settings';
await nav('Weight');
await nav('Settings');
checks.unsavedPreferencesSurviveNavigation = cutoff.value === '987';
changeValue(original);
visible('.bottom-nav button').find(e => e.textContent.trim() === 'Library').click();
visible('.bottom-nav button').find(e => e.textContent.trim() === 'Weight').click();
await pause();
checks.rapidTapsUseLatestDestination = page() === 'Weight';
await nav('Today');
visible('.bottom-nav .nav-add')[0].click();
await pause();
checks.sheetOpens = Boolean(document.querySelector('dialog[open]'));
await swipe('dialog input[type="date"]', -150);
checks.dialogDoesNotNavigate = page() === 'Today';
visible('dialog .sheet-head button')[0].click();
await pause(20);
checks.sheetHasExitAnimation = Boolean(document.querySelector('dialog.sheet-exiting'));
await pause();
checks.sheetCloses = !document.querySelector('dialog[open]');
checks.scrollLockReleased = document.body.style.overflow === '';
checks.noHorizontalOverflow = document.documentElement.scrollWidth <= innerWidth + 1;
return { pass: Object.values(checks).every(Boolean), checks };
})()

16
tests/navigation.test.js Normal file
View file

@ -0,0 +1,16 @@
import test from "node:test";
import assert from "node:assert/strict";
import { swipeStep } from "../shared/navigation.js";
test("phone swipes accept deliberate travel and short fast flicks in both directions", () => {
assert.equal(swipeStep(-100, 8, 500, 393), 1);
assert.equal(swipeStep(100, -8, 500, 393), -1);
assert.equal(swipeStep(-40, 2, 65, 393), 1);
assert.equal(swipeStep(60, 0, 500, 320), -1);
});
test("scrolling, diagonal travel, slow small movements and jitter never switch tabs", () => {
assert.equal(swipeStep(12, 150, 250, 393), 0);
assert.equal(swipeStep(100, 100, 150, 393), 0);
assert.equal(swipeStep(40, 2, 500, 393), 0);
assert.equal(swipeStep(8, 0, 5, 393), 0);
});

View file

@ -0,0 +1,73 @@
import test from "node:test";
import assert from "node:assert/strict";
import { nutritionSummary } from "../shared/nutrition-trends.js";
import {
defaultSettings,
emptyNutrients,
recordSchema,
} from "../shared/domain.js";
const entry = (date, calories, protein, quantity = 1) => ({
date,
quantity,
nutrients: { ...emptyNutrients(), calories, protein },
});
const dates = ["2026-10-19", "2026-10-20", "2026-10-21", "2026-10-22"];
test("incomplete and empty days do not dilute calorie or macro averages; bars keep raw totals", () => {
const entries = [
entry(dates[0], 1000, 50, 2),
entry(dates[1], 200, 5),
entry(dates[2], 1800, 0),
];
const before = structuredClone(entries);
const stats = nutritionSummary(entries, dates, 1000);
assert.equal(stats.average.calories, 1900);
assert.equal(stats.average.protein, 50); // A real zero macro on a complete day counts.
assert.equal(stats.includedCount, 2);
assert.equal(stats.excludedCount, 1);
assert.equal(stats.days[1].nutrients.calories, 200);
assert.equal(stats.days[1].included, false);
assert.equal(stats.days[3].logged, false);
assert.deepEqual(entries, before);
});
test("cutoff boundary counts; disabling the cutoff includes all logged days, even a zero", () => {
const entries = [entry(dates[0], 1000, 20), entry(dates[1], 0, 10)];
assert.equal(nutritionSummary(entries, dates, 1000).includedCount, 1);
assert.equal(nutritionSummary(entries, dates, 0).average.calories, 500);
assert.equal(nutritionSummary(entries, dates, 0).average.protein, 15);
});
test("no qualifying data yields a finite empty result and dates outside the period stay excluded", () => {
const stats = nutritionSummary(
[entry(dates[0], 200, 2), entry("2025-01-01", 2200, 100)],
dates,
1000,
);
assert.equal(stats.includedCount, 0);
assert.deepEqual(stats.average, emptyNutrients());
});
test("average preference is optional for old journals and rejects invalid synced settings", () => {
const record = {
id: "settings",
type: "settings",
deleted: false,
updatedAt: "2026-10-22T12:00:00.000Z",
data: defaultSettings,
};
assert.equal(recordSchema.safeParse(record).success, true);
for (const cutoff of [0, 1000, 100000])
assert.equal(
recordSchema.safeParse({
...record,
data: { ...defaultSettings, minimumAverageCalories: cutoff },
}).success,
true,
);
for (const cutoff of [-1, Infinity, "1000", 100001])
assert.equal(
recordSchema.safeParse({
...record,
data: { ...defaultSettings, minimumAverageCalories: cutoff },
}).success,
false,
);
});