fix(webui): open ready apps by default (#6685)

* fix(webui): open ready apps by default

* test(webui): select apps when checking catalog cache
This commit is contained in:
chengyongru authored and GitHub committed 2026-11-17 11:21:26 +08:00
1 parent 7782095a85
commit e767174450
7 files changed
+130 -14

No files matched your search

+27
View File
@@ -3533,6 +3533,33 @@ describe("App layout", () => {
expect(settingsHighlight).toHaveAttribute("data-active-id", "capabilities");
});
it("defaults to Ready again when returning to Apps from another sidebar page", async () => {
const app = {
name: "example", display_name: "Example App", category: "productivity", description: "Example",
requires: "", source: "catalog", entry_point: "example", install_supported: true,
installed: true, available: true, status: "installed", skill_installed: false,
};
mockFetchRoutes({
"/api/settings": baseSettingsPayload(),
"/api/settings/cli-apps": { apps: [app], installed_count: 1 },
"/api/settings/mcp-presets": { presets: [], installed_count: 0 },
"/api/webui/skills": { skills: [] },
});
render(<App />);
await waitFor(() => expect(connectSpy).toHaveBeenCalled());
const sidebar = screen.getByRole("navigation", { name: "Sidebar navigation" });
fireEvent.click(within(sidebar).getByRole("button", { name: "Apps" }));
await act(async () => { await import("@/components/settings/SettingsView"); });
expect(await screen.findByRole("heading", { name: "Example App" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Ready" })).toHaveAttribute("aria-pressed", "true");
fireEvent.click(screen.getByRole("button", { name: "MCP" }));
fireEvent.click(within(sidebar).getByRole("button", { name: "Skills" }));
expect(await screen.findByRole("heading", { name: "Skills" })).toBeInTheDocument();
fireEvent.click(within(sidebar).getByRole("button", { name: "Apps" }));
expect(await screen.findByRole("heading", { name: "Example App" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Ready" })).toHaveAttribute("aria-pressed", "true");
});
it("transitions between Apps and Skills without replacing the sidebar", async () => {
mockFetchRoutes({
"/api/settings": baseSettingsPayload(),
+3
View File
@@ -57,6 +57,7 @@ describe("catalog loading", () => {
cleanup();
fetch.mockClear();
renderSettingsView({ client, initialSettings: settingsPayload() });
fireEvent.click(screen.getByRole("button", { name: "Apps" }));
expect(screen.getByRole("heading", { name: "AnyGen" })).toBeInTheDocument();
expect(screen.getByRole("heading", { name: "Computer Use" })).toBeInTheDocument();
expect(screen.queryByRole("status", { name: "Loading apps…" })).not.toBeInTheDocument();
@@ -66,6 +67,7 @@ describe("catalog loading", () => {
const now = vi.spyOn(Date, "now").mockReturnValue(Date.now() + TOOLS_CATALOG_TTL_MS + 1);
try {
renderSettingsView({ client, initialSettings: settingsPayload() });
fireEvent.click(screen.getByRole("button", { name: "Apps" }));
expect(screen.getByRole("heading", { name: "AnyGen" })).toBeInTheDocument();
expect(screen.getByRole("heading", { name: "Computer Use" })).toBeInTheDocument();
expect(screen.queryByRole("status", { name: "Loading apps…" })).not.toBeInTheDocument();
@@ -134,6 +136,7 @@ describe("catalog loading", () => {
return Promise.resolve(jsonResponse(settingsPayload()));
}));
renderSettingsView({ initialSettings: settingsPayload() });
fireEvent.click(screen.getByRole("button", { name: "Apps" }));
expect(screen.getByRole("status", { name: "Loading apps…" })).toHaveAttribute("aria-busy", "true");
await act(async () => { cli.resolve(jsonResponse({ apps: [app], installed_count: 1 })); });
@@ -0,0 +1,69 @@
import { act, cleanup, fireEvent, screen } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import type { NanobotClient } from "@/lib/nanobot-client";
import {
installSettingsViewTestHooks,
jsonResponse,
renderSettingsView,
settingsPayload,
} from "@/tests/settings-test-utils";
const app = {
name: "example", display_name: "Example App", category: "productivity", description: "Example app",
requires: "", source: "catalog", entry_point: "example", install_supported: true,
installed: false, available: false, status: "not_installed", skill_installed: false,
};
const mcp = {
name: "docs", display_name: "Docs MCP", category: "productivity", description: "Example MCP",
docs_url: "", transport: "stdio", requires: "", note: "", install_supported: true,
installed: true, configured: true, available: true, status: "configured", required_fields: [],
connection_summary: "", source: "preset", runtime_status: "connected",
};
const plugin = { ...mcp, name: "plugin", display_name: "Example Plugin", source: "agent-plugin", enabled: true };
function deferred<T>() {
let resolve!: (value: T) => void;
const promise = new Promise<T>((done) => { resolve = done; });
return { promise, resolve };
}
describe("Apps default filter", () => {
installSettingsViewTestHooks();
it("opens Apps when nothing is ready, including disconnected MCP and disabled plugins", async () => {
vi.stubGlobal("fetch", vi.fn(async (input: RequestInfo | URL) => {
if (String(input) === "/api/settings/cli-apps") return jsonResponse({ apps: [app], installed_count: 0 });
if (String(input) === "/api/settings/mcp-presets") return jsonResponse({
presets: [{ ...mcp, runtime_status: "disconnected" }, { ...plugin, enabled: false }], installed_count: 2,
});
return jsonResponse(settingsPayload());
}));
renderSettingsView({ initialSettings: settingsPayload() });
expect(await screen.findByRole("heading", { name: "Example App" })).toBeInTheDocument();
expect(screen.getByRole("button", { name: "Apps" })).toHaveAttribute("aria-pressed", "true");
});
it("preserves a manual choice while MCP loads, then defaults to the cached Ready items on re-entry", async () => {
const client = { status: "open", onStatus: () => () => {} } as unknown as NanobotClient;
const pending = deferred<Response>();
vi.stubGlobal("fetch", vi.fn((input: RequestInfo | URL) => {
if (String(input) === "/api/settings/cli-apps") return Promise.resolve(jsonResponse({ apps: [app], installed_count: 0 }));
if (String(input) === "/api/settings/mcp-presets") return pending.promise;
return Promise.resolve(jsonResponse(settingsPayload()));
}));
renderSettingsView({ client, initialSettings: settingsPayload() });
await act(async () => {});
expect(screen.queryByRole("heading", { name: "Example App" })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("button", { name: "Apps" }));
await act(async () => { pending.resolve(jsonResponse({ presets: [mcp], installed_count: 1 })); });
expect(screen.getByRole("button", { name: "Apps" })).toHaveAttribute("aria-pressed", "true");
expect(screen.getByRole("heading", { name: "Example App" })).toBeInTheDocument();
cleanup();
renderSettingsView({ client, initialSettings: settingsPayload() });
expect(screen.getByRole("button", { name: "Ready" })).toHaveAttribute("aria-pressed", "true");
expect(screen.getByRole("heading", { name: "Docs MCP" })).toBeInTheDocument();
});
});