Files
Netcatty/components/systemManager/systemPanelConfirmDialogRegression.test.ts
T
陈大猫 af3459ed6e fix(ui): replace native confirms in system manager panels (#2248)
* fix(ui): replace native confirms in system manager panels

Windows native confirm dialogs steal focus after process/tmux/docker
destructive actions. Use SystemPanelConfirmDialog so the side panel
stays usable after confirm/cancel.

Fixes #2242

* fix(ui): clear system manager confirms on session switch

Drop pending process/docker confirms when sessionId changes so a
dialog opened for one host cannot execute against another.

* fix(ui): clear docker image action busy on session switch

Reset actionBusy when sessionId changes so a previous host's
in-flight remove/prune cannot leave the new session's confirm
dialog disabled. Guard stale completions with a generation counter.
2026-07-16 11:27:07 +08:00

56 lines
2.0 KiB
TypeScript

import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { join } from "node:path";
import { fileURLToPath } from "node:url";
import test from "node:test";
const root = fileURLToPath(new URL("../..", import.meta.url));
function readProjectFile(path: string): string {
return readFileSync(join(root, path), "utf8");
}
const SYSTEM_MANAGER_PANELS = [
"components/systemManager/ProcessManagerTab.tsx",
"components/systemManager/TmuxSessionCard.tsx",
"components/systemManager/DockerContainersPanel.tsx",
"components/systemManager/DockerImagesPanel.tsx",
] as const;
test("system manager destructive actions use in-app confirm dialogs", () => {
for (const path of SYSTEM_MANAGER_PANELS) {
const source = readProjectFile(path);
assert.match(
source,
/import \{ SystemPanelConfirmDialog \} from ['"]\.\/SystemPanelConfirmDialog['"]/,
`${path} should import SystemPanelConfirmDialog`,
);
assert.match(
source,
/<SystemPanelConfirmDialog/,
`${path} should render SystemPanelConfirmDialog`,
);
assert.doesNotMatch(
source,
/window\.confirm|globalThis\.confirm/,
`${path} must not use native confirm dialogs`,
);
}
});
test("process and docker confirm dialogs reset when sessionId changes", () => {
const processSource = readProjectFile("components/systemManager/ProcessManagerTab.tsx");
const containersSource = readProjectFile("components/systemManager/DockerContainersPanel.tsx");
const imagesSource = readProjectFile("components/systemManager/DockerImagesPanel.tsx");
assert.match(processSource, /setPendingSignal\(null\)/);
assert.match(processSource, /}, \[sessionId\]\);/);
assert.match(containersSource, /setConfirmAction\(null\)/);
assert.match(containersSource, /}, \[sessionId\]\);/);
assert.match(imagesSource, /setConfirmTarget\(null\)/);
assert.match(imagesSource, /setActionBusy\(false\)/);
assert.match(imagesSource, /}, \[sessionId\]\);/);
});