Files
fusion/packages/dashboard/app/components/__tests__/EngineControlMenu.test.tsx
gsxdsm e18745b79e FN-6844: move engine controls to footer status bar
Move engine stop, pause, and scheduler tuning controls into the executor footer status bar.

- Add a footer EngineControlMenu popover with stop/start, pause/resume, and debounced concurrency/worktree sliders.
- Remove the engine controls from the dashboard header and wire the footer running-state text to open the controls.
- Update dashboard tests, English labels, and operator documentation for the footer control location.

Files changed:
 docs/dashboard-guide.md                            |   4 +
 packages/dashboard/app/App.tsx                     |   7 -
 .../app/__tests__/tablet-header-controls.test.tsx  |  21 +-
 .../dashboard/app/components/EngineControlMenu.css | 118 +++++++++
 .../dashboard/app/components/EngineControlMenu.tsx | 292 +++++++++++++++++++++
 .../dashboard/app/components/ExecutorStatusBar.css |  28 ++
 .../dashboard/app/components/ExecutorStatusBar.tsx |  25 +-
 packages/dashboard/app/components/Header.css       |  89 -------
 packages/dashboard/app/components/Header.tsx       |  81 +-----
 .../app/components/__tests__/App.test.tsx          | 132 ----------
 .../__tests__/EngineControlMenu.test.tsx           | 145 ++++++++++
 .../__tests__/ExecutorStatusBar.test.tsx           |  40 +++
 .../app/components/__tests__/Header.test.tsx       |  57 +---
 .../components/__tests__/MultiProjectFlow.test.tsx |   8 -
 .../app/components/__tests__/ResearchView.test.tsx |   4 -
 packages/i18n/locales/en/app.json                  |   5 +-
 16 files changed, 666 insertions(+), 390 deletions(-)

Fusion-Task-Id: FN-6844

Fusion-Task-Lineage: f0e17e3d-489e-483c-ba7d-a020c111231c
2026-06-21 09:00:40 -07:00

146 lines
5.3 KiB
TypeScript

