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
34 changes: 33 additions & 1 deletion apps/web/src/components/Sidebar.logic.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { describe, expect, it } from "vitest";

import { hasUnseenCompletion, resolveThreadStatusPill } from "./Sidebar.logic";
import {
hasUnseenCompletion,
resolveThreadStatusPill,
shouldClearThreadSelectionOnMouseDown,
} from "./Sidebar.logic";

function makeLatestTurn(overrides?: {
completedAt?: string | null;
Expand Down Expand Up @@ -30,6 +34,34 @@ describe("hasUnseenCompletion", () => {
});
});

describe("shouldClearThreadSelectionOnMouseDown", () => {
it("preserves selection for thread items", () => {
const child = {
closest: (selector: string) =>
selector.includes("[data-thread-item]") ? ({} as Element) : null,
} as unknown as HTMLElement;

expect(shouldClearThreadSelectionOnMouseDown(child)).toBe(false);
});

it("preserves selection for thread list toggle controls", () => {
const selectionSafe = {
closest: (selector: string) =>
selector.includes("[data-thread-selection-safe]") ? ({} as Element) : null,
} as unknown as HTMLElement;

expect(shouldClearThreadSelectionOnMouseDown(selectionSafe)).toBe(false);
});

it("clears selection for unrelated sidebar clicks", () => {
const unrelated = {
closest: () => null,
} as unknown as HTMLElement;

expect(shouldClearThreadSelectionOnMouseDown(unrelated)).toBe(true);
});
});

describe("resolveThreadStatusPill", () => {
const baseThread = {
interactionMode: "plan" as const,
Expand Down
8 changes: 8 additions & 0 deletions apps/web/src/components/Sidebar.logic.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import type { Thread } from "../types";
import { findLatestProposedPlan, isLatestTurnSettled } from "../session-logic";

export const THREAD_SELECTION_SAFE_SELECTOR =
"[data-thread-item], [data-thread-selection-safe]";

export interface ThreadStatusPill {
label:
| "Working"
Expand Down Expand Up @@ -30,6 +33,11 @@ export function hasUnseenCompletion(thread: ThreadStatusInput): boolean {
return completedAt > lastVisitedAt;
}

export function shouldClearThreadSelectionOnMouseDown(target: HTMLElement | null): boolean {
if (target === null) return true;
return !target.closest(THREAD_SELECTION_SAFE_SELECTOR);
}

export function resolveThreadStatusPill(input: {
thread: ThreadStatusInput;
hasPendingApprovals: boolean;
Expand Down
Loading