Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

test(frontend): realign unit tests with the theme-aware settings group and menu-role agent picker

rubenluetke10-beepfb0ff7ca07b4
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgentPicker.test.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgentPicker.test.tsx
index d529ce1c72..009386b976 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgentPicker.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgentPicker.test.tsx
@@ -1,8 +1,8 @@
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
-import { StrictMode, useState } from "react";
+import { useState } from "react";
import { afterEach, describe, expect, it, vi } from "vitest";
-import { AgentPickerMenu } from "./AgentPicker";
+import { AgentPickerMenu, offersAgentChoice } from "./AgentPicker";
afterEach(cleanup);
@@ -32,48 +32,69 @@ function PickerHarness({ onPick = vi.fn() }: { onPick?: (agent: string) => void
}
describe("AgentPickerMenu", () => {
- it("uses ordinary dialog controls and keeps unavailable choices explainable", () => {
+ it("renders a labelled menu and keeps unavailable choices visible but inert", () => {
const onPick = vi.fn();
render(<PickerHarness onPick={onPick} />);
fireEvent.click(screen.getByRole("button", { name: "Open picker" }));
- expect(screen.getByRole("dialog", { name: "Choose a terminal" })).toBeTruthy();
+ expect(screen.getByRole("menu", { name: "Choose a terminal" })).toBeTruthy();
+
+ // A CLI that is not installed stays listed — the absence explains itself —
+ // but is a real disabled button, so clicking it picks nothing.
const unavailable = screen.getByTestId("pick-claude");
- expect(unavailable.getAttribute("aria-disabled")).toBe("true");
+ expect(unavailable.hasAttribute("disabled")).toBe(true);
+ expect(screen.getByText("not installed")).toBeTruthy();
fireEvent.click(unavailable);
expect(onPick).not.toHaveBeenCalled();
});
- it("Escape closes the dialog and restores focus to its trigger", () => {
- render(
- <StrictMode>
- <PickerHarness />
- </StrictMode>,
- );
- const trigger = screen.getByRole("button", { name: "Open picker" });
- trigger.focus();
- fireEvent.click(trigger);
+ it("focuses the first installed entry and picks it on click", () => {
+ const onPick = vi.fn();
+ render(<PickerHarness onPick={onPick} />);
+ fireEvent.click(screen.getByRole("button", { name: "Open picker" }));
+ // Keyboard users land on the first actionable choice, not the wrapper.
expect(document.activeElement).toBe(screen.getByTestId("pick-codex"));
- fireEvent.keyDown(document.activeElement as Element, { key: "Escape" });
- expect(screen.queryByRole("dialog")).toBeNull();
- expect(document.activeElement).toBe(trigger);
+ fireEvent.click(screen.getByTestId("pick-codex"));
+ expect(onPick).toHaveBeenCalledWith("codex");
});
- it("focuses the setup dialog when no choice is installed", () => {
- render(
- <AgentPickerMenu
- title="Open what?"
- ariaLabel="Choose a terminal"
- agents={[]}
- onPick={vi.fn()}
- onDismiss={vi.fn()}
- testId="empty-picker"
- itemTestId={(agent) => `empty-${agent}`}
- />,
+ it("Escape and a click outside both dismiss the menu", () => {
+ render(<PickerHarness />);
+ const trigger = screen.getByRole("button", { name: "Open picker" });
+
+ fireEvent.click(trigger);
+ fireEvent.keyDown(screen.getByTestId("picker"), { key: "Escape" });
+ expect(screen.queryByRole("menu")).toBeNull();
+
+ // The backdrop covers everything else, so a mousedown anywhere outside the
+ // menu lands on it and closes without a global listener.
+ fireEvent.click(trigger);
+ fireEvent.mouseDown(
+ screen.getByTestId("picker").previousElementSibling as Element,
);
+ expect(screen.queryByRole("menu")).toBeNull();
+ });
+});
- expect(document.activeElement).toBe(screen.getByRole("dialog"));
+describe("offersAgentChoice", () => {
+ it("only offers a menu when more than one choice is actually installed", () => {
+ expect(offersAgentChoice(undefined)).toBe(false);
+ expect(
+ offersAgentChoice([{ name: "codex", displayName: "Codex", installed: true }]),
+ ).toBe(false);
+ expect(
+ offersAgentChoice([
+ { name: "codex", displayName: "Codex", installed: true },
+ { name: "claude", displayName: "Claude Code", installed: false },
+ ]),
+ ).toBe(false);
+ expect(
+ offersAgentChoice([
+ { name: "codex", displayName: "Codex", installed: true },
+ { name: "shell", displayName: "Plain Terminal", installed: true },
+ ]),
+ ).toBe(true);
});
});
diff --git a/jarvis/ui/web/frontend/src/components/missions/PtyTerminal.test.tsx b/jarvis/ui/web/frontend/src/components/missions/PtyTerminal.test.tsx
index 08c31390c2..8414ed5a4b 100644
--- a/jarvis/ui/web/frontend/src/components/missions/PtyTerminal.test.tsx
+++ b/jarvis/ui/web/frontend/src/components/missions/PtyTerminal.test.tsx
@@ -6,6 +6,9 @@ vi.mock("@xterm/xterm", () => ({
Terminal: class {
cols = 80;
rows = 24;
+ // The component retints a live terminal via `term.options.theme = …`, so
+ // the double must carry a real options bag like the xterm API does.
+ options: Record<string, unknown> = {};
loadAddon() {}
open() {}
write(_data: string, done?: () => void) { done?.(); }
diff --git a/jarvis/ui/web/frontend/src/views/settings/AppSettingsGroup.test.tsx b/jarvis/ui/web/frontend/src/views/settings/AppSettingsGroup.test.tsx
index 443535695a..6345c21196 100644
--- a/jarvis/ui/web/frontend/src/views/settings/AppSettingsGroup.test.tsx
+++ b/jarvis/ui/web/frontend/src/views/settings/AppSettingsGroup.test.tsx
@@ -1,5 +1,20 @@
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
+
+// AppearanceRow inside AppSettingsGroup consumes useTheme, but this suite's
+// subject is the autostart row. Stub the hook so the group renders without a
+// ThemeProvider — mounting the real provider would also fire its own
+// /api/settings/appearance fetch and consume the sequenced fetch mocks below.
+vi.mock("@/hooks/useTheme", async (importOriginal) => ({
+ ...(await importOriginal<typeof import("@/hooks/useTheme")>()),
+ useTheme: () => ({
+ theme: "dark" as const,
+ preference: "dark" as const,
+ setPreference: vi.fn(),
+ toggle: vi.fn(),
+ }),
+}));
+
import { AppSettingsGroup } from "./AppSettingsGroup";
// A supported desktop host with autostart enabled (the default after the