Skip to content
Merged
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
3 changes: 3 additions & 0 deletions dashboard/e2e/audit-alerts.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { quietForYou } from "./foryou-data";
import { expect, test, type Page, type Route } from "@playwright/test";
import fs from "node:fs";
import path from "node:path";
Expand Down Expand Up @@ -54,6 +55,8 @@ async function mockApi(page: Page, init: Partial<Backend> = {}): Promise<Backend
const req = route.request();
const url = new URL(req.url());
const p = url.pathname;
// The menu's For you count (read with the shell on every page).
if (p === "/api/foryou") return route.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify(quietForYou()) });
db.calls.push(`${req.method()} ${p}${url.search}`);
if (p === "/api/me") return json(route, { user_id: "u_1", team_id: "t_1", github_login: null, email: "admin@example.com", avatar_url: "", role: "admin" });
if (p === "/api/usage") return json(route, { month: "2026-01", total_tokens: 0, tokens_in: 0, tokens_out: 0, total_runs: 0, max_tokens: 0 });
Expand Down
3 changes: 3 additions & 0 deletions dashboard/e2e/audit-plans.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { quietForYou } from "./foryou-data";
import { expect, test, type Page, type Route } from "@playwright/test";
import fs from "node:fs";
import path from "node:path";
Expand Down Expand Up @@ -144,6 +145,8 @@ async function mockApi(page: Page, init: Partial<Backend> = {}): Promise<Backend
const req = route.request();
const url = new URL(req.url());
const p = url.pathname;
// The menu's For you count (read with the shell on every page).
if (p === "/api/foryou") return route.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify(quietForYou()) });
const m = req.method();
db.calls.push(`${m} ${p}${url.search}`);
if (m !== "GET" && p.startsWith("/api/plans/") && !p.startsWith("/api/plans/chat")) {
Expand Down
3 changes: 3 additions & 0 deletions dashboard/e2e/audit-reviewer.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { quietForYou } from "./foryou-data";
import { expect, test, type Page, type Route } from "@playwright/test";
import fs from "node:fs";
import path from "node:path";
Expand Down Expand Up @@ -205,6 +206,8 @@ async function mockApi(page: Page, init: Partial<Backend> = {}): Promise<Backend
const req = route.request();
const url = new URL(req.url());
const p = url.pathname;
// The menu's For you count (read with the shell on every page).
if (p === "/api/foryou") return route.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify(quietForYou()) });
db.calls.push(`${req.method()} ${p}${url.search}`);
if (req.method() !== "GET") db.bodies.push(JSON.parse(req.postData() || "{}"));
if (p === "/api/me") return json(route, { user_id: "u_1", team_id: "t_1", github_login: null, email: "someone@example.com", avatar_url: "", role: db.role });
Expand Down
3 changes: 3 additions & 0 deletions dashboard/e2e/audit-shell.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { quietForYou } from "./foryou-data";
import { expect, test, type Page, type Route } from "@playwright/test";
import fs from "node:fs";
import path from "node:path";
Expand Down Expand Up @@ -45,6 +46,8 @@ async function mockApi(page: Page, init: Partial<Backend> = {}): Promise<Backend
const req = route.request();
const url = new URL(req.url());
const p = url.pathname;
// The menu's For you count (read with the shell on every page).
if (p === "/api/foryou") return route.fulfill({ status: 200, contentType: "application/json", body: JSON.stringify(quietForYou()) });
db.calls.push(`${req.method()} ${p}${url.search}`);
if (p === "/api/me") {
if (db.me !== 200) return route.fulfill({ status: db.me, body: "" });
Expand Down
163 changes: 149 additions & 14 deletions dashboard/e2e/foryou-data.ts

Large diffs are not rendered by default.

48 changes: 48 additions & 0 deletions dashboard/e2e/foryou-polish.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { expect, test, type Page } from "@playwright/test";
import path from "node:path";
import { openForYou } from "./foryou-data";

// For you at every data size (sparse: one repo, a couple of pull requests,
// Jira not linked, no history; medium; big) and width. Each is checked for
// what makes a page look broken: a popover or tooltip open at rest,
// sideways scroll, an empty frame or a row of zeros. Screenshots are saved
// when E2E_SHOTS_DIR is set (foryou-polish-<size>-<width>.png).

const DIR = process.env.E2E_SHOTS_DIR;
const WIDTHS = [1440, 1280, 1024, 375];
const SIZES = [
["sparse", "sparse"],
["medium", "busy"],
["big", "big"],
] as const;

async function atRest(page: Page) {
const open = await page.locator('[role=tooltip], [data-radix-popper-content-wrapper], [role=dialog], [role=menu]').evaluateAll((els) =>
els.filter((e) => {
const r = e.getBoundingClientRect();
const s = getComputedStyle(e);
return r.width > 0 && r.height > 0 && s.visibility !== "hidden" && s.display !== "none" && Number(s.opacity) > 0;
}).length,
);
expect(open, "nothing pops up at rest").toBe(0);
const sideways = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);
expect(sideways, "no sideways scroll").toBe(0);
// Never a row of zero tiles: a number shown on the rail is a real count.
const zeros = await page.getByTestId("fy-stats").locator("dd").evaluateAll((els) => els.filter((e) => /^\s*0\s*$/.test(e.textContent ?? "")).length);
expect(zeros, "no zero tiles on the rail").toBe(0);
}

