b673363351
Adds a working Dark/Light toggle (next to the language switcher, same row
as EN/VI) and re-themes the whole dashboard, not just the handful of
components that already used semantic tokens.
- Tailwind darkMode:"class" + CSS-variable color tokens (client/src/index.css,
tailwind.config.js): surface.0-5, border/border-light, accent/accent-hover,
fg.primary/secondary/muted, status.success/danger/warning. One class flip
on <html> re-themes everything — no per-element dark: variant pairs.
- useTheme() hook: localStorage-persisted, defaults to dark, no
prefers-color-scheme fallback (client/src/hooks/useTheme.ts).
- Mechanical, table-driven migration (scripts/migrate-color-tokens.mjs,
scripts/tokenize-status-colors.mjs, scripts/darken-status-colors.mjs) of
every raw neutral/gray/slate + emerald/red/amber Tailwind utility across
client/src onto the new tokens, so every badge/button/component pulls the
same shade per status/role instead of each picking its own.
- Palette values are the literal Radix Colors (radix-ui.com/colors) scale
constants — slate/blue/green/red/amber steps 1-12 — adopted after three
rounds of hand-picked values that kept overshooting (flat, then too dark,
then glaring); see docs/superpowers/specs/2026-07-31-color-redesign-
dark-light-mode-design.md for the full history and role mapping.
- PipelineMap: done/current/failed/passed-no-evidence/detected share one
visual language (border + text + translucent wash of the same status
color); `current` alone stays a solid accent fill, the one state that
gets to look bolder ("you are here").
- LaneCard: removed the stage/kind/auto-stage chips that duplicated the
Workspace lane-detail header already showing them.
Categorical/decorative hues (violet, indigo, cyan, teal, sky, rose, pink,
orange, yellow, and blue where it plays a role-coloring part e.g. message
bubbles) are deliberately out of scope — collapsing those onto shared
tokens would erase the distinction between different kinds of thing, not
a status.
228 lines
8.6 KiB
TypeScript
228 lines
8.6 KiB
TypeScript
/**
|
|
* @file Regression test for the lane card's status badge. Every lane status
|
|
* the server can set must have a real translated word behind
|
|
* `t("status." + lane.status)`; before this test existed, no locale defined
|
|
* any `status.*` key, and i18next's default missing-key behavior (return the
|
|
* key itself) hid that from the `||` fallback, so the badge showed literal
|
|
* text like `status.active`.
|
|
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
|
*/
|
|
|
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { render, screen } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import LaneCard from "../LaneCard";
|
|
import type { Lane } from "../../../lib/types";
|
|
import { api } from "../../../lib/api";
|
|
|
|
vi.mock("../../../lib/api", () => ({
|
|
api: {
|
|
lanes: { git: vi.fn(), preflight: vi.fn().mockResolvedValue({ blocked: [], warnings: [] }) },
|
|
},
|
|
}));
|
|
|
|
beforeEach(() => {
|
|
vi.mocked(api.lanes.git).mockReset();
|
|
vi.mocked(api.lanes.git).mockResolvedValue({ available: false });
|
|
});
|
|
|
|
function makeLane(overrides: Partial<Lane> = {}): Lane {
|
|
return {
|
|
id: 1,
|
|
title: "demo",
|
|
cwd: "/work/demo",
|
|
branch: "lane/demo",
|
|
kind: "adopted",
|
|
pipeline: "default",
|
|
session_id: null,
|
|
run_id: null,
|
|
stage: "plan",
|
|
stage_since: null,
|
|
status: "idle",
|
|
gate_decision: null,
|
|
ci_status: null,
|
|
needs_action: null,
|
|
links: {},
|
|
stages: {},
|
|
notes: null,
|
|
pipeline_name: "Default",
|
|
pipeline_nodes: [],
|
|
progress: 0,
|
|
stage_seconds: null,
|
|
last_event_seconds: null,
|
|
liveness: "idle",
|
|
detected_stage: null,
|
|
detected_signal: null,
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
describe("LaneCard status badge", () => {
|
|
for (const status of ["idle", "running", "provisioning", "failed"] as const) {
|
|
it(`renders a real word for status "${status}", not the raw key`, () => {
|
|
render(<LaneCard lane={makeLane({ status })} onAction={vi.fn()} />);
|
|
expect(screen.queryByText(`status.${status}`)).not.toBeInTheDocument();
|
|
expect(screen.queryByText(status.toUpperCase())).not.toBeInTheDocument();
|
|
});
|
|
}
|
|
});
|
|
|
|
const pipelineNodes: Lane["pipeline_nodes"] = [
|
|
{ id: "intake", label: "intake", icon: "📥", gate: false, state: "done" },
|
|
{ id: "plan", label: "plan", icon: "🧭", gate: false, state: "done" },
|
|
{ id: "implement", label: "implement", icon: "🛠", gate: false, state: "current" },
|
|
{ id: "tests", label: "tests", icon: "🧪", gate: false, state: "pending" },
|
|
];
|
|
|
|
describe("LaneCard rebuilt layout", () => {
|
|
const full = (over: Partial<Lane> = {}) =>
|
|
makeLane({
|
|
id: 7,
|
|
title: "Rename Metric to Rule",
|
|
kind: "managed",
|
|
status: "running",
|
|
liveness: "active",
|
|
stage: "plan",
|
|
stage_seconds: 152,
|
|
progress: 48,
|
|
ci_status: "green",
|
|
pipeline_nodes: pipelineNodes,
|
|
...over,
|
|
});
|
|
|
|
it("labels the card with the lane id", () => {
|
|
render(<LaneCard lane={full()} onAction={vi.fn()} />);
|
|
expect(screen.getByTestId("lane-card-7")).toBeInTheDocument();
|
|
});
|
|
|
|
it("shows the progress percentage and the time on stage", () => {
|
|
render(<LaneCard lane={full()} onAction={vi.fn()} />);
|
|
expect(screen.getByText("48%")).toBeInTheDocument();
|
|
expect(screen.getByText("2m 32s")).toBeInTheDocument();
|
|
});
|
|
|
|
it("gives the progress bar a width matching the lane's progress", () => {
|
|
render(<LaneCard lane={full()} onAction={vi.fn()} />);
|
|
expect(screen.getByTestId("lane-progress-fill").getAttribute("style")).toContain("48%");
|
|
});
|
|
|
|
it("surfaces a needs-you message", () => {
|
|
render(<LaneCard lane={full({ needs_action: "waiting on approval" })} onAction={vi.fn()} />);
|
|
expect(screen.getByText(/waiting on approval/)).toBeInTheDocument();
|
|
});
|
|
|
|
it("fires a plain action with its own name", async () => {
|
|
const onAction = vi.fn();
|
|
render(<LaneCard lane={full()} onAction={onAction} />);
|
|
await userEvent.setup().click(screen.getByTestId("lane-action-stop"));
|
|
expect(onAction).toHaveBeenCalledWith("stop");
|
|
});
|
|
|
|
it("shows both deletions as buttons, and keeps reset behind the menu", async () => {
|
|
render(<LaneCard lane={full()} onAction={vi.fn()} />);
|
|
// Deleting the lane and deleting its history are the two the user goes
|
|
// looking for, so they are visible without opening anything. Reset is not.
|
|
expect(screen.getByTestId("lane-action-remove")).toBeInTheDocument();
|
|
expect(screen.getByTestId("lane-action-purge")).toBeInTheDocument();
|
|
expect(screen.queryByTestId("lane-action-reset")).toBeNull();
|
|
|
|
await userEvent.setup().click(screen.getByTestId("lane-more"));
|
|
expect(screen.getByTestId("lane-action-reset")).toBeInTheDocument();
|
|
});
|
|
|
|
it("routes both deletions through the modal rather than firing them", async () => {
|
|
const onAction = vi.fn();
|
|
render(<LaneCard lane={full()} onAction={onAction} />);
|
|
const user = userEvent.setup();
|
|
await user.click(screen.getByTestId("lane-action-remove"));
|
|
expect(onAction).not.toHaveBeenCalled();
|
|
await user.click(screen.getByTestId("lane-action-purge"));
|
|
expect(onAction).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("routes reset through the confirmation modal rather than firing it", async () => {
|
|
const onAction = vi.fn();
|
|
render(<LaneCard lane={full()} onAction={onAction} />);
|
|
const user = userEvent.setup();
|
|
await user.click(screen.getByTestId("lane-more"));
|
|
await user.click(screen.getByTestId("lane-action-reset"));
|
|
expect(onAction).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("offers reset only for a managed lane, and drops the menu entirely without it", async () => {
|
|
const user = userEvent.setup();
|
|
const { unmount } = render(<LaneCard lane={full()} onAction={vi.fn()} />);
|
|
await user.click(screen.getByTestId("lane-more"));
|
|
expect(screen.getByTestId("lane-action-reset")).toBeInTheDocument();
|
|
unmount();
|
|
|
|
// An adopted lane has nothing left in the menu, so there is no ⋯ to open.
|
|
render(<LaneCard lane={full({ kind: "adopted" })} onAction={vi.fn()} />);
|
|
expect(screen.queryByTestId("lane-more")).toBeNull();
|
|
expect(screen.queryByTestId("lane-action-reset")).toBeNull();
|
|
expect(screen.getByTestId("lane-action-remove")).toBeInTheDocument();
|
|
});
|
|
});
|
|
|
|
describe("LaneCard git block", () => {
|
|
const facts = {
|
|
available: true as const,
|
|
branch: "feat/rename-metric",
|
|
head: "9b3e74a",
|
|
subject: "free-text rule mode in the form",
|
|
dirty: 2,
|
|
untracked: 1,
|
|
};
|
|
|
|
it("renders the live branch, head, subject and uncommitted counts", async () => {
|
|
vi.mocked(api.lanes.git).mockResolvedValueOnce(facts);
|
|
render(<LaneCard lane={makeLane({ branch: "stale/recorded" })} onAction={vi.fn()} />);
|
|
|
|
const block = await screen.findByTestId("lane-git");
|
|
expect(block.textContent).toContain("feat/rename-metric");
|
|
expect(block.textContent).toContain("9b3e74a");
|
|
expect(block.textContent).toContain("free-text rule mode in the form");
|
|
expect(block.textContent).toContain("2");
|
|
// The live branch replaces the lane's recorded one rather than doubling it.
|
|
expect(screen.queryByText(/stale\/recorded/)).toBeNull();
|
|
});
|
|
|
|
it("omits the uncommitted line when the tree is clean", async () => {
|
|
vi.mocked(api.lanes.git).mockResolvedValueOnce({ ...facts, dirty: 0, untracked: 0 });
|
|
render(<LaneCard lane={makeLane()} onAction={vi.fn()} />);
|
|
const block = await screen.findByTestId("lane-git");
|
|
expect(block.textContent).not.toContain("modified");
|
|
});
|
|
|
|
it("renders the card with no git block and no error when git is unavailable", async () => {
|
|
vi.mocked(api.lanes.git).mockResolvedValueOnce({ available: false });
|
|
render(<LaneCard lane={makeLane({ title: "plain dir lane" })} onAction={vi.fn()} />);
|
|
|
|
expect(await screen.findByText("plain dir lane")).toBeInTheDocument();
|
|
expect(screen.queryByTestId("lane-git")).toBeNull();
|
|
});
|
|
|
|
it("swallows a rejected request instead of surfacing an error", async () => {
|
|
vi.mocked(api.lanes.git).mockRejectedValueOnce(new Error("network down"));
|
|
render(<LaneCard lane={makeLane({ title: "offline lane" })} onAction={vi.fn()} />);
|
|
|
|
expect(await screen.findByText("offline lane")).toBeInTheDocument();
|
|
expect(screen.queryByTestId("lane-git")).toBeNull();
|
|
expect(screen.queryByText(/network down/)).toBeNull();
|
|
});
|
|
|
|
it("stops polling once the card unmounts", async () => {
|
|
vi.useFakeTimers();
|
|
try {
|
|
vi.mocked(api.lanes.git).mockResolvedValue({ available: false });
|
|
const { unmount } = render(<LaneCard lane={makeLane()} onAction={vi.fn()} />);
|
|
expect(api.lanes.git).toHaveBeenCalledTimes(1);
|
|
unmount();
|
|
vi.advanceTimersByTime(120_000);
|
|
expect(api.lanes.git).toHaveBeenCalledTimes(1);
|
|
} finally {
|
|
vi.useRealTimers();
|
|
}
|
|
});
|
|
});
|