mirror of
https://github.com/priyanshujain/margin-calendar.git
synced 2026-10-02 19:17:04 +00:00
Keep the hour it is now on the axis
The visible range is drawn from the events in view, and in the evening the events are behind you: the bounds end at six, everything after that is in the trailing strip, and the now line has nowhere to land. The app stops saying where in the day you are, which is most of what it is open for. Same at seven in the morning, from the other end. So when today is one of the columns, the axis takes that one hour in, and everything the widening reached over folds behind it. At half eleven at night the fixture week reads 7am to 8pm as usual, then an "8pm to 11pm" strip, then one 11pm row with the line in it. A row and a strip, not four rows of empty evening. Only the hour itself is opened, so how far the clock has drifted past the last event costs nothing. The pin sits on top of the hysteresis rather than inside it. previous.current still holds what the events and the user asked for, so an hour pinned open tonight cannot accumulate into the bounds the grid remembers tomorrow. One consequence, and it is the only place the axis is allowed to move under you: page to a week that does not contain today and the row goes again, along with the strip it was sitting under. The tick that drives it is an hour long, not a minute, because that is how often the answer changes. It lives in a new useClock alongside the minute tick the now line already had, which moves there out of GridNowLine. Both schedule off the clock rather than off an interval, so a machine that was asleep catches up on the next tick instead of drifting further out every hour. The browser suite has to say what time it is now. The shape of the axis depends on the hour a run happens at, so anything measuring a row height or counting strips pins the clock to the middle of the working day, the same way it already pins the theme and the week start. The three tests that are about the clock ask for half eleven at night, which the fixture leaves empty.
This commit is contained in:
1 parent
3323496a34
commit
67879fd6c3
8 files changed
+223
-32
No files matched your search
@@ -23,8 +23,35 @@ export interface OpenOptions {
|
||||
view?: "day" | "week" | "agenda";
|
||||
/** Extra localStorage entries, written before the app's first script runs. */
|
||||
storage?: Record<string, string>;
|
||||
/** Pins the browser's clock. See `clockAt`. */
|
||||
now?: Date;
|
||||
}
|
||||
|
||||
/**
|
||||
* A fixed instant on the day the suite is being run, at a given hour of the pinned zone.
|
||||
*
|
||||
* The axis takes in the hour it is now, so the shape of the grid depends on when you run the
|
||||
* suite: at eleven at night it carries a row and a strip that it does not carry at eleven in the
|
||||
* morning. A test that measures the axis has to say which of those it means, the same way it says
|
||||
* which theme and which week start it means. The one test that is *about* the clock asks for an
|
||||
* hour the fixture leaves empty; every other one asks for the middle of the working day.
|
||||
*
|
||||
* Asia/Kolkata is UTC+5:30 the whole year round, so the offset can be written out.
|
||||
*/
|
||||
export function clockAt(hour: number, minute = 0): Date {
|
||||
const day = new Intl.DateTimeFormat("en-CA", {
|
||||
timeZone: "Asia/Kolkata",
|
||||
year: "numeric",
|
||||
month: "2-digit",
|
||||
day: "2-digit",
|
||||
}).format(new Date());
|
||||
const pad = (n: number) => String(n).padStart(2, "0");
|
||||
return new Date(`${day}T${pad(hour)}:${pad(minute)}:00+05:30`);
|
||||
}
|
||||
|
||||
/** The middle of the working day: the fixture is busy, and the clock pins nothing extra open. */
|
||||
export const MIDDAY = () => clockAt(11, 30);
|
||||
|
||||
const SEEDED = "__test-seeded";
|
||||
|
||||
/**
|
||||
@@ -56,6 +83,7 @@ export async function openApp(page: Page, options: OpenOptions = {}): Promise<vo
|
||||
{ values: seed, flag: SEEDED },
|
||||
);
|
||||
|
||||
if (options.now) await page.clock.setFixedTime(options.now);
|
||||
await page.goto("/");
|
||||
if ((options.view ?? "week") === "agenda") await agendaReady(page);
|
||||
else await gridReady(page);
|
||||
|
||||
Reference in new issue
Block a user