test.describe.configure({ mode: "parallel" });

for (const [size, state] of SIZES) {
for (const width of WIDTHS) {
test(`For you, ${size}, ${width} wide: designed, nothing open at rest`, async ({ page }) => {
await openForYou(page, state, { width, height: 900 });
await expect(page.getByTestId("fy-status")).toBeVisible();
await page.mouse.move(0, 0);
await page.waitForTimeout(250);
await atRest(page);
if (DIR) await page.screenshot({ path: path.join(DIR, `foryou-polish-${size}-${width}.png`), fullPage: true });
});
}
}
113 changes: 113 additions & 0 deletions dashboard/e2e/foryou-polish2.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { expect, test, type Page } from "@playwright/test";
import path from "node:path";
import { openForYou, type Sent } from "./foryou-data";

// For you's type and content, round two: one small label style for group
// headers, one primary button (the top row), code shown as code, old rows
// folded away, copies of one thing under one row, the accounts card with one
// plain status per account, the Jira link sheet, and an older backend that
// offers no button it can't serve. Screenshots: foryou-polish2-*.png when
// E2E_SHOTS_DIR is set.

const DIR = process.env.E2E_SHOTS_DIR;
const DESKTOP = { width: 1440, height: 900 };

async function shot(page: Page, name: string, full = true) {
if (DIR) await page.screenshot({ path: path.join(DIR, `foryou-polish2-${name}.png`), fullPage: full });
}

test.describe.configure({ mode: "parallel" });

test("one primary button, on the top row only; group headers in one small label style", async ({ page }) => {
await openForYou(page);
await expect(page.getByTestId("fy-need").first()).toBeVisible();
const primaries = await page.locator("[data-testid=fy-need-action]").evaluateAll((els) => els.filter((e) => e.className.includes("bg-inverse")).length);
expect(primaries).toBe(1);
const head = page.getByTestId("fy-needs").getByText("Reviews requested of you", { exact: true });
const style = await head.evaluate((e) => {
const s = getComputedStyle(e.parentElement as HTMLElement);
return { size: s.fontSize, transform: s.textTransform, weight: s.fontWeight };
});
expect(style).toEqual({ size: "15px", transform: "none", weight: "600" });
const title = page.getByTestId("fy-need").first().locator("div.text-sm.font-medium").first();
expect(await title.evaluate((e) => getComputedStyle(e).fontSize)).toBe("15px");
});

