Files
outline/app/utils/splitView.test.ts
Tom MoorandClaude e1c906a1c2 feat: Fuse powered local content search (#13115)
* wip

* generalize

* refactor

* Extract SearchResultIcon for command bar results

Both search action builders rendered the same document icon inline. Move it
into a shared component alongside the other command bar pieces, forwarding
size so the command bar can continue to size icons via cloneElement.

Also drop the redundant charAt(0).toUpperCase() on the initial, as the Icon
component already normalizes it.

Co-Authored-By: Claude <noreply@anthropic.com>

* PR feedback
Prevent same doc showing twice in cmd k
Improve result ordering in main app command bar
Refactor to flattenTree

* Upgrade Fuse to 7.5.0, use workers

* fix: Re-register search actions when index is enriched

Include result contexts in the command bar registration key so that
snippets refresh when the same documents are enriched, and only mark a
server search as cached once its results are actually fed to the index.

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-07-25 13:16:53 -04:00

178 lines
5.9 KiB
TypeScript

import { createMemoryHistory } from "history";
import { reaction } from "mobx";
import {
closeSplitPane,
getFocusedSplitPane,
getSplitPath,
isSplittablePath,
openRouteInSplit,
setFocusedSplitPane,
setSplitPath,
} from "./splitView";
beforeEach(() => {
setFocusedSplitPane("primary");
});
describe("getSplitPath", () => {
it("returns the split path from a search string", () => {
expect(getSplitPath("?split=%2Fdoc%2Fmy-doc")).toEqual("/doc/my-doc");
expect(getSplitPath("split=%2Fdoc%2Fmy-doc")).toEqual("/doc/my-doc");
});
it("returns undefined when no split parameter is present", () => {
expect(getSplitPath("")).toBeUndefined();
expect(getSplitPath("?foo=bar")).toBeUndefined();
});
it("returns undefined for values that are not internal paths", () => {
expect(getSplitPath("?split=https%3A%2F%2Fexample.com")).toBeUndefined();
expect(getSplitPath("?split=%2F%2Fexample.com")).toBeUndefined();
expect(getSplitPath("?split=doc%2Fmy-doc")).toBeUndefined();
});
it("returns undefined for routes that cannot render in a pane", () => {
expect(getSplitPath("?split=%2Fsettings%2Fmembers")).toBeUndefined();
expect(getSplitPath("?split=%2Flogout")).toBeUndefined();
});
it("uses the last value when the parameter is repeated", () => {
expect(getSplitPath("?split=%2Fone&split=%2Ftwo")).toEqual("/two");
});
});
describe("setSplitPath", () => {
it("adds the split parameter to a search string", () => {
expect(setSplitPath("", "/doc/my-doc")).toEqual("?split=%2Fdoc%2Fmy-doc");
});
it("preserves other query parameters", () => {
expect(setSplitPath("?foo=bar", "/doc/my-doc")).toEqual(
"?foo=bar&split=%2Fdoc%2Fmy-doc"
);
});
it("removes the split parameter when the path is undefined", () => {
expect(setSplitPath("?split=%2Fdoc%2Fmy-doc", undefined)).toEqual("");
expect(setSplitPath("?foo=bar&split=%2Fdoc%2Fmy-doc", undefined)).toEqual(
"?foo=bar"
);
});
it("round trips with getSplitPath", () => {
const search = setSplitPath("?commentId=123", "/doc/my-doc?revision=1");
expect(getSplitPath(search)).toEqual("/doc/my-doc?revision=1");
});
});
describe("isSplittablePath", () => {
it("allows content routes", () => {
expect(isSplittablePath("/home")).toBe(true);
expect(isSplittablePath("/doc/my-doc-a1b2c3d4e5")).toBe(true);
expect(isSplittablePath("/collection/engineering-a1b2c3d4e5")).toBe(true);
expect(isSplittablePath("/search")).toBe(true);
expect(isSplittablePath("/drafts")).toBe(true);
});
it("rejects routes that render their own chrome", () => {
expect(isSplittablePath("/")).toBe(false);
expect(isSplittablePath("/settings")).toBe(false);
expect(isSplittablePath("/settings/members")).toBe(false);
expect(isSplittablePath("/s/abc123")).toBe(false);
expect(isSplittablePath("/logout")).toBe(false);
expect(isSplittablePath("/oauth/authorize")).toBe(false);
expect(isSplittablePath("/404")).toBe(false);
});
it("does not reject routes sharing a prefix with an excluded route", () => {
expect(isSplittablePath("/search")).toBe(true);
expect(isSplittablePath("/settings-doc-a1b2c3d4e5")).toBe(true);
});
it("rejects values that are not internal absolute paths", () => {
expect(isSplittablePath("https://example.com/doc/my-doc")).toBe(false);
expect(isSplittablePath("//example.com")).toBe(false);
expect(isSplittablePath("doc/my-doc")).toBe(false);
expect(isSplittablePath("")).toBe(false);
});
});
describe("focused split pane", () => {
it("defaults to the primary pane", () => {
expect(getFocusedSplitPane()).toEqual("primary");
});
it("is observable", () => {
const observed: string[] = [];
const dispose = reaction(
() => getFocusedSplitPane(),
(pane) => observed.push(pane)
);
setFocusedSplitPane("secondary");
setFocusedSplitPane("secondary");
setFocusedSplitPane("primary");
dispose();
setFocusedSplitPane("secondary");
expect(observed).toEqual(["secondary", "primary"]);
});
});
describe("openRouteInSplit", () => {
it("adds the split parameter and focuses the secondary pane", () => {
const history = createMemoryHistory({
initialEntries: ["/doc/my-doc?commentId=123"],
});
openRouteInSplit(history, "/doc/other-doc");
expect(history.location.pathname).toEqual("/doc/my-doc");
expect(getSplitPath(history.location.search)).toEqual("/doc/other-doc");
expect(history.location.search).toContain("commentId=123");
expect(getFocusedSplitPane()).toEqual("secondary");
});
});
describe("closeSplitPane", () => {
it("keeps the primary route when closing the secondary pane", () => {
const history = createMemoryHistory({
initialEntries: ["/doc/my-doc?split=%2Fdoc%2Fother-doc"],
});
setFocusedSplitPane("secondary");
closeSplitPane(history, "secondary");
expect(history.location.pathname).toEqual("/doc/my-doc");
expect(getSplitPath(history.location.search)).toBeUndefined();
expect(getFocusedSplitPane()).toEqual("primary");
});
it("promotes the secondary route when closing the primary pane", () => {
const history = createMemoryHistory({
initialEntries: [
"/doc/my-doc?split=%2Fdoc%2Fother-doc%3FcommentId%3D123",
],
});
setFocusedSplitPane("secondary");
closeSplitPane(history, "primary");
expect(history.location.pathname).toEqual("/doc/other-doc");
expect(history.location.search).toContain("commentId=123");
expect(getSplitPath(history.location.search)).toBeUndefined();
expect(getFocusedSplitPane()).toEqual("primary");
});
it("removes the split parameter when closing the primary pane without a secondary route", () => {
const history = createMemoryHistory({
initialEntries: ["/doc/my-doc"],
});
closeSplitPane(history, "primary");
expect(history.location.pathname).toEqual("/doc/my-doc");
expect(getSplitPath(history.location.search)).toBeUndefined();
});
});