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
31 changes: 26 additions & 5 deletions apps/app/src/components/commands/CommandPalette.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const testState = vi.hoisted(() => ({
const modeState = vi.hoisted(() => ({
activeRecents: [] as ThreadListEntry[],
archivedRecents: [] as ThreadListEntry[],
archivedRecentsEnabled: false,
threadDraftIds: new Set<string>(),
searchResponse: undefined as ThreadSearchResponse | undefined,
recentLoading: false,
Expand Down Expand Up @@ -243,11 +244,14 @@ vi.mock("@/hooks/queries/sidebar-navigation-query", () => ({
}));

vi.mock("@/hooks/queries/palette-thread-queries", () => ({
usePaletteRecentArchivedThreads: () => ({
data: modeState.archivedRecents,
isLoading: false,
isError: false,
}),
usePaletteRecentArchivedThreads: ({ enabled }: { enabled: boolean }) => {
modeState.archivedRecentsEnabled = enabled;
return {
data: modeState.archivedRecents,
isLoading: false,
isError: false,
};
},
}));

vi.mock("@/hooks/queries/thread-queries", async (importOriginal) => {
Expand Down Expand Up @@ -414,6 +418,7 @@ afterEach(() => {
testState.plugins.length = 0;
modeState.activeRecents = [];
modeState.archivedRecents = [];
modeState.archivedRecentsEnabled = false;
modeState.threadDraftIds.clear();
modeState.searchResponse = undefined;
modeState.recentLoading = false;
Expand Down Expand Up @@ -1109,6 +1114,22 @@ describe("CommandPalette", () => {
);
});

it("loads archived recents only while Archived is selected and the query is empty", async () => {
const { store } = renderPalette();
openThreadSearch();
await screen.findByRole("combobox", { name: "Search threads" });
expect(modeState.archivedRecentsEnabled).toBe(false);

act(() => store.set(paletteThreadLifecyclesAtom, ["active", "archived"]));
expect(modeState.archivedRecentsEnabled).toBe(true);

fireEvent.change(searchField(), { target: { value: "match" } });
expect(modeState.archivedRecentsEnabled).toBe(false);

fireEvent.change(searchField(), { target: { value: " " } });
expect(modeState.archivedRecentsEnabled).toBe(true);
});

it("operates the lifecycle filter with the keyboard without selecting a result", async () => {
modeState.activeRecents = [makeThread("active")];
const { store } = renderPalette();
Expand Down
115 changes: 81 additions & 34 deletions apps/app/src/components/plugin/theme-preview-fixture-anatomy.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
import { describe, expect, it } from "vitest";
import {
SIDEBAR_ROW_INTERACTIVE_STATE_CLASS,
SIDEBAR_ROW_OPEN_IN_SPLIT_STATE_CLASS,
SIDEBAR_ROW_SELECTED_STATE_CLASS,
} from "@bb/shared-ui/sidebar-row-classes";

const REPO_ROOT = resolve(import.meta.dirname, "../../../../..");
const THEME_PREVIEW_TAXONOMY = resolve(
Expand All @@ -10,28 +15,62 @@ const THEME_PREVIEW_TAXONOMY = resolve(

interface FixtureAnchor {
file: string;
mustContain: readonly string[];
mustContain?: readonly string[];
classLists?: readonly (readonly string[])[];
because: string;
}

const SHARED_FIXTURE_ANCHORS: readonly FixtureAnchor[] = [
const MOCK_ROW_CLASS_CONTRACTS = [
{
file: "apps/app/src/components/ui/sidebar.tsx",
mustContain: ["fixed inset-y-0", "bg-sidebar text-sidebar-foreground"],
because:
"The mock sidebar carries `fixed bg-sidebar` so theme blocks scoped to `.fixed.bg-sidebar` (token overrides, noise overlays) apply to it exactly as they do in the app.",
name: "SIDEBAR_ROW_INTERACTIVE_STATE_CLASS",
value: SIDEBAR_ROW_INTERACTIVE_STATE_CLASS,
classes: [
"hover:bg-sidebar-accent",
"hover:text-sidebar-accent-foreground",
],
},
{
file: "packages/shared-ui/src/components/ui/sidebar-row-classes.ts",
mustContain: [
"SIDEBAR_ROW_BASE_CLASS =",
"SIDEBAR_ROW_INTERACTIVE_STATE_CLASS =",
"hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
"SIDEBAR_ROW_SELECTED_STATE_CLASS =",
"SIDEBAR_ROW_OPEN_IN_SPLIT_STATE_CLASS =",
name: "SIDEBAR_ROW_SELECTED_STATE_CLASS",
value: SIDEBAR_ROW_SELECTED_STATE_CLASS,
classes: [
"bg-state-active",
"bb-sidebar-selected-row",
"text-sidebar-foreground",
],
},
{
name: "SIDEBAR_ROW_OPEN_IN_SPLIT_STATE_CLASS",
value: SIDEBAR_ROW_OPEN_IN_SPLIT_STATE_CLASS,
classes: ["bb-sidebar-open-in-split-row"],
},
] as const;

const MIRROR_NOTE =
"Theme Preview's mock (plugins/theme-preview/app.tsx) mirrors this, so update it together with this anchor.";

const STRING_LITERAL_PATTERNS = [/"([^"\n]*)"/g, /'([^'\n]*)'/g, /`([^`]*)`/g];

function sourceClassLists(source: string): Set<string>[] {
return STRING_LITERAL_PATTERNS.flatMap((pattern) =>
Array.from(
source.matchAll(pattern),
(match) => new Set(match[1].split(/\s+/)),
),
);
}

function hasClassList(source: string, classes: readonly string[]): boolean {
return sourceClassLists(source).some((tokens) =>
classes.every((token) => tokens.has(token)),
);
}

const SHARED_FIXTURE_ANCHORS: readonly FixtureAnchor[] = [
{
file: "apps/app/src/components/ui/sidebar.tsx",
classLists: [["fixed", "bg-sidebar", "text-sidebar-foreground"]],
because:
"Mock thread and settings rows keep BB's shared row geometry and rest, hover, selected, and split states.",
"The mock sidebar carries `fixed bg-sidebar` so theme blocks scoped to `.fixed.bg-sidebar` (token overrides, noise overlays) apply to it exactly as they do in the app.",
},
{
file: "apps/app/src/components/sidebar/SectionSidebar.tsx",
Expand All @@ -44,11 +83,6 @@ const SHARED_FIXTURE_ANCHORS: readonly FixtureAnchor[] = [
because:
"Mock sidebars use BB's shared button primitive, section-label token, padding, and project-row anatomy.",
},
{
file: "packages/shared-ui/src/components/ui/context-selection.ts",
mustContain: ['CONTEXT_SELECTION_SURFACE_CLASS = "bg-state-active"'],
because: "The open thread's row in the mock paints state-active.",
},
{
file: "apps/app/src/components/ui/theme.css",
mustContain: [
Expand Down Expand Up @@ -141,8 +175,8 @@ const VIEW_FIXTURE_ANCHORS: Record<string, readonly FixtureAnchor[]> = {
'aria-label="Thread table of contents"',
'label="Agent messages"',
'label="Your messages"',
"bg-popover",
],
classLists: [["bg-popover"]],
because:
"The held-open fixture keeps the real message-role tabs and popover surface.",
},
Expand All @@ -155,8 +189,7 @@ const VIEW_FIXTURE_ANCHORS: Record<string, readonly FixtureAnchor[]> = {
{
file: "plugins/git/ui/info/GitInfoRows.tsx",
mustContain: ['<DetailRow icon="GitBranch"'],
because:
"The open Info panel's branch row comes from the Git plugin.",
because: "The open Info panel's branch row comes from the Git plugin.",
},
{
file: "plugins/github-pr-status/ui/PullRequestInfoRow.tsx",
Expand All @@ -178,16 +211,14 @@ const VIEW_FIXTURE_ANCHORS: Record<string, readonly FixtureAnchor[]> = {
new: [
{
file: "apps/app/src/views/RootComposeView.tsx",
mustContain: [
'ROOT_COMPOSE_SIDEBAR_ACTION_ALIGNED_TOP_PADDING_CLASS = "pt-14"',
"{promptBox}",
],
mustContain: ["{promptBox}"],
classLists: [["pt-14"]],
because:
"The New thread projection opens on the composer alone, aligned under the sidebar actions.",
},
{
file: "apps/app/src/views/RootComposeHome.tsx",
mustContain: ['ROOT_COMPOSE_MAX_WIDTH_CLASS = "max-w-[760px]"'],
classLists: [["max-w-[760px]"]],
because: "The New thread projection keeps BB's home column width.",
},
{
Expand All @@ -204,9 +235,9 @@ const VIEW_FIXTURE_ANCHORS: Record<string, readonly FixtureAnchor[]> = {
"data-split-pane-id",
"data-focused",
"data-pane-focus-scrim",
'"bg-background/30"',
"<SplitDivider",
],
classLists: [["bg-background/30"]],
because:
"The Split projection keeps BB's pane identity, focus state, divider, and inactive-pane wash.",
},
Expand Down Expand Up @@ -241,10 +272,10 @@ const VIEW_FIXTURE_ANCHORS: Record<string, readonly FixtureAnchor[]> = {
},
{
file: "apps/app/src/components/ui/settings-section.tsx",
mustContain: [
"rounded-lg border border-border bg-card px-4 py-3.5",
"flex flex-col gap-2.5",
"text-xs leading-snug text-subtle-foreground/75",
classLists: [
["rounded-lg", "border", "border-border", "bg-card", "px-4", "py-3.5"],
["flex-col", "gap-2.5"],
["text-xs", "leading-snug", "text-subtle-foreground/75"],
],
because:
"The Appearance projection keeps BB's section card, responsive rows, and supporting-copy hierarchy.",
Expand Down Expand Up @@ -285,15 +316,31 @@ describe("Theme Preview fixture anatomy", () => {
}
});

it("keeps the shared sidebar row states the mock rows copy", () => {
for (const contract of MOCK_ROW_CLASS_CONTRACTS) {
expect(
contract.value.split(/\s+/),
`Mock thread and settings rows copy BB's shared hover, selected, and split row states.\n${MIRROR_NOTE}\nExpected ${contract.name} to include: ${contract.classes.join(" ")}`,
).toEqual(expect.arrayContaining([...contract.classes]));
}
});

for (const anchor of FIXTURE_ANCHORS) {
it(`still matches ${anchor.file}`, () => {
const source = readFileSync(resolve(REPO_ROOT, anchor.file), "utf8");
for (const needle of anchor.mustContain) {
const mirrorNote = `${anchor.because}\n${MIRROR_NOTE}`;
for (const needle of anchor.mustContain ?? []) {
expect(
source,
`${anchor.because}\nTheme Preview's mock (plugins/theme-preview/app.tsx) mirrors this, so update it together with this anchor.\nExpected ${anchor.file} to contain: ${needle}`,
`${mirrorNote}\nExpected ${anchor.file} to contain: ${needle}`,
).toContain(needle);
}
for (const classes of anchor.classLists ?? []) {
expect(
hasClassList(source, classes),
`${mirrorNote}\nExpected one class list in ${anchor.file} to include, in any order: ${classes.join(" ")}`,
).toBe(true);
}
});
}
});
41 changes: 24 additions & 17 deletions apps/app/src/components/promptbox/banner/ProviderCliBanner.test.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
// @vitest-environment jsdom

import { cleanup, render, screen } from "@testing-library/react";
import type { ComponentProps } from "react";
import { renderToStaticMarkup } from "react-dom/server";
import { describe, expect, it } from "vitest";
import { afterEach, describe, expect, it } from "vitest";
import { ProviderCliBanner } from "./ProviderCliBanner";

afterEach(() => {
cleanup();
});

function renderBanner(
props: Omit<ComponentProps<typeof ProviderCliBanner>, "onAction">,
) {
const markup = renderToStaticMarkup(
<ProviderCliBanner {...props} onAction={() => {}} />,
);
render(<ProviderCliBanner {...props} onAction={() => {}} />);
return {
markup,
text: markup.replace(/<[^>]+>/g, ""),
button: markup.match(/<button([^>]*)>(.*?)<\/button>/),
text: screen.getByRole("alert").textContent,
button: screen.getByRole("button"),
};
}

describe("ProviderCliBanner", () => {
it("uses the selected provider's identity and update requirement", () => {
const { markup, text, button } = renderBanner({
const { text, button } = renderBanner({
displayName: "Example Agent",
installed: true,
currentVersion: "0.135.0",
Expand All @@ -27,12 +30,14 @@ describe("ProviderCliBanner", () => {
actionRunning: false,
});

expect(markup).toContain('aria-label="Example Agent update required"');
expect(
screen.getByRole("region", { name: "Example Agent update required" }),
).toBeTruthy();
expect(text).toContain(
"Update Example Agent before starting a thread. Installed 0.135.0; version 0.136.0 or newer is required.",
);
expect(button?.[2]).toBe("Update Example Agent");
expect(button?.[1]).not.toContain('disabled=""');
expect(button.textContent).toBe("Update Example Agent");
expect(button.hasAttribute("disabled")).toBe(false);
});

it("shows update progress without repeating an ambiguous version fallback", () => {
Expand All @@ -46,12 +51,12 @@ describe("ProviderCliBanner", () => {
});

expect(text).toContain("Installed 0.135.0; a newer version is required.");
expect(button?.[2]).toContain("Updating…");
expect(button?.[1]).toContain('disabled=""');
expect(button.textContent).toContain("Updating…");
expect(button.hasAttribute("disabled")).toBe(true);
});

it("asks for an install instead of a version when the CLI is missing", () => {
const { markup, text, button } = renderBanner({
const { text, button } = renderBanner({
displayName: "Claude Code",
installed: false,
currentVersion: null,
Expand All @@ -60,9 +65,11 @@ describe("ProviderCliBanner", () => {
actionRunning: false,
});

expect(markup).toContain('aria-label="Claude Code not installed"');
expect(
screen.getByRole("region", { name: "Claude Code not installed" }),
).toBeTruthy();
expect(text).toContain("Install Claude Code before starting a thread.");
expect(text).not.toContain("version");
expect(button?.[2]).toBe("Install Claude Code");
expect(button.textContent).toBe("Install Claude Code");
});
});
Loading
Loading