Build App / compute-version (pull_request) Successful in 4s
Build App / build-macos (pull_request) Successful in 2m30s
Build App / build-linux (pull_request) Successful in 5m11s
Build App / build-windows (pull_request) Successful in 5m23s
Build App / create-tag (pull_request) Skipped
Build App / sync-to-github (pull_request) Skipped
Ten findings from the review of the previous commit, all applied. **The tab drag is now pointer events, not HTML5 drag-and-drop.** Two independent reasons, either one fatal. Tauri's `dragDropEnabled` blocks HTML5 drag inside the webview on Windows, and it cannot just be turned off — `TerminalView` needs Tauri's native drag-drop event, which is the only one that carries dropped *file paths*. And an HTML5 drag carries a `DataTransfer`: released over any text field in the app, the default handler types `term:<uuid>` into it, and in Config that is then saved with the project. Pointer events have neither problem, and the drag is measured from the tabs on screen rather than from the event target, so the marker and the drop agree even over the marker itself. Escape abandons a drag; a press under 4px stays a click; the click that ends a drag does not select. **`Ctrl+Shift+←/→` no longer swallows word-wise selection.** It is bound on `document` in the capture phase, so in any input — the rename field, Config, Settings — it was taking the OS's extend-selection chord *and* silently reordering the strip. Guarded by `inTextField()`, which excludes xterm's helper textarea: that is an input-method shim, and the terminal is where the shortcut matters most. **The pop-out's state is read from the window, never remembered.** The pane is unmounted whenever another Project Home sub-tab is selected, so "Keep on top" came back Off over a window still floating on top. `get_browser_view_popout_state` returns both facts from the window itself, and the change event carries them. `poppedOut` is tri-state: until the answer arrives the iframe is not mounted, because guessing "not popped out" is what flashes a second viewer onto the browser. Also: `popout::close` and the off-status emit in the supervisor are behind the same epoch guard as the deregistration above them, so a supervisor whose teardown outlives a restart can no longer destroy the *new* session's window; `close()` returns its `destroy()` error instead of logging it and reporting success, since the pane restores its iframe on success; the drop marker is `pointer-events-none` and is placed before the first *visible* tab at or past the slot, so it neither refuses a drop nor vanishes when a `tabOrder` entry renders nothing; and the "Keep on top" Toggle's accessible name now matches its visible text. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
215 lines
6.3 KiB
TypeScript
215 lines
6.3 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { fireEvent, render, screen } from "@testing-library/react";
|
|
import MainTabs from "./MainTabs";
|
|
import { useAppState, homeTabKey, terminalTabKey } from "../../store/appState";
|
|
import type { Project, TerminalSession } from "../../lib/types";
|
|
|
|
const close = vi.fn();
|
|
|
|
const sessions: TerminalSession[] = [
|
|
{
|
|
id: "s1",
|
|
projectId: "p1",
|
|
projectName: "api-server",
|
|
sessionName: "claude",
|
|
sessionType: "claude",
|
|
},
|
|
{
|
|
id: "s2",
|
|
projectId: "p1",
|
|
projectName: "api-server",
|
|
sessionName: "shell",
|
|
sessionType: "bash",
|
|
},
|
|
] as unknown as TerminalSession[];
|
|
|
|
const projects: Project[] = [
|
|
{
|
|
id: "p1",
|
|
name: "api-server",
|
|
status: "running",
|
|
permission_mode: "bypass",
|
|
renamed_session_names: {},
|
|
},
|
|
] as unknown as Project[];
|
|
|
|
vi.mock("../../hooks/useTerminal", () => ({
|
|
useTerminal: () => ({ sessions, close }),
|
|
}));
|
|
vi.mock("../../hooks/useProjects", () => ({
|
|
useProjects: () => ({ projects, update: vi.fn() }),
|
|
}));
|
|
|
|
const HOME = homeTabKey("p1");
|
|
const S1 = terminalTabKey("s1");
|
|
const S2 = terminalTabKey("s2");
|
|
|
|
/**
|
|
* A pointer event carrying a real `clientX`.
|
|
*
|
|
* jsdom implements no `PointerEvent`, so Testing Library's synthesized one has
|
|
* no coordinates — and the coordinate is the whole point here, since it decides
|
|
* which slot the drop lands in. `MouseEvent` has one, and React dispatches on
|
|
* the event's type name either way.
|
|
*/
|
|
function pointer(el: Element, type: string, clientX: number) {
|
|
fireEvent(el, new MouseEvent(type, { bubbles: true, cancelable: true, clientX, button: 0 }));
|
|
}
|
|
|
|
/** Press, move past the drag threshold, and release over `endX`. */
|
|
function dragTab(el: Element, fromX: number, endX: number) {
|
|
pointer(el, "pointerdown", fromX);
|
|
pointer(el, "pointermove", endX);
|
|
pointer(el, "pointerup", endX);
|
|
}
|
|
|
|
/** Pin a tab's geometry so "past the midpoint" means something in jsdom. */
|
|
function place(el: Element, left: number, width = 100) {
|
|
el.getBoundingClientRect = () =>
|
|
({ left, width, right: left + width, top: 0, bottom: 30, height: 30, x: left, y: 0 }) as DOMRect;
|
|
}
|
|
|
|
/** Lay the strip out as three 100px tabs starting at x=0. */
|
|
function laidOut() {
|
|
const tabs = screen.getAllByRole("tab");
|
|
tabs.forEach((tab, i) => place(tab, i * 100));
|
|
return tabs;
|
|
}
|
|
|
|
const order = () => useAppState.getState().tabOrder;
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
useAppState.setState({
|
|
tabOrder: [HOME, S1, S2],
|
|
activeTabKey: HOME,
|
|
activeSessionId: null,
|
|
projects,
|
|
});
|
|
});
|
|
|
|
describe("MainTabs reordering", () => {
|
|
it("drags a tab to the front", () => {
|
|
render(<MainTabs />);
|
|
const tabs = laidOut();
|
|
|
|
// Left half of the first tab — the tab lands before it.
|
|
dragTab(tabs[2], 250, 10);
|
|
|
|
expect(order()).toEqual([S2, HOME, S1]);
|
|
});
|
|
|
|
it("drops after the tab when the pointer is past its midpoint", () => {
|
|
render(<MainTabs />);
|
|
const tabs = laidOut();
|
|
|
|
dragTab(tabs[0], 50, 190);
|
|
|
|
expect(order()).toEqual([S1, HOME, S2]);
|
|
});
|
|
|
|
it("drops at the end when released past the last tab", () => {
|
|
render(<MainTabs />);
|
|
const tabs = laidOut();
|
|
|
|
dragTab(tabs[0], 50, 800);
|
|
|
|
expect(order()).toEqual([S1, S2, HOME]);
|
|
});
|
|
|
|
it("dragging does not steal the selection", () => {
|
|
render(<MainTabs />);
|
|
const tabs = laidOut();
|
|
|
|
dragTab(tabs[1], 150, 290);
|
|
|
|
expect(order()).toEqual([HOME, S2, S1]);
|
|
expect(useAppState.getState().activeTabKey).toBe(HOME);
|
|
});
|
|
|
|
it("shows the drop marker only while a drag is under way", () => {
|
|
render(<MainTabs />);
|
|
const tabs = laidOut();
|
|
expect(screen.queryByTestId("tab-drop-marker")).toBeNull();
|
|
|
|
pointer(tabs[2], "pointerdown", 250);
|
|
pointer(tabs[2], "pointermove", 10);
|
|
expect(screen.getByTestId("tab-drop-marker")).toBeInTheDocument();
|
|
|
|
pointer(tabs[2], "pointerup", 10);
|
|
expect(screen.queryByTestId("tab-drop-marker")).toBeNull();
|
|
});
|
|
|
|
it("abandons the drag on Escape, leaving the order alone", () => {
|
|
render(<MainTabs />);
|
|
const tabs = laidOut();
|
|
|
|
pointer(tabs[2], "pointerdown", 250);
|
|
pointer(tabs[2], "pointermove", 10);
|
|
fireEvent.keyDown(window, { key: "Escape" });
|
|
|
|
expect(screen.queryByTestId("tab-drop-marker")).toBeNull();
|
|
pointer(tabs[2], "pointerup", 10);
|
|
expect(order()).toEqual([HOME, S1, S2]);
|
|
});
|
|
|
|
it("treats a press that barely moves as a click, not a drag", () => {
|
|
render(<MainTabs />);
|
|
const tabs = laidOut();
|
|
|
|
// Two pixels of tremble, under the threshold.
|
|
pointer(tabs[2], "pointerdown", 250);
|
|
pointer(tabs[2], "pointermove", 252);
|
|
pointer(tabs[2], "pointerup", 252);
|
|
fireEvent.click(tabs[2]);
|
|
|
|
expect(order()).toEqual([HOME, S1, S2]);
|
|
expect(useAppState.getState().activeTabKey).toBe(S2);
|
|
});
|
|
|
|
it("does not select the tab it just dropped", () => {
|
|
render(<MainTabs />);
|
|
const tabs = laidOut();
|
|
|
|
dragTab(tabs[2], 250, 10);
|
|
// The browser fires a click after the pointerup that ended the drag.
|
|
fireEvent.click(tabs[2]);
|
|
|
|
expect(order()).toEqual([S2, HOME, S1]);
|
|
expect(useAppState.getState().activeTabKey).toBe(HOME);
|
|
});
|
|
|
|
it("ignores a press that starts on the close button", () => {
|
|
render(<MainTabs />);
|
|
const tabs = laidOut();
|
|
const close = screen.getByRole("button", { name: "Close shell (bash)" });
|
|
|
|
fireEvent(close, new MouseEvent("pointerdown", { bubbles: true, clientX: 290, button: 0 }));
|
|
pointer(tabs[2], "pointermove", 10);
|
|
|
|
expect(screen.queryByTestId("tab-drop-marker")).toBeNull();
|
|
expect(order()).toEqual([HOME, S1, S2]);
|
|
});
|
|
|
|
it("does not drag a tab that is being renamed — that drag selects text", () => {
|
|
render(<MainTabs />);
|
|
const tabs = laidOut();
|
|
fireEvent.doubleClick(tabs[1]);
|
|
expect(screen.getByLabelText("Rename tab")).toBeInTheDocument();
|
|
|
|
dragTab(screen.getAllByRole("tab")[1], 150, 10);
|
|
|
|
expect(order()).toEqual([HOME, S1, S2]);
|
|
});
|
|
|
|
it("carries no drag payload that another element could receive", () => {
|
|
// An HTML5 drag would put the tab key in a DataTransfer, and releasing over
|
|
// any text field in the app would type `term:…` into it. Pointer events
|
|
// have nothing to hand over, and the tabs are not draggable at all.
|
|
render(<MainTabs />);
|
|
for (const tab of screen.getAllByRole("tab")) {
|
|
expect(tab).not.toHaveAttribute("draggable", "true");
|
|
}
|
|
});
|
|
});
|