import { describe, expect, it } from "vitest";
import fs from "node:fs";
import path from "node:path";

const SIDEBAR_SOURCE = path.join(process.cwd(), "src/components/sidebar/sidebar.tsx");

describe("sidebar file tree selection source", () => {
  it("rust_family renderer selection snapshot 只能由 filetree selection event 写入", () => {
    const source = fs.readFileSync(SIDEBAR_SOURCE, "utf8");
    const writes = source.match(/setResourceRendererSelection\(/g) ?? [];

    expect(writes).toHaveLength(1);
    expect(source).toContain("const [resourceRendererSelection, setResourceRendererSelection]");
    expect(source).toContain("const handleFileTreeShellSelectionChange = useCallback");
    expect(source).toContain("materializeRendererSelectionSnapshot");
    expect(source).not.toContain("selectedRowIds={resourceSelection.selectedRowIds}");
  });
});