import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { render, screen, fireEvent, waitFor, act } from "@testing-library/react";
import { EngineControlMenu } from "../EngineControlMenu";
const defaultSettings = {
maxConcurrent: 2,
maxTriageConcurrent: 1,
maxWorktrees: 4,
globalPause: false,
enginePaused: false,
autoMerge: true,
experimentalFeatures: {},
};
const apiMocks = vi.hoisted(() => ({
fetchConfig: vi.fn(),
fetchSettings: vi.fn(),
updateSettings: vi.fn(),
updateGlobalSettings: vi.fn(),
}));
const legacyMocks = vi.hoisted(() => ({
fetchConfig: vi.fn(),
fetchSettings: vi.fn(),
updateSettings: vi.fn(),
}));
vi.mock("../../api", () => apiMocks);
vi.mock("../../api/legacy", () => legacyMocks);
vi.mock("../../versionCheck", () => ({
setAutoReloadEnabled: vi.fn(),
}));
async function openMenu() {
render(<EngineControlMenu projectId="proj_123" />);
fireEvent.click(screen.getByTestId("engine-control-menu-trigger"));
await screen.findByTestId("engine-control-menu");
}
describe("EngineControlMenu", () => {
beforeEach(() => {
vi.useRealTimers();
apiMocks.fetchConfig.mockResolvedValue({ maxConcurrent: 2, rootDir: "/workspace/project" });
apiMocks.fetchSettings.mockResolvedValue({ ...defaultSettings });
apiMocks.updateSettings.mockResolvedValue({ ...defaultSettings });
apiMocks.updateGlobalSettings.mockResolvedValue({});
legacyMocks.fetchConfig.mockResolvedValue({ maxConcurrent: 2, rootDir: "/workspace/project" });
legacyMocks.fetchSettings.mockResolvedValue({ ...defaultSettings });
legacyMocks.updateSettings.mockResolvedValue({ ...defaultSettings });
});
afterEach(() => {
vi.clearAllMocks();
vi.useRealTimers();
});
it("stops and starts the global AI engine via settings", async () => {
apiMocks.fetchSettings.mockResolvedValue({ ...defaultSettings, globalPause: false });
await openMenu();
fireEvent.click(screen.getByTestId("engine-control-stop-btn"));
await waitFor(() => expect(apiMocks.updateSettings).toHaveBeenCalledWith(
{ globalPause: true, globalPauseReason: "manual" },
"proj_123",
));
});
it("starts the global AI engine when currently stopped", async () => {
apiMocks.fetchSettings.mockResolvedValue({ ...defaultSettings, globalPause: true });
await openMenu();
await waitFor(() => expect(screen.getByTestId("engine-control-stop-btn")).toHaveTextContent(/start ai engine/i));
fireEvent.click(screen.getByTestId("engine-control-stop-btn"));
await waitFor(() => expect(apiMocks.updateSettings).toHaveBeenCalledWith(
{ globalPause: false, globalPauseReason: undefined },
"proj_123",
));
});
it("pauses and resumes triage, and disables triage while globally stopped", async () => {
apiMocks.fetchSettings.mockResolvedValue({ ...defaultSettings, enginePaused: false });
await openMenu();
fireEvent.click(screen.getByTestId("engine-control-pause-triage-btn"));
await waitFor(() => expect(apiMocks.updateSettings).toHaveBeenCalledWith({ enginePaused: true }, "proj_123"));
vi.clearAllMocks();
apiMocks.fetchConfig.mockResolvedValue({ maxConcurrent: 2, rootDir: "/workspace/project" });
apiMocks.fetchSettings.mockResolvedValue({ ...defaultSettings, globalPause: true, enginePaused: true });
legacyMocks.fetchConfig.mockResolvedValue({ maxConcurrent: 2, rootDir: "/workspace/project" });
legacyMocks.fetchSettings.mockResolvedValue({ ...defaultSettings });
render(<EngineControlMenu projectId="proj_123" />);
fireEvent.click(screen.getAllByTestId("engine-control-menu-trigger")[1]);
await waitFor(() => expect(screen.getAllByTestId("engine-control-pause-triage-btn")).toHaveLength(2));
const pauseButton = screen.getAllByTestId("engine-control-pause-triage-btn")[1];
expect(pauseButton).toBeDisabled();
expect(pauseButton).toHaveTextContent(/resume scheduling/i);
});
it("persists debounced concurrency and worktree slider changes and refreshes settings", async () => {
legacyMocks.fetchSettings.mockResolvedValue({
...defaultSettings,
maxConcurrent: 12,
maxTriageConcurrent: 3,
maxWorktrees: 25,
});
await openMenu();
const maxConcurrent = await screen.findByLabelText(/max concurrent tasks/i);
const maxTriage = screen.getByLabelText(/max triage concurrent/i);
const maxWorktrees = screen.getByLabelText(/max worktrees/i);
vi.useFakeTimers();
expect(maxConcurrent).toHaveAttribute("max", "12");
expect(maxConcurrent).toHaveValue("12");
expect(maxWorktrees).toHaveAttribute("max", "25");
expect(maxWorktrees).toHaveValue("25");
fireEvent.change(maxConcurrent, { target: { value: "9" } });
fireEvent.change(maxTriage, { target: { value: "4" } });
fireEvent.change(maxWorktrees, { target: { value: "8" } });
await act(async () => {
await vi.advanceTimersByTimeAsync(500);
});
expect(legacyMocks.updateSettings).toHaveBeenCalledWith(
{ maxConcurrent: 9, maxTriageConcurrent: 4, maxWorktrees: 8 },
"proj_123",
);
expect(apiMocks.fetchSettings).toHaveBeenCalledTimes(2);
});
it("renders a load error state without crashing", async () => {
legacyMocks.fetchSettings.mockRejectedValue(new Error("settings unavailable"));
await openMenu();
expect(await screen.findByRole("alert")).toHaveTextContent("settings unavailable");
});
});