Skip to content

Open-source, local-first AI agent for real work.

1.2 KB
Raw Blame
// @vitest-environment jsdom

import { act } from "react";
import { createRoot } from "react-dom/client";
import { expect, it } from "vitest";
import { StorageCleanListView } from "./StorageCleanListView";

Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });

it("展示理由与恢复方式,点击整行切换勾选,占用中的条目不能勾选", () => {
	const toggled: unknown[] = [];
	const item = { path: "workspace/a", size: "1 GB", reason: "Idle", restore: "npm ci", checked: true, disabled: false };
	const container = document.createElement("div");
	document.body.append(container);
	const root = createRoot(container);
	act(() =>
		root.render(
			<StorageCleanListView
				items={[
					{ ...item, id: "a", title: "Dependencies" },
					{ ...item, id: "b", title: "Busy", checked: false, disabled: true },
				]}
				summary="1 selected"
				onToggle={(id, checked) => toggled.push([id, checked])}
			/>,
		),
	);
	const [first, second] = [...container.querySelectorAll("label")];
	expect(first?.textContent).toContain("Idle");
	expect(first?.textContent).toContain("npm ci");
	act(() => first?.click());
	act(() => second?.click());
	expect(toggled).toEqual([["a", false]]);
	act(() => root.unmount());
	container.remove();
});