fix(sidebar): preserve group state after search

This commit is contained in:
Melody Ruch authored and GitHub committed 2026-08-14 22:12:44 +08:00
1 parent 26084d12e1
commit b9e63dc57e
3 files changed
+103 -8

No files matched your search

@@ -0,0 +1,25 @@
import { describe, expect, it } from "vitest";
import { createSidebarSearchExpansionState } from "@/lib/sidebar/sidebarSearchExpansionState";
describe("sidebar search expansion state", () => {
it("keeps auto-expanded ownership after a filtered group becomes an unfiltered ancestor match", () => {
const state = createSidebarSearchExpansionState();
state.markFiltered("group-tables", true);
expect(state.markUnfiltered("group-tables")).toBe(true);
expect(state.filteredNodeIds.has("group-tables")).toBe(false);
expect(state.autoExpandedNodeIds.has("group-tables")).toBe(true);
expect(state.shouldRestore("group-tables")).toBe(true);
});
it("clears tracked ownership when ordinary search exits through another mode", () => {
const state = createSidebarSearchExpansionState();
state.markFiltered("group-tables", true);
state.clear();
expect(state.hasTrackedNodes()).toBe(false);
expect(state.shouldRestore("group-tables")).toBe(false);
});
});