Files
buzz/desktop-new/tests/inline-chip.spec.ts
morgmart 7b8c73b95f desktop-new: purple accent, rename tile to chip, redesign from Figma
Accent hue is now Tailwind purple. The ramp is a slot, so this is five values
in tokens.css and every role follows; steps 2 and 3 are purple-100/200 exactly
because the chip design was drawn against them and the tint pair is what a
person sees most. Dark mode cannot use those two — near-white reads as a light
surface on a dark panel — so it holds the hue at dark violets instead.

Renamed InlineTile to InlineChip throughout, plus shared/tiles to shared/chips,
tileNode to chipNode, and every token, class, and identifier. A chip is what
this is.

Redesigned to match Figma 700-2782:
- One treatment for every kind: accent tint behind primary text. Kinds are told
  apart by sigil and, where the label is ambiguous, an icon — not by colour.
  This replaces the earlier per-kind colour split, which spent palette on a
  distinction the sigil already makes.
- Label is primary text, not accent text; the tint does the colour work.
- Two new kinds the design draws: message and link, both icon-led with no
  sigil. AUTHORABLE_CHIP_KINDS records that v1's picker still offers only
  person, agent, and channel; the others arrive by another route.
- Dropped avatar and status dot. The design has neither, and neither was
  earning its place at text size.
- Unresolved is now a real state: neutral fill, lesser text, and never a
  control, because there is nothing to open.
- Chip inset and gap intentionally sit below the 4px spacing floor (3px inset,
  4px gap) — a chip hugs its label. Recorded on the tokens.

Eight new rendered-contract tests bound to the real specimen page: sigils and
selective icons, assistive naming, unresolved-is-never-a-control, read-only
claims no stop, activation reports the address, truncation, never breaking
across a line, and hover deepening the tint without moving the text.

Signed-off-by: morgmart <98432065+morgmart@users.noreply.github.com>
2026-09-06 18:15:13 -07:00

153 lines
4.7 KiB
TypeScript

import { expect, test, type Page } from "@playwright/test";
/**
* InlineChip's rendered contract, asserted against the real specimen page so
* these bind the shipped component rather than a test-only copy.
*/
const SPECIMEN = "/design/components/inline-chip";
async function open(page: Page) {
await page.goto(SPECIMEN);
await expect(
page.getByRole("heading", { name: "InlineChip", level: 1 }),
).toBeVisible();
}
function group(page: Page, label: string) {
return page
.locator(".component-specimen-group")
.filter({ has: page.getByRole("heading", { name: label, exact: true }) });
}
test("draws every kind with its sigil, and an icon only where needed", async ({
page,
}) => {
await open(page);
const kinds = group(page, "Kinds");
await expect(kinds.locator(".inline-chip-label")).toHaveText([
"@Morgan Martin",
"@Morgarita",
"#buzz-team",
"buzz-team",
"github.com/block/buzz",
]);
// A person, agent, and channel are identified by their sigil, so adding a
// glyph would say the same thing twice. A message and link have no sigil.
const iconed = kinds.locator(".inline-chip", {
has: page.locator(".inline-chip-icon"),
});
await expect(iconed).toHaveCount(2);
await expect(iconed.first()).toHaveAttribute("data-kind", "message");
await expect(iconed.last()).toHaveAttribute("data-kind", "link");
});
test("names itself for assistive technology without speaking an identity", async ({
page,
}) => {
await open(page);
await expect(
group(page, "Kinds").locator(".inline-chip").first(),
).toHaveAttribute("aria-label", "Person Morgan Martin");
// An abbreviated identity read aloud tells a screen-reader user nothing.
const unresolved = group(page, "Unresolved reference").locator(
".inline-chip",
);
await expect(unresolved).toHaveAttribute("aria-label", "Unresolved person");
const label = await unresolved.locator(".inline-chip-label").innerText();
expect(label).not.toContain("9f2c4a1b7e5d8306");
});
test("an unresolved reference is never a control", async ({ page }) => {
await open(page);
// Nothing to open, so it must not look or behave actionable however it was
// asked for. A chip that invites a click and does nothing is worse than one
// that reads as inert.
const unresolved = group(page, "Unresolved reference").locator(
".inline-chip",
);
await expect(unresolved).toHaveAttribute("data-state", "unresolved");
await expect(unresolved).toHaveRole("img");
});
test("read-only chips claim no interactive stop", async ({ page }) => {
await open(page);
const readOnly = group(
page,
"Read-only, as a conversation renders it",
).locator(".inline-chip");
await expect(readOnly).toHaveRole("img");
await expect(readOnly.locator("xpath=self::button")).toHaveCount(0);
});
test("activating a chip reports its address, not its label", async ({
page,
}) => {
await open(page);
const activation = group(page, "Activation");
await expect(activation.getByText("Not activated")).toBeVisible();
await activation.locator(".inline-chip").click();
await expect(activation.getByText("Opened pk-morgan")).toBeVisible();
});
test("a long label truncates instead of stretching the line", async ({
page,
}) => {
await open(page);
const chip = group(page, "Long label truncates").locator(".inline-chip");
const box = await chip.boundingBox();
if (!box) throw new Error("Chip is not laid out");
// Bounded by the component's max-width rather than growing to fit.
expect(box.width).toBeLessThan(280);
const label = chip.locator(".inline-chip-label");
const clipped = await label.evaluate(
(el) => el.scrollWidth > el.clientWidth + 1,
);
expect(clipped).toBe(true);
});
test("a chip never breaks across a line", async ({ page }) => {
await open(page);
const chips = group(page, "Wrapping across lines").locator(".inline-chip");
// Each chip occupies exactly one client rect: a break falls before or after
// it, never through its middle.
for (const chip of await chips.all()) {
const rects = await chip.evaluate((el) => el.getClientRects().length);
expect(rects).toBe(1);
}
});
test("hover deepens the tint rather than changing the text", async ({
page,
}) => {
await open(page);
const chip = group(page, "Activation").locator(".inline-chip");
const read = () =>
chip.evaluate((el) => {
const s = getComputedStyle(el);
return { bg: s.backgroundColor, color: s.color };
});
const rest = await read();
await chip.hover();
await page.waitForFunction(
([el, was]) => getComputedStyle(el as Element).backgroundColor !== was,
[await chip.elementHandle(), rest.bg] as const,
);
const hovered = await read();
expect(hovered.bg).not.toBe(rest.bg);
expect(hovered.color).toBe(rest.color);
});