Add frontend checks, run from the repo
The server has go test; the frontend had nothing, and the things most likely to break there are the ones hardest to see: the arithmetic behind the charts, a panel lost while shuffling tabs, a label that truncates on a phone none of us owns. There is no browser in this loop, so these are what can be checked without one. They read the real code rather than copying it. The app is one long IIFE with nothing exported, and adding a module system or a build step to make it testable would be a large change in service of a small one — so checks/extract.mjs reads src/app.js, brace-matches the declarations a check asks for, and evaluates them. Rename a function and it throws by name. A check quietly exercising a stale copy of the code would be worse than no check, and that is the failure mode this avoids. calendarGridStart is pulled out of renderCalendar as part of this. It is the one line of the month grid that is easy to get wrong and impossible to notice — a month starting on the week's first day needs no backing up, one starting the day before needs six — so it earns a name and a test. The width figures are estimates, not measurements: layout numbers come out of style.css so they cannot drift, text is sized from per-character advances, and the pass mark demands a few pixels of headroom because the estimate is only good to a few percent. They will catch a sixth tab or a longer label. They will not settle a two-pixel question, and nothing here replaces looking at a phone. No new dependencies: nodejs is already in the devShell for `node --check`, and checks/ sits outside src/ so it is not served with the app.
This commit is contained in:
+12
-2
@@ -4923,6 +4923,17 @@
|
||||
return 1;
|
||||
}
|
||||
|
||||
// The top-left cell of the grid: back up from the 1st to the most recent
|
||||
// `start` weekday, which is nought to six days. Named because it is the one
|
||||
// line of the calendar that is easy to get wrong and impossible to notice —
|
||||
// a month beginning on the week's first day needs no backing up at all, and
|
||||
// one beginning the day before needs six.
|
||||
function calendarGridStart(calMonth, start) {
|
||||
const d = new Date(calMonth);
|
||||
d.setDate(1 - ((calMonth.getDay() - start + 7) % 7));
|
||||
return d;
|
||||
}
|
||||
|
||||
function renderCalendar() {
|
||||
const start = firstDayOfWeek();
|
||||
const selected = ymd(selectedDay());
|
||||
@@ -4939,8 +4950,7 @@
|
||||
}
|
||||
|
||||
// Always six rows, so the panel doesn't change height from month to month.
|
||||
const gridStart = new Date(calMonth);
|
||||
gridStart.setDate(1 - ((calMonth.getDay() - start + 7) % 7));
|
||||
const gridStart = calendarGridStart(calMonth, start);
|
||||
calGrid.innerHTML = "";
|
||||
for (let i = 0; i < 42; i++) {
|
||||
const d = new Date(gridStart);
|
||||
|
||||
Reference in New Issue
Block a user