test("old rows fold into one group with Dismiss all; copies sit under one row; code shows as code", async ({ page }) => {
const sent: Sent[] = [];
await openForYou(page, "busy", DESKTOP, sent, { staleAndAlike: true });
const stale = page.getByTestId("fy-stale");
await expect(stale).toContainText("Old, probably abandoned");
await expect(stale).not.toHaveAttribute("open", "");
const alike = page.getByTestId("fy-need").filter({ hasText: "Save the weekly stock report" });
await expect(alike).toHaveCount(1);
await expect(alike.getByTestId("fy-alike")).toContainText("2 more like it");
const coded = page.getByTestId("fy-need").filter({ hasText: "Fix CI after" });
await expect(coded.locator("code").first()).toHaveText("cd381bd");
await expect(coded).not.toContainText("`");
await shot(page, "stale-alike-1440");
await stale.locator("summary").click();
await stale.getByTestId("fy-stale-dismiss").click();
await expect(page.getByText("1 old item dismissed.")).toBeVisible();
expect(sent.filter((s) => s.path === "/api/foryou/items").map((s) => JSON.parse(s.body).key)).toEqual(["plan:old-1"]);
});

test("the accounts card: one plain status per account, never a badge beside a contradicting word", async ({ page }) => {
for (const [state, gh, jira, name] of [
["busy", "Linked as @dana-ortiz", "Linked as Dana Ortiz", "accounts-linked"],
["nc", "Not linked", "Not linked", "accounts-not-linked"],
["partial", "Linked as @dana-ortiz", "Not linked", "accounts-mixed"],
] as const) {
await openForYou(page, state, DESKTOP);
const card = page.getByTestId("fy-accounts");
await expect(page.getByTestId("fy-acct-github-status")).toHaveText(gh);
await expect(page.getByTestId("fy-acct-jira-status")).toHaveText(jira);
await expect(card).not.toContainText(/\bOn\b/);
await expect(card.locator(".bg-inverse")).toHaveCount(0);
for (const id of ["fy-acct-github-status", "fy-acct-jira-status"]) {
const h = await page.getByTestId(id).evaluate((e) => e.getBoundingClientRect().height);
expect(h, `${id} on one line`).toBeLessThan(20);
}
if (DIR) await card.screenshot({ path: path.join(DIR, `foryou-polish2-${name}.png`) });
}
});

test("Link Jira: three steps, the code with Copy, and Waiting for Jira turns into Linked as", async ({ page, context }) => {
await context.grantPermissions(["clipboard-read", "clipboard-write"]);
await openForYou(page, "partial", DESKTOP, [], { linkFlips: true });
await page.getByTestId("fy-connect-jira-rail").click();
const sheet = page.getByTestId("fy-link-code");
await expect(sheet).toContainText("Open any Jira issue.");
await expect(sheet).toContainText("Link my CoderHelm account");
await expect(sheet.getByTestId("fy-link-wait")).toHaveText("Waiting for Jira…");
await sheet.getByTestId("fy-code-copy").click();
await expect(sheet.getByTestId("fy-code-copy")).toHaveText("Copied");
await shot(page, "link-sheet", false);
await expect(sheet.getByTestId("fy-link-wait")).toHaveText("Linked as Dana Ortiz", { timeout: 15_000 });
});

test("an older backend offers no Jira button and never raises a 404 toast", async ({ page }) => {
await openForYou(page, "old", DESKTOP);
await expect(page.getByTestId("fy-fallback")).toBeVisible();
await expect(page.getByTestId("fy-acct-jira-status")).toHaveText("Arrives with the next update");
await expect(page.getByTestId("fy-connect-jira-rail")).toHaveCount(0);
await expect(page.getByTestId("fy-connect-jira")).toHaveCount(0);
await expect(page.getByText(/error 404|Not found/i)).toHaveCount(0);
});

for (const [size, state] of [
["fallback", "old"],
["busy", "busy"],
["sparse", "sparse"],
] as const) {
for (const width of [1440, 1280, 1024, 375]) {
test(`shots: ${size} at ${width}`, async ({ page }) => {
test.skip(!DIR, "E2E_SHOTS_DIR is not set");
await openForYou(page, state, { width, height: 900 });
await expect(page.getByTestId("fy-status")).toBeVisible();
await page.mouse.move(0, 0);
await page.waitForTimeout(250);
await shot(page, `${size}-${width}`);
});
}
}
112 changes: 112 additions & 0 deletions dashboard/e2e/foryou-real.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import { expect, test, type Page } from "@playwright/test";
import AxeBuilder from "@axe-core/playwright";
import { mockForYou, openForYou, type Sent } from "./foryou-data";
import { hideDevOverlay } from "./needs-data";

