Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 53 additions & 2 deletions apps/web/e2e/keyboard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ test("S sets status on the focused task, optimistically", async ({ page }) => {
test("S on a selection edits every selected task; mod+Z undoes them as one step", async ({ page }) => {
await open(page);
const calls = await stubWrites(page, workspaceId);
for (const _ of [1, 2, 3]) {
for (let i = 0; i < 3; i++) {
await page.keyboard.press("j");
await page.keyboard.press("x");
}
Expand Down Expand Up @@ -260,7 +260,8 @@ test("P, E, Shift+D, Shift+C edit priority, estimate, due date, and cycle", asyn
{ F_ktarget: { type: "date", date: "2026-12-24" } },
{ F_ksprint: { type: "iteration", iterationId: "k-it2" } },
]);
await expect(row(page, 1)).toContainText("2026-12-24");
await expect(row(page, 1).locator("time")).toHaveAttribute("datetime", "2026-12-24");
await expect(row(page, 1)).toContainText("Dec 24");
});

test("mod+Shift+X closes and reopens the focused task", async ({ page }) => {
Expand Down Expand Up @@ -355,6 +356,55 @@ test("keys typed in a field stay in the field", async ({ page }) => {
await expect(page.getByRole("dialog")).toBeVisible();
});

test("keys work on every workspace page, and the store survives moving between pages", async ({ page }) => {
await open(page);
// Focus lives only in the client store: if it survives the round trip, so did the store.
await page.keyboard.press("j");
await page.keyboard.press("j");
let documents = 0;
page.on("request", (r) => {
if (r.isNavigationRequest()) documents++;
});
await page.getByRole("navigation", { name: "Workspace" }).getByRole("link", { name: "Members" }).click();
await expect(page).toHaveURL(new RegExp(`/w/${workspaceId}/members$`));
await page.keyboard.press("?");
await expect(page.getByTestId("shortcut-sheet")).toBeVisible();
await page.keyboard.press("Escape");
await page.keyboard.press("ControlOrMeta+k");
await page.getByRole("dialog").getByRole("combobox").fill("Key task 5");
await page.keyboard.press("Enter");
await expect(page.getByTestId("peek-panel").getByRole("heading", { name: "Key task 5" })).toBeVisible();
await page.keyboard.press("Escape");
// Back to tasks: the same store, so the focus set from the menu on the Members page (task 5)
// is still there; no page load on the way.
await page.getByRole("navigation", { name: "Workspace" }).getByRole("link", { name: "Tasks" }).click();
await expect(page.getByTestId("task-row")).toHaveCount(N);
expect(await focusedId(page)).toBe("PVTI_kb5");
expect(documents).toBe(0);
await expect(page.getByTestId("sync-status")).toContainText("Synced");
});

test("the panel and the new-task dialog say where an edit goes", async ({ page }) => {
await open(page);
await page.keyboard.press("j");
await page.keyboard.press(" ");
// This owner has not linked GitHub: the app writes, with their name.
await expect(page.getByTestId("peek-panel").getByTestId("write-path")).toHaveText("Edits save to GitHub through the Gitwork app, signed with your name.");
await page.keyboard.press("Escape");
await page.keyboard.press("c");
await expect(page.getByRole("dialog").getByTestId("write-path")).toBeVisible();
});

test("dark mode follows the system setting", async ({ browser }) => {
const ctx = await browser.newContext({ storageState: ".data/keys-owner.json", colorScheme: "dark" });
const page = await ctx.newPage();
await page.goto(`/w/${workspaceId}`);
await expect(page.locator("html")).toHaveClass(/\bdark\b/);
await page.emulateMedia({ colorScheme: "light" });
await expect(page.locator("html")).not.toHaveClass(/\bdark\b/);
await ctx.close();
});

test.describe("as Read Only", () => {
test.use({ storageState: ".data/keys-reader.json" });

Expand All @@ -371,6 +421,7 @@ test.describe("as Read Only", () => {
await expect(page.getByRole("dialog")).toHaveCount(0);
await page.keyboard.press(" ");
await expect(page.getByTestId("peek-panel").getByRole("heading", { name: "Key task 1" })).toBeVisible();
await expect(page.getByTestId("write-path")).toHaveCount(0);
expect(writes).toBe(0);
});
});
Expand Down
120 changes: 94 additions & 26 deletions apps/web/e2e/speed.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import { emailCount, signInCode } from "./outbox";

const TASKS = 2_000;
/** Script time for one view switch, measured in the page. Generous for CI machines; local runs are far lower. */
const SWITCH_BUDGET_MS = Number(process.env.SWITCH_BUDGET_MS ?? 400);
const SWITCH_BUDGET_MS = Number(process.env.SWITCH_BUDGET_MS ?? 150);
/** One J press on a 2,000-row list. Only two rows may re-render. */
const FOCUS_BUDGET_MS = Number(process.env.FOCUS_BUDGET_MS ?? 16);

async function signIn(page: Page, email: string) {
const before = emailCount(email);
Expand Down Expand Up @@ -135,15 +137,15 @@ function watchRequests(page: Page) {
}

/**
* Clicks a view button and returns the time until the new view's `count` items are in the DOM.
* Clicks a view button and returns the time until the new view's first item is in the DOM.
* React commits in a microtask after the click, so the clock stops on the DOM, not on click().
*/
async function switchView(page: Page, label: string, testId: string, count: number): Promise<number> {
async function switchView(page: Page, label: string, testId: string): Promise<number> {
return page.evaluate(
({ name, testId, count }) =>
({ name, testId }) =>
new Promise<number>((resolve) => {
const button = [...document.querySelectorAll<HTMLButtonElement>('nav[aria-label="Views"] button')].find((b) => b.textContent === name)!;
const done = () => document.querySelectorAll(`[data-testid="${testId}"]`).length === count;
const done = () => document.querySelector(`[data-testid="${testId}"]`) !== null;
const t0 = performance.now();
const observer = new MutationObserver(() => {
if (!done()) return;
Expand All @@ -153,30 +155,57 @@ async function switchView(page: Page, label: string, testId: string, count: numb
observer.observe(document.body, { childList: true, subtree: true });
button.click();
}),
{ name: label, testId, count },
{ name: label, testId },
);
}

test("the /sync payload at 2,000 tasks (measured for decision 033)", async ({ page }) => {
await page.goto(`/w/${workspaceId}`);
const t0 = Date.now();
const res = await page.request.get(`/api/v1/workspaces/${workspaceId}/sync`);
const ms = Date.now() - t0;
const bytes = (await res.body()).length;
const etag = res.headers()["etag"]!;
const t1 = Date.now();
const again = await page.request.get(`/api/v1/workspaces/${workspaceId}/sync`, { headers: { "if-none-match": etag } });
const ms304 = Date.now() - t1;
console.log(`[speed] /sync 200: ${(bytes / 1024).toFixed(0)} KiB uncompressed in ${ms} ms; 304 in ${ms304} ms`);
expect(again.status()).toBe(304);
});

test("the list renders only rows near the viewport, and J reaches rows far below", async ({ page }) => {
await page.goto(`/w/${workspaceId}?view=list`);
await expect(page.getByTestId("task-row").first()).toBeVisible();
const rendered = await page.getByTestId("task-row").count();
console.log(`[speed] list rows in the DOM: ${rendered} of ${TASKS}`);
expect(rendered).toBeLessThan(150);
// The Todo group holds every third task; 100 J presses go far past the first screen.
for (let i = 0; i < 100; i++) await page.keyboard.press("j");
const focused = page.locator('[data-focused="true"]');
await expect(focused).toBeInViewport();
expect(await focused.getAttribute("data-task-id")).toBe("PVTI_big300"); // the 100th Todo task: 3, 6, …, 300
});

test("the first poll is a 304: the page and /sync agree", async ({ page }) => {
await page.goto(`/w/${workspaceId}`);
await expect(page.getByTestId("task-row")).toHaveCount(TASKS);
await expect(page.getByTestId("task-row").first()).toBeVisible();
const poll = page.waitForResponse((r) => r.url().endsWith(`/workspaces/${workspaceId}/sync`));
await page.evaluate(() => window.dispatchEvent(new Event("focus")));
expect((await poll).status()).toBe(304);
});

test("switching views sends no request and stays within budget", async ({ page }) => {
await page.goto(`/w/${workspaceId}?view=list`);
await expect(page.getByTestId("task-row")).toHaveCount(TASKS);
await expect(page.getByTestId("task-row").first()).toBeVisible();
const requests = watchRequests(page);
const times: Record<string, number> = {};
for (const [label, testId] of [
["Board", "task-card"],
["Timeline", "timeline-row"],
["List", "task-row"],
] as const) {
times[label] = await switchView(page, label, testId, TASKS);
await expect(page.getByTestId(testId)).toHaveCount(TASKS);
times[label] = await switchView(page, label, testId);
await expect(page.getByTestId(testId).first()).toBeVisible();
}
requests.stop();
console.log(`[speed] view switch script ms: ${JSON.stringify(times)}`);
Expand All @@ -187,6 +216,36 @@ test("switching views sends no request and stays within budget", async ({ page }
for (const [label, ms] of Object.entries(times)) expect(ms, `${label} switch`).toBeLessThan(SWITCH_BUDGET_MS);
});

test("J moves focus within budget on 2,000 rows", async ({ page }) => {
await page.goto(`/w/${workspaceId}?view=list`);
await expect(page.getByTestId("task-row").first()).toBeVisible();
await page.keyboard.press("j"); // focus the first row
await expect(page.locator('[data-focused="true"]')).toHaveCount(1);
const times = await page.evaluate(async () => {
const out: number[] = [];
for (let i = 0; i < 10; i++) {
const before = document.querySelector('[data-focused="true"]');
const t0 = performance.now();
await new Promise<void>((resolve) => {
const observer = new MutationObserver(() => {
const now = document.querySelector('[data-focused="true"]');
if (now && now !== before) {
observer.disconnect();
resolve();
}
});
observer.observe(document.body, { attributes: true, subtree: true, attributeFilter: ["data-focused"] });
window.dispatchEvent(new KeyboardEvent("keydown", { key: "j", bubbles: true }));
});
out.push(performance.now() - t0);
}
return out;
});
const worst = Math.max(...times);
console.log(`[speed] J focus move ms (10 presses): worst ${worst.toFixed(1)}, median ${[...times].sort((a, b) => a - b)[5]!.toFixed(1)}`);
expect(worst).toBeLessThan(FOCUS_BUDGET_MS);
});

test("a task opens in the side panel without a page load", async ({ page }) => {
await page.goto(`/w/${workspaceId}?view=list`);
const url = page.url();
Expand All @@ -195,10 +254,10 @@ test("a task opens in the side panel without a page load", async ({ page }) => {
page.on("request", (r) => {
if (r.isNavigationRequest() || (r.url().includes("_rsc") && !r.headers()["next-router-prefetch"])) loads.push(r.url());
});
await page.getByRole("link", { name: "Task number 7", exact: true }).click();
await page.getByRole("link", { name: "Task number 3", exact: true }).click();
const panel = page.getByTestId("peek-panel");
await expect(panel.getByRole("heading", { name: "Task number 7" })).toBeVisible();
await expect(panel.getByText("Body of task 7")).toBeVisible();
await expect(panel.getByRole("heading", { name: "Task number 3" })).toBeVisible();
await expect(panel.getByText("Body of task 3")).toBeVisible();
expect(page.url()).toBe(url);
expect(loads).toEqual([]);
await page.keyboard.press("Escape");
Expand All @@ -207,8 +266,10 @@ test("a task opens in the side panel without a page load", async ({ page }) => {

test("an edit shows before the server answers, and rolls back on refusal", async ({ page }) => {
await page.goto(`/w/${workspaceId}?view=list`);
const row = page.getByTestId("task-row").filter({ has: page.getByRole("link", { name: "Task number 9", exact: true }) });
await expect(row).toContainText("Todo"); // 9 % 3 = 0 → Todo
// The row moves to another status group when the status changes, so watch the store through the
// panel's Status field, and the Todo group's count in its header.
const todoHeader = page.getByRole("heading", { name: /^Todo/ });
await expect(todoHeader).toContainText("666"); // n % 3 = 0: 3, 6, …, 1998

let release!: () => void;
const gate = new Promise<void>((r) => (release = r));
Expand All @@ -219,29 +280,36 @@ test("an edit shows before the server answers, and rolls back on refusal", async
});

await page.getByRole("link", { name: "Task number 9", exact: true }).click();
await page.getByTestId("peek-panel").getByLabel("Status").selectOption({ label: "Done" });
// Before the server answers: the row already shows the new status.
await expect(row).toContainText("Done");
const status = page.getByTestId("peek-panel").getByLabel("Status");
await status.selectOption({ label: "Done" });
// Before the server answers: the task has already left the Todo group.
await expect(status).toHaveValue("s-done");
await expect(todoHeader).toContainText("665");
release();
await expect(page.getByRole("status")).toContainText("Could not change Status");
await expect(row).toContainText("Todo");
await expect(status).toHaveValue("s-todo");
await expect(todoHeader).toContainText("666");
});

test("a successful edit keeps the server's answer", async ({ page }) => {
await page.goto(`/w/${workspaceId}?view=list`);
const row = page.getByTestId("task-row").filter({ has: page.getByRole("link", { name: "Task number 10", exact: true }) });
await expect(row).toContainText("Doing"); // 10 % 3 = 1
// The Done group is far below the first screen (virtualized), so watch the panel's Status field.
const sync = await page.request.get(`/api/v1/workspaces/${workspaceId}/sync`);
const task = ((await sync.json()) as { board: { tasks: { id: string; fields: Record<string, unknown> }[] } }).board.tasks.find(
(t) => t.id === "PVTI_big10",
(t) => t.id === "PVTI_big6",
)!;
await page.route(`**/api/v1/workspaces/${workspaceId}/tasks/PVTI_big10`, async (route) => {
await page.route(`**/api/v1/workspaces/${workspaceId}/tasks/PVTI_big6`, async (route) => {
if (route.request().method() !== "PATCH") return route.fallback();
await route.fulfill({
json: { task: { ...task, fields: { ...task.fields, F_bstatus: { type: "single_select", optionId: "s-done", name: "Done" } } } },
});
});
await page.getByRole("link", { name: "Task number 10", exact: true }).click();
await page.getByTestId("peek-panel").getByLabel("Status").selectOption({ label: "Done" });
await expect(row).toContainText("Done");
await page.getByRole("link", { name: "Task number 6", exact: true }).click();
const status = page.getByTestId("peek-panel").getByLabel("Status");
await status.selectOption({ label: "Done" });
await expect(status).toHaveValue("s-done");
// After the stubbed success the server's answer stays: no rollback, no notice.
await page.waitForTimeout(300);
await expect(status).toHaveValue("s-done");
await expect(page.getByRole("status")).not.toContainText("Could not");
});
8 changes: 8 additions & 0 deletions apps/web/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,20 @@ export const metadata: Metadata = {
description: "Project management on top of GitHub.",
};

// Dark mode follows the system setting, before the first paint (no flash of the light theme).
const THEME = `(function(){var m=window.matchMedia("(prefers-color-scheme: dark)");function a(){document.documentElement.classList.toggle("dark",m.matches)}a();m.addEventListener("change",a)})()`;

export default function RootLayout({ children }: LayoutProps<"/">) {
return (
<html
lang="en"
// The theme script sets the "dark" class before React hydrates.
suppressHydrationWarning
className={`${geistSans.variable} ${geistMono.variable} h-full antialiased`}
>
<head>
<script dangerouslySetInnerHTML={{ __html: THEME }} />
</head>
<body className="min-h-full flex flex-col">{children}</body>
</html>
);
Expand Down
Loading
Loading