-
{copy.totalValue}
-
- {formatMoney(totals.value, currency)}
+
+ {/* Sized by the section, not the viewport: the sidebar narrows it at tablet widths. */}
+
+
+
{copy.totalValue}
+
+
-
-
+
{stats.map((stat) => (
-
-
- {stat.label}
-
- {stat.value}
- {stat.detail && (
-
- {stat.detail}
- )}
+
+
- {stat.label}
+ -
+ {stat.value}
+ {stat.detail && {stat.detail}}
+
))}
-
+
{dashboard.history.length >= PORTFOLIO_HERO.minHistoryPoints ? (
) : (
-
{copy.historyEmpty}
+
{copy.historyEmpty}
)}
diff --git a/src/components/portfolio-hero/portfolio-hero.config.ts b/src/components/portfolio-hero/portfolio-hero.config.ts
index 920e5e13..05c9b3c2 100644
--- a/src/components/portfolio-hero/portfolio-hero.config.ts
+++ b/src/components/portfolio-hero/portfolio-hero.config.ts
@@ -1,2 +1,16 @@
/** Below this many points the history chart has nothing useful to show. */
-export const PORTFOLIO_HERO = { minHistoryPoints: 3 } as const; // two snapshots plus the live value
+export const PORTFOLIO_HERO = {
+ minHistoryPoints: 3, // two snapshots plus the live value
+ classes: {
+ root: "@container",
+ top: "flex flex-col gap-6 pb-5 @3xl:flex-row @3xl:items-end @3xl:justify-between",
+ figure: "mt-4 text-[52px] @md:text-[72px] @3xl:text-[96px] @5xl:text-[120px]",
+ change: "mt-4 min-h-5",
+ stats: "grid grid-cols-[auto_1fr] gap-x-4 gap-y-1.5 text-xs @3xl:w-72 @3xl:shrink-0",
+ statLabel: "text-muted-foreground",
+ statValue: "min-w-0 font-mono tabular-nums text-foreground",
+ statDetail: "ml-2 font-sans text-muted-foreground",
+ chart: "border-y",
+ empty: "py-10 text-center text-muted-foreground",
+ },
+} as const;
diff --git a/src/components/portfolio-hero/portfolio-hero.skeleton.tsx b/src/components/portfolio-hero/portfolio-hero.skeleton.tsx
index bb6f2caf..51f00957 100644
--- a/src/components/portfolio-hero/portfolio-hero.skeleton.tsx
+++ b/src/components/portfolio-hero/portfolio-hero.skeleton.tsx
@@ -1,38 +1,40 @@
import { Skeleton } from "~/components/skeleton/skeleton.component";
import { HISTORY_PANEL } from "~/components/history-panel/history-panel.config";
import { VALUE_CHART } from "~/components/value-chart/value-chart.config";
+import { PORTFOLIO_HERO } from "./portfolio-hero.config";
-/** Same box as PortfolioHero: heading + number, stat strip, filter pills and the chart. */
+const { classes } = PORTFOLIO_HERO;
+
+/** Same box as PortfolioHero: kicker + figure, the stat list, filter pills and the chart. */
export function PortfolioHeroSkeleton() {
return (
-
-
-
-
-
-
+
+
+
-
+
{[0, 1, 2].map((stat) => (
-
+
-
- {stat === 1 && }
+
))}
-
-
+
+
{HISTORY_PANEL.series.map((s) => (
-
+
))}
{HISTORY_PANEL.ranges.map((r) => (
-
+
))}
diff --git a/src/components/portfolio-hero/portfolio-hero.test.tsx b/src/components/portfolio-hero/portfolio-hero.test.tsx
new file mode 100644
index 00000000..fc2b4daf
--- /dev/null
+++ b/src/components/portfolio-hero/portfolio-hero.test.tsx
@@ -0,0 +1,57 @@
+/* oxlint-disable typescript/no-floating-promises -- node:test registers suites synchronously */
+import assert from "node:assert/strict";
+import { describe, test } from "node:test";
+import { COPY } from "~/lib/copy/copy.config";
+import { formatInteger, formatMoney } from "~/utils/format";
+import { makeDashboard, makeHistory } from "~test/fixtures";
+import { render, screen } from "~test/ui";
+import { PortfolioHero } from "./portfolio-hero.component";
+import { PORTFOLIO_HERO } from "./portfolio-hero.config";
+
+const copy = COPY.dashboard;
+
+describe("PortfolioHero", () => {
+ test("shows the total, its parts and item count", () => {
+ const dashboard = makeDashboard();
+ render(
);
+ assert.ok(screen.getByText(formatMoney(dashboard.totals.value, "USD")));
+ assert.ok(screen.getAllByText(copy.inventory).length >= 1);
+ assert.ok(screen.getByText(formatMoney(dashboard.totals.inventoryValue, "USD")));
+ assert.ok(screen.getByText(formatInteger(dashboard.totals.itemCount)));
+ assert.ok(screen.getByText("2/3 units"));
+ });
+
+ test("the charms line shows only when charms have value", () => {
+ const base = makeDashboard();
+ const { rerender } = render(
);
+ assert.ok(screen.queryByText(copy.charms) === null);
+ rerender(
+
,
+ );
+ assert.ok(screen.getByText(copy.charms));
+ });
+
+ test("with too little history it says so instead of drawing a chart", () => {
+ render(
+
,
+ );
+ assert.ok(screen.getByText(copy.historyEmpty));
+ });
+
+ test("with enough history it shows the history controls", () => {
+ render(
+
,
+ );
+ assert.ok(screen.queryByText(copy.historyEmpty) === null);
+ assert.ok(screen.getByRole("button", { name: "CSV" }));
+ });
+});
diff --git a/src/components/pulled-list/pulled-list.test.tsx b/src/components/pulled-list/pulled-list.test.tsx
new file mode 100644
index 00000000..f5a09a73
--- /dev/null
+++ b/src/components/pulled-list/pulled-list.test.tsx
@@ -0,0 +1,24 @@
+/* oxlint-disable typescript/no-floating-promises -- node:test registers suites synchronously */
+import assert from "node:assert/strict";
+import { test } from "node:test";
+import { render, screen } from "~test/ui";
+import { PulledList } from "./pulled-list.component";
+
+test("PulledList shows each item with how many times it was pulled", () => {
+ render(
+
,
+ );
+ assert.equal(screen.getAllByRole("listitem").length, 2);
+ assert.ok(screen.getByText("Redline"));
+ assert.ok(screen.getByText(/1,234/));
+});
+
+test("PulledList with no items has no rows", () => {
+ render(
);
+ assert.equal(screen.queryAllByRole("listitem").length, 0);
+});
diff --git a/src/components/rarity-picker/rarity-picker.config.ts b/src/components/rarity-picker/rarity-picker.config.ts
index 83381e55..f468f2e0 100644
--- a/src/components/rarity-picker/rarity-picker.config.ts
+++ b/src/components/rarity-picker/rarity-picker.config.ts
@@ -3,10 +3,10 @@ export const RARITY_PICKER = {
root: "flex items-center gap-2.5 text-muted-foreground",
group: "flex items-center gap-2",
option:
- "group relative size-[22px] rounded-full opacity-55 transition duration-150 hover:scale-110 hover:opacity-100 focus-visible:opacity-100 focus-visible:outline-2 focus-visible:outline-offset-[3px] focus-visible:outline-ring",
+ "group relative size-[22px] rounded-full opacity-55 transition duration-150 hover:scale-110 hover:opacity-100 focus-visible:opacity-100 focus-visible:outline-2 focus-visible:outline-offset-[3px] focus-visible:outline-accent-ink",
optionActive: "opacity-100 ring-2 ring-current ring-offset-2 ring-offset-background",
tooltip:
- "pointer-events-none absolute bottom-[130%] left-1/2 -translate-x-1/2 whitespace-nowrap z-10 rounded-md border bg-card px-2 py-1 text-[11px] text-foreground shadow-md opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100",
+ "pointer-events-none absolute bottom-[130%] left-1/2 -translate-x-1/2 whitespace-nowrap z-10 rounded-md border bg-card px-2 py-1 text-[11px] text-foreground border-border-strong opacity-0 transition-opacity group-hover:opacity-100 group-focus-visible:opacity-100",
current: "text-foreground",
},
keys: {
diff --git a/src/components/rarity-picker/rarity-picker.test.tsx b/src/components/rarity-picker/rarity-picker.test.tsx
new file mode 100644
index 00000000..b1279453
--- /dev/null
+++ b/src/components/rarity-picker/rarity-picker.test.tsx
@@ -0,0 +1,60 @@
+/* oxlint-disable typescript/no-floating-promises -- node:test registers suites synchronously */
+import assert from "node:assert/strict";
+import { describe, test } from "node:test";
+import { render, screen, setupUser } from "~test/ui";
+import { RarityPicker } from "./rarity-picker.component";
+
+const OPTIONS = [
+ { id: "a", label: "Consumer", color: "#999" },
+ { id: "b", label: "Industrial", color: "#59f" },
+ { id: "c", label: "Mil-spec", color: "#35f" },
+] as const;
+
+describe("RarityPicker", () => {
+ test("one radio per rarity with the value checked and in the tab order", () => {
+ render(
{}} />);
+ const radios = screen.getAllByRole("radio");
+ assert.equal(radios.length, 3);
+ assert.equal(
+ screen.getByRole("radio", { name: "Industrial" }).getAttribute("aria-checked"),
+ "true",
+ );
+ assert.equal(screen.getByRole("radio", { name: "Industrial" }).getAttribute("tabindex"), "0");
+ assert.equal(screen.getByRole("radio", { name: "Consumer" }).getAttribute("tabindex"), "-1");
+ });
+
+ test("click selects", async () => {
+ const picked: string[] = [];
+ render(
+ picked.push(id)}
+ />,
+ );
+ await setupUser().click(screen.getByRole("radio", { name: "Mil-spec" }));
+ assert.deepEqual(picked, ["c"]);
+ });
+
+ test("arrow keys move and wrap the selection", async () => {
+ const picked: string[] = [];
+ render(
+ picked.push(id)}
+ />,
+ );
+ const user = setupUser();
+ screen.getByRole("radio", { name: "Mil-spec" }).focus();
+ await user.keyboard("{ArrowRight}");
+ assert.deepEqual(picked, ["a"]);
+ });
+
+ test("the chosen rarity's name is shown", () => {
+ render( {}} />);
+ assert.ok(screen.getAllByText("Industrial").length >= 1);
+ });
+});
diff --git a/src/components/reveal/reveal.test.tsx b/src/components/reveal/reveal.test.tsx
new file mode 100644
index 00000000..ac19f74a
--- /dev/null
+++ b/src/components/reveal/reveal.test.tsx
@@ -0,0 +1,44 @@
+/* oxlint-disable typescript/no-floating-promises -- node:test registers suites synchronously */
+import assert from "node:assert/strict";
+import { afterEach, beforeEach, describe, mock, test } from "node:test";
+import { act, render, screen } from "~test/ui";
+import { Reveal } from "./reveal.component";
+import { REVEAL } from "./reveal.config";
+
+describe("Reveal", () => {
+ beforeEach(() => {
+ mock.timers.enable({ apis: ["setTimeout"] });
+ });
+ afterEach(() => {
+ mock.timers.reset();
+ });
+
+ test("open shows its content", () => {
+ render(hello);
+ assert.ok(screen.getByText("hello"));
+ });
+
+ test("closed from the start renders no content", () => {
+ render(hello);
+ assert.ok(screen.queryByText("hello") === null);
+ });
+
+ test("closing keeps the content until the transition is over, then removes it", async () => {
+ const { rerender, container } = render(hello);
+ rerender(hello);
+ assert.ok(screen.getByText("hello"));
+ const wrapper = container.firstElementChild as HTMLElement;
+ assert.equal(wrapper.getAttribute("aria-hidden"), "true");
+ assert.equal(wrapper.hasAttribute("inert"), true);
+ await act(async () => {
+ mock.timers.tick(REVEAL.durationMs);
+ });
+ assert.ok(screen.queryByText("hello") === null);
+ });
+
+ test("reopening brings the content back", () => {
+ const { rerender } = render(hello);
+ rerender(hello);
+ assert.ok(screen.getByText("hello"));
+ });
+});
diff --git a/src/components/root-error/root-error.test.tsx b/src/components/root-error/root-error.test.tsx
new file mode 100644
index 00000000..53e64362
--- /dev/null
+++ b/src/components/root-error/root-error.test.tsx
@@ -0,0 +1,30 @@
+/* oxlint-disable typescript/no-floating-promises -- node:test registers suites synchronously */
+import assert from "node:assert/strict";
+import { describe, test } from "node:test";
+import { render, screen } from "~test/ui";
+import { ROOT_ERROR } from "./root-error.config";
+import { RootError } from "./root-error.component";
+
+describe("RootError", () => {
+ test("is a labelled main landmark with a reload button", () => {
+ render();
+ assert.ok(screen.getByRole("main", { name: ROOT_ERROR.title }));
+ assert.ok(screen.getByRole("button", { name: ROOT_ERROR.reload }));
+ });
+
+ test("shows the message of an Error", () => {
+ render();
+ assert.ok(screen.getByText("kaput"));
+ });
+
+ test("shows a thrown string", () => {
+ render();
+ assert.ok(screen.getByText("plain text"));
+ });
+
+ test("shows no detail for other thrown values", () => {
+ const { container } = render();
+ assert.ok(!container.textContent?.includes("[object"));
+ assert.ok(screen.getByText(ROOT_ERROR.body));
+ });
+});
diff --git a/src/components/scheme-preview/scheme-preview.component.tsx b/src/components/scheme-preview/scheme-preview.component.tsx
index d8eba5f8..750354ca 100644
--- a/src/components/scheme-preview/scheme-preview.component.tsx
+++ b/src/components/scheme-preview/scheme-preview.component.tsx
@@ -82,9 +82,7 @@ function MiniUi({ variant }: MiniUiProps) {
diff --git a/src/components/scheme-preview/scheme-preview.config.ts b/src/components/scheme-preview/scheme-preview.config.ts
index 450bbf45..a1adcc78 100644
--- a/src/components/scheme-preview/scheme-preview.config.ts
+++ b/src/components/scheme-preview/scheme-preview.config.ts
@@ -5,8 +5,7 @@ export const SCHEME_PREVIEW = {
fade: {
text: 55,
muted: 22,
- tint: 28,
- tintEnd: 6,
+ tint: 14,
navIcon: 60,
navLabel: 32,
navLabelActive: 70,
diff --git a/src/components/scheme-preview/scheme-preview.test.tsx b/src/components/scheme-preview/scheme-preview.test.tsx
new file mode 100644
index 00000000..7c0e38fc
--- /dev/null
+++ b/src/components/scheme-preview/scheme-preview.test.tsx
@@ -0,0 +1,20 @@
+/* oxlint-disable typescript/no-floating-promises -- node:test registers suites synchronously */
+import assert from "node:assert/strict";
+import { test } from "node:test";
+import { PALETTE_LIST } from "~/lib/theme/palettes.config";
+import { render } from "~test/ui";
+import { SchemePreview } from "./scheme-preview.component";
+
+const PALETTE = PALETTE_LIST[0];
+if (!PALETTE) throw new Error("no palette");
+
+test("SchemePreview is a decorative mock-up in every mode", () => {
+ for (const mode of ["light", "dark", "split"] as const) {
+ const { container, unmount } = render(
+
,
+ );
+ assert.equal(container.firstElementChild?.getAttribute("aria-hidden"), "true");
+ assert.equal(container.textContent, "");
+ unmount();
+ }
+});
diff --git a/src/components/segmented-control/segmented-control.config.ts b/src/components/segmented-control/segmented-control.config.ts
index 89c105e3..0dad78ce 100644
--- a/src/components/segmented-control/segmented-control.config.ts
+++ b/src/components/segmented-control/segmented-control.config.ts
@@ -1,6 +1,8 @@
export const SEGMENTED_CONTROL = {
- groupClass: "inline-flex h-8 rounded-md bg-muted p-0.5 max-sm:h-10",
+ groupClass: "inline-flex h-8 gap-0.5 rounded-md border border-control p-0.5 max-sm:h-10",
buttonClass:
- "flex items-center justify-center rounded border border-transparent px-3 text-xs text-muted-foreground transition-colors hover:text-foreground max-sm:min-w-10",
- activeClass: "bg-card font-medium text-foreground shadow-sm",
+ "flex items-center justify-center rounded-sm border border-transparent px-2.5 text-xs whitespace-nowrap text-muted-foreground transition-colors hover:bg-muted hover:text-foreground max-sm:min-w-10",
+ /** The selected segment is the control's only lime fill. */
+ activeClass:
+ "border-accent-edge bg-accent font-semibold text-accent-foreground hover:bg-accent hover:text-accent-foreground",
} as const;
diff --git a/src/components/segmented-control/segmented-control.test.tsx b/src/components/segmented-control/segmented-control.test.tsx
new file mode 100644
index 00000000..1980214f
--- /dev/null
+++ b/src/components/segmented-control/segmented-control.test.tsx
@@ -0,0 +1,59 @@
+/* oxlint-disable typescript/no-floating-promises -- node:test registers suites synchronously */
+import assert from "node:assert/strict";
+import { describe, test } from "node:test";
+import { render, screen, setupUser } from "~test/ui";
+import { SegmentedControl } from "./segmented-control.component";
+
+const OPTIONS = [
+ { id: "a", label: "Alpha" },
+ { id: "b", label: "Bravo" },
+ { id: "c", label: "Charlie" },
+] as const;
+
+describe("SegmentedControl", () => {
+ test("is a labelled radio group with the value checked", () => {
+ render(
{}} />);
+ assert.ok(screen.getByRole("radiogroup", { name: "Mode" }));
+ assert.equal(screen.getByRole("radio", { name: "Bravo" }).getAttribute("aria-checked"), "true");
+ assert.equal(
+ screen.getByRole("radio", { name: "Alpha" }).getAttribute("aria-checked"),
+ "false",
+ );
+ });
+
+ test("only the checked radio is in the tab order", () => {
+ render( {}} />);
+ assert.equal(screen.getByRole("radio", { name: "Bravo" }).getAttribute("tabindex"), "0");
+ assert.equal(screen.getByRole("radio", { name: "Alpha" }).getAttribute("tabindex"), "-1");
+ });
+
+ test("click selects", async () => {
+ const picked: string[] = [];
+ render(
+ picked.push(id)}
+ />,
+ );
+ await setupUser().click(screen.getByRole("radio", { name: "Charlie" }));
+ assert.deepEqual(picked, ["c"]);
+ });
+
+ test("arrow keys move the selection and wrap", async () => {
+ const picked: string[] = [];
+ render(
+ picked.push(id)}
+ />,
+ );
+ const user = setupUser();
+ screen.getByRole("radio", { name: "Charlie" }).focus();
+ await user.keyboard("{ArrowRight}");
+ assert.deepEqual(picked, ["a"]);
+ });
+});
diff --git a/src/components/select/select.component.tsx b/src/components/select/select.component.tsx
index f8eb8d5d..5c353936 100644
--- a/src/components/select/select.component.tsx
+++ b/src/components/select/select.component.tsx
@@ -203,15 +203,11 @@ export function Select({
// Focusable, so a click on the search row's padding keeps focus inside instead of closing.
tabIndex={-1}
onKeyDown={onListKeyDown}
- className="fixed z-50 flex flex-col overflow-hidden rounded-md border bg-card text-foreground shadow-lg outline-none"
+ className={SELECT.classes.popover}
>
{searchable && (
-
-
+
+
0 ? `${id}-${highlight}` : undefined}
- className="no-focus-ring min-w-0 flex-1 bg-transparent outline-none placeholder:text-muted-foreground"
+ className={SELECT.classes.searchInput}
/>
)}
@@ -235,7 +231,7 @@ export function Select({
aria-label={ariaLabel}
aria-activedescendant={visible.length > 0 ? `${id}-${highlight}` : undefined}
style={{ maxHeight: placement.maxHeight }}
- className="no-focus-ring overflow-y-auto p-1 outline-none"
+ className={SELECT.classes.list}
>
{visible.map((option, index) => (
- setHighlight(index)}
onClick={() => choose(option)}
className={cn(
- "flex cursor-pointer items-center gap-2 rounded px-2 py-1.5",
- index === highlight && "bg-muted",
- option.disabled && "cursor-not-allowed opacity-50",
+ SELECT.classes.option,
+ index === highlight && SELECT.classes.optionActive,
+ option.id === value && SELECT.classes.optionSelected,
+ option.disabled && SELECT.classes.optionDisabled,
)}
>
{option.leading}
{option.label}
- {option.hint && (
-
- {option.hint}
-
- )}
+ {option.hint && {option.hint}}
- {option.detail && (
-
- {option.detail}
-
- )}
+ {option.detail && {option.detail}}
))}
- {visible.length === 0 && (
-
- {SELECT.noMatches}
- )}
+ {visible.length === 0 &&
- {SELECT.noMatches}
}
)}
diff --git a/src/components/select/select.config.ts b/src/components/select/select.config.ts
index 961d9733..ff579d4e 100644
--- a/src/components/select/select.config.ts
+++ b/src/components/select/select.config.ts
@@ -6,10 +6,28 @@ export const SELECT = {
iconSize: 14,
/** A square, touch-sized button that opens the list when the trigger is only an icon. */
iconTriggerClass:
- "grid size-8 shrink-0 place-items-center rounded-md text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:border-primary aria-expanded:bg-muted aria-expanded:text-foreground disabled:pointer-events-none disabled:opacity-50 max-sm:size-9",
+ "grid size-8 shrink-0 place-items-center rounded-md text-muted-foreground transition-colors hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground disabled:pointer-events-none disabled:opacity-50 max-sm:size-9",
fieldTriggerClass:
- "flex h-8 w-full items-center justify-between gap-2 rounded-md border border-input bg-card pl-3 pr-2 text-left text-foreground outline-none transition-colors hover:bg-muted focus-visible:border-primary disabled:pointer-events-none disabled:opacity-50 max-sm:h-9",
+ "flex h-8 w-full items-center justify-between gap-2 rounded-md border border-control bg-background pl-2.5 pr-2 text-left text-foreground transition-colors hover:bg-muted disabled:pointer-events-none disabled:opacity-45 max-sm:h-9",
triggerIconSize: 16,
+ classes: {
+ popover:
+ "fixed z-50 flex flex-col overflow-hidden rounded-md border border-border-strong bg-card text-foreground outline-none",
+ searchRow: "flex h-9 shrink-0 items-center gap-2 border-b px-2.5",
+ searchIcon: "shrink-0 text-muted-foreground",
+ searchInput:
+ "no-focus-ring min-w-0 flex-1 bg-transparent outline-none placeholder:text-muted-foreground",
+ list: "no-focus-ring overflow-y-auto p-1 outline-none",
+ option: "flex min-h-8 cursor-pointer items-center gap-2 rounded-sm px-2 py-1",
+ optionActive: "bg-muted",
+ /** The chosen option: ink tick and semibold, so it reads without colour. */
+ optionSelected: "font-semibold",
+ optionDisabled: "cursor-not-allowed opacity-45",
+ check: "shrink-0 text-accent-ink",
+ hint: "block truncate text-xs text-muted-foreground",
+ detail: "shrink-0 font-mono text-[11px] tabular-nums text-muted-foreground",
+ empty: "px-2 py-1.5 text-muted-foreground",
+ },
gap: 6,
viewportMargin: 8,
maxListHeight: 280,
diff --git a/src/components/select/select.test.tsx b/src/components/select/select.test.tsx
new file mode 100644
index 00000000..0060e215
--- /dev/null
+++ b/src/components/select/select.test.tsx
@@ -0,0 +1,182 @@
+/* oxlint-disable typescript/no-floating-promises -- node:test registers suites synchronously */
+import assert from "node:assert/strict";
+import { describe, test } from "node:test";
+import { ArrowLeftRight } from "lucide-react";
+import { render, screen, setupUser, within } from "~test/ui";
+import { Select } from "./select.component";
+import { SELECT } from "./select.config";
+import type { SelectOption } from "./select.types";
+
+const FEW: readonly SelectOption[] = [
+ { id: "a", label: "Alpha", detail: "3" },
+ { id: "b", label: "Bravo", hint: "second" },
+ { id: "c", label: "Charlie", disabled: true },
+];
+
+const MANY: readonly SelectOption[] = Array.from(
+ { length: SELECT.searchThreshold + 3 },
+ (_, index) => ({
+ id: `id-${index}`,
+ label: `Option ${index}`,
+ }),
+);
+
+function mount(
+ options: readonly SelectOption[],
+ value: string,
+ onChange: (id: string) => void = () => {},
+) {
+ return render();
+}
+
+describe("Select", () => {
+ test("the trigger is a collapsed combobox showing the chosen label", () => {
+ mount(FEW, "b");
+ const trigger = screen.getByRole("combobox", { name: "Pick" });
+ assert.equal(trigger.getAttribute("aria-expanded"), "false");
+ assert.equal(trigger.getAttribute("aria-haspopup"), "listbox");
+ assert.ok(trigger.textContent?.includes("Bravo"));
+ assert.ok(screen.queryByRole("listbox") === null);
+ });
+
+ test("triggerLabel and triggerDetail show in the trigger, not the list label", () => {
+ mount(
+ [{ id: "a", label: "Long full name", triggerLabel: "Short", triggerDetail: "…1234" }],
+ "a",
+ );
+ const trigger = screen.getByRole("combobox");
+ assert.ok(trigger.textContent?.includes("Short"));
+ assert.ok(trigger.textContent?.includes("…1234"));
+ assert.ok(!trigger.textContent?.includes("Long full name"));
+ });
+
+ test("clicking opens a listbox of options with the value selected", async () => {
+ mount(FEW, "b");
+ await setupUser().click(screen.getByRole("combobox"));
+ assert.equal(screen.getByRole("combobox").getAttribute("aria-expanded"), "true");
+ const options = within(screen.getByRole("listbox", { name: "Pick" })).getAllByRole("option");
+ assert.equal(options.length, FEW.length);
+ assert.equal(
+ screen.getByRole("option", { name: /Bravo/ }).getAttribute("aria-selected"),
+ "true",
+ );
+ assert.equal(
+ screen.getByRole("option", { name: /Alpha/ }).getAttribute("aria-selected"),
+ "false",
+ );
+ });
+
+ test("choosing an option reports it, closes the list and refocuses the trigger", async () => {
+ const picked: string[] = [];
+ mount(FEW, "a", (id) => picked.push(id));
+ const user = setupUser();
+ await user.click(screen.getByRole("combobox"));
+ await user.click(screen.getByRole("option", { name: /Bravo/ }));
+ assert.deepEqual(picked, ["b"]);
+ assert.ok(screen.queryByRole("listbox") === null);
+ assert.equal(document.activeElement, screen.getByRole("combobox"));
+ });
+
+ test("a disabled option cannot be chosen", async () => {
+ const picked: string[] = [];
+ mount(FEW, "a", (id) => picked.push(id));
+ const user = setupUser();
+ await user.click(screen.getByRole("combobox"));
+ const disabled = screen.getByRole("option", { name: /Charlie/ });
+ assert.equal(disabled.getAttribute("aria-disabled"), "true");
+ await user.click(disabled);
+ assert.deepEqual(picked, []);
+ assert.ok(screen.getByRole("listbox"));
+ });
+
+ test("a disabled select does not open", async () => {
+ render(