// For you's real plan, step checklist, nudge and desktop count, with the
// same invented team (acme/*, Dana Ortiz, @mara, @theo, @jun, BOOK tickets).

const DESKTOP = { width: 1440, height: 900 };
const PHONE = { width: 375, height: 760 };

async function axe(page: Page, what: string) {
const r = await new AxeBuilder({ page }).withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22a", "wcag22aa"]).exclude("nextjs-portal").analyze();
const found = r.violations.map((v) => `${v.id}: ${v.nodes.length}x ${v.nodes.slice(0, 3).map((n) => n.target.join(" ")).join(" | ")}`);
expect(found, `${what}: axe WCAG 2.2 AA`).toEqual([]);
}

const sideways = (page: Page) => page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);

test.describe.configure({ mode: "parallel" });

test("a plan waiting for your OK opens as written: steps, repositories, files and tests; Approve answers the run", async ({ page }) => {
const sent: Sent[] = [];
await openForYou(page, "busy", DESKTOP, sent, { planAsk: true });
const row = page.getByTestId("fy-need").filter({ hasText: "Add an empty state to the saved carts list" });
await expect(row).toContainText("CoderHelm wrote the plan and waits for your OK before coding.");
await row.getByTestId("fy-need-action").click();
const sheet = page.getByTestId("fy-plan-sheet");
await expect(sheet).toContainText("The plan, for your OK");
await expect(sheet.getByTestId("fy-plan-step")).toHaveCount(3);
await expect(sheet.getByTestId("fy-plan-repos")).toHaveText("acme/web");
await expect(sheet.getByTestId("fy-plan-files")).toContainText("web/src/carts/__tests__/SavedCartsList.test.tsx");
await expect(sheet.getByTestId("fy-plan-tests")).toContainText("Add tests for zero carts and one cart");
await axe(page, "plan sheet");
await sheet.getByTestId("fy-plan-approve").click();
await expect(page.getByText("Approved. CoderHelm codes from this plan now.")).toBeVisible();
const answer = sent.find((s) => s.path === "/api/runs/run_112p/answer");
expect(JSON.parse(answer?.body ?? "{}")).toEqual({ answers: [{ question_id: "q1", answer: "Approve the plan and start coding" }] });
});

test("changing the plan sends the words and asks for another OK", async ({ page }) => {
const sent: Sent[] = [];
await openForYou(page, "busy", DESKTOP, sent, { planAsk: true });
await page.getByTestId("fy-need").filter({ hasText: "Add an empty state" }).getByTestId("fy-need-action").click();
const sheet = page.getByTestId("fy-plan-sheet");
await sheet.getByTestId("fy-plan-change").click();
await expect(sheet.getByTestId("fy-plan-send-change")).toBeDisabled();
await sheet.getByTestId("fy-plan-change-words").fill("Keep the old empty text for the mobile app");
await sheet.getByTestId("fy-plan-send-change").click();
await expect(page.getByText("Sent. CoderHelm plans again and asks for your OK again.")).toBeVisible();
const answer = sent.find((s) => s.path === "/api/runs/run_112p/answer");
expect(JSON.parse(answer?.body ?? "{}").answers[0].answer).toBe("Change the plan first (say how): Keep the old empty text for the mobile app");
});

test("a run at work shows its plan's real steps, ticked as it goes", async ({ page }) => {
await openForYou(page);
const work = page.getByTestId("fy-work").filter({ hasText: "Add a gift-wrap note" });
await work.getByTestId("fy-steps-toggle").click();
await expect(work.getByTestId("fy-steps-count")).toHaveText("2 of 4 steps done");
await expect(work.getByTestId("fy-plan-step")).toHaveCount(4);
await expect(work.locator("[data-testid=fy-plan-step][data-done]")).toHaveCount(2);
await axe(page, "steps open");
});

test("Give shows the plan the ticket's run already wrote", async ({ page }) => {
await openForYou(page, "busy", DESKTOP, [], { planWritten: true });
await page.getByTestId("fy-ticket").filter({ hasText: "BOOK-112" }).getByTestId("fy-sug-accept").click();
const sheet = page.getByTestId("fy-give-sheet");
await expect(sheet.getByTestId("fy-give-plan").getByTestId("fy-plan-step")).toHaveCount(3);
await expect(sheet.getByTestId("fy-give-plan")).toContainText("Tests: Add tests for zero carts");
});

