test(app): triage desktop test files — delete 16-mock component slop, tighten attachment store (#721)
* test(app): triage desktop test files — delete 16-mock component slop, tighten attachment store assertion Removes desktop-updates-section.test.tsx (16 internal mocks, JSDOM, toHaveBeenCalledWith chains on component renders). Tightens desktop-attachment-store.test.ts: toHaveBeenCalled() → toHaveBeenCalledWith(attachment). * refactor(app): extract daemon management toggle coordinator with unit tests Fills the coverage gap left by deleting desktop-updates-section.test.tsx. Extracts executeDaemonManagementToggle from useDaemonManagementToggle — pure async coordinator with injected deps (no vi.mock). Unit tests verify the three key invariants: settings persist before stop, stop is skipped when not desktop-managed, and start/stop are invoked on enable/disable.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import type { DesktopDaemonStatus } from "./desktop-daemon";
|
||||
|
||||
export interface DaemonManagementToggleDeps {
|
||||
confirm: () => Promise<boolean>;
|
||||
persistSettings: (next: { manageBuiltInDaemon: boolean }) => Promise<void>;
|
||||
startDaemon: () => Promise<DesktopDaemonStatus>;
|
||||
stopDaemon: () => Promise<DesktopDaemonStatus>;
|
||||
}
|
||||
|
||||
export type DaemonManagementToggleResult =
|
||||
| { kind: "cancelled" }
|
||||
| { kind: "enabled"; newStatus: DesktopDaemonStatus }
|
||||
| { kind: "disabled"; newStatus: DesktopDaemonStatus | null };
|
||||
|
||||
export async function executeDaemonManagementToggle(
|
||||
currentlyManaging: boolean,
|
||||
daemonStatus: Pick<DesktopDaemonStatus, "status" | "desktopManaged"> | null,
|
||||
deps: DaemonManagementToggleDeps,
|
||||
): Promise<DaemonManagementToggleResult> {
|
||||
if (!currentlyManaging) {
|
||||
await deps.persistSettings({ manageBuiltInDaemon: true });
|
||||
const newStatus = await deps.startDaemon();
|
||||
return { kind: "enabled", newStatus };
|
||||
}
|
||||
|
||||
const confirmed = await deps.confirm();
|
||||
if (!confirmed) {
|
||||
return { kind: "cancelled" };
|
||||
}
|
||||
|
||||
// Settings must persist before the daemon is stopped so the persisted
|
||||
// state reflects what was actually applied if the stop fails.
|
||||
await deps.persistSettings({ manageBuiltInDaemon: false });
|
||||
|
||||
if (daemonStatus?.status === "running" && daemonStatus.desktopManaged) {
|
||||
const newStatus = await deps.stopDaemon();
|
||||
return { kind: "disabled", newStatus };
|
||||
}
|
||||
|
||||
return { kind: "disabled", newStatus: null };
|
||||
}
|
||||
Reference in New Issue
Block a user