test("Nudge reminds the one person on GitHub, says it was sent, and can be undone", async ({ page }) => {
const sent: Sent[] = [];
await openForYou(page, "busy", DESKTOP, sent);
const row = page.getByTestId("fy-waiting").filter({ hasText: "Paginate the orders export" });
await row.getByTestId("fy-nudge").click();
await expect(page.getByText("Reminded @mara on GitHub. Undo takes the comment back.")).toBeVisible();
expect(sent.filter((s) => s.path === "/api/foryou/nudge" && s.method === "POST").map((s) => JSON.parse(s.body))).toEqual([{ repo: "acme/api", number: 477 }]);
await expect(row.getByTestId("fy-nudged")).toContainText("You nudged @mara just now");
await row.getByTestId("fy-unnudge").click();
await expect(page.getByText("The reminder is taken back.")).toBeVisible();
expect(sent.filter((s) => s.path === "/api/foryou/nudge" && s.method === "DELETE").map((s) => JSON.parse(s.body))).toEqual([{ repo: "acme/api", number: 477 }]);
await expect(row.getByTestId("fy-nudge")).toBeVisible();
});

test("a nudge sent today shows instead of the button, at most one a day", async ({ page }) => {
await openForYou(page);
const row = page.getByTestId("fy-waiting").filter({ hasText: "Show proration when a plan changes" });
await expect(row.getByTestId("fy-nudged")).toContainText(/You nudged @theo \d+ min ago · one a day/);
await expect(row.getByTestId("fy-nudge")).toHaveCount(0);
await axe(page, "nudged row");
});

test("on a phone the plan sheet and nudges fit without sideways scroll", async ({ page }) => {
await openForYou(page, "busy", PHONE, [], { planAsk: true });
await expect(page.getByTestId("fy-waiting").first()).toBeVisible();
expect(await sideways(page)).toBe(0);
await page.getByTestId("fy-need").filter({ hasText: "Add an empty state" }).getByTestId("fy-need-action").click();
await expect(page.getByTestId("fy-plan-sheet").getByTestId("fy-plan-step")).toHaveCount(3);
expect(await sideways(page)).toBe(0);
});

test("a wide screen shows the For you count with the menu, before For you is opened", async ({ page }) => {
await mockForYou(page);
await hideDevOverlay(page);
await page.setViewportSize(DESKTOP);
await page.goto("/plans/");
const link = page.getByTestId("main-nav").first().getByRole("link").first();
await expect(link).toHaveText(/^For you/);
await expect(link.getByTestId("count-badge")).toContainText("6");
});
17 changes: 17 additions & 0 deletions dashboard/e2e/foryou-shots.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,23 @@ test("desktop screenshots: For you and its states", async ({ page }) => {
await expect(page.getByTestId("fy-customize")).toBeVisible();
await shot(page, "desktop-customize");

// The plan a "Draft a plan first" run waits on, as written.
await openForYou(page, "busy", DESKTOP, [], { planAsk: true });
await page.getByTestId("fy-need").filter({ hasText: "Add an empty state" }).getByTestId("fy-need-action").click();
await expect(page.getByTestId("fy-plan-step")).toHaveCount(3);
await shot(page, "desktop-plan-sheet");
await page.keyboard.press("Escape");

// A run's steps, and a nudge sent.
await openForYou(page, "busy", DESKTOP);
const work = page.getByTestId("fy-work").filter({ hasText: "Add a gift-wrap note" });
await work.getByTestId("fy-steps-toggle").click();
await expect(work.getByTestId("fy-steps-count")).toBeVisible();
await work.scrollIntoViewIfNeeded();
await shot(page, "desktop-steps");
await page.getByTestId("fy-waiting").first().scrollIntoViewIfNeeded();
await shot(page, "desktop-waiting-nudge");

for (const st of ["quiet", "partial", "nc"] as const) {
await openForYou(page, st, DESKTOP);
await expect(page.getByTestId("fy-status")).toBeVisible();
Expand Down
Loading
Loading