Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✅ test: fix home cold route CI coverage

Inneif017dcd0eaf6
diff --git a/e2e/src/steps/home/chat-input.steps.ts b/e2e/src/steps/home/chat-input.steps.ts
index 4092dd52917..bc7936407f9 100644
--- a/e2e/src/steps/home/chat-input.steps.ts
+++ b/e2e/src/steps/home/chat-input.steps.ts
@@ -2,7 +2,8 @@ import { After, Given, Then, When } from '@cucumber/cucumber';
import { expect } from '@playwright/test';
import { llmMockManager } from '../../mocks/llm';
-import { type CustomWorld, WAIT_TIMEOUT } from '../../support/world';
+import type { CustomWorld } from '../../support/world';
+import { WAIT_TIMEOUT } from '../../support/world';
const COLD_ROUTE_SCRIPT_DELAY = 2500;
@@ -11,6 +12,30 @@ const delay = (ms: number) =>
setTimeout(resolve, ms);
});
+const focusHomeChatInput = async (world: CustomWorld): Promise<void> => {
+ const candidates = [
+ world.page.locator('[data-testid="chat-input"] textarea'),
+ world.page.locator('[data-testid="chat-input"] [contenteditable="true"]'),
+ world.page.getByRole('textbox'),
+ world.page.locator('[data-testid="chat-input"]'),
+ ];
+
+ for (const locator of candidates) {
+ const count = await locator.count();
+
+ for (let index = 0; index < count; index += 1) {
+ const item = locator.nth(index);
+ const visible = await item.isVisible().catch(() => false);
+ if (!visible) continue;
+
+ await item.click({ force: true });
+ return;
+ }
+ }
+
+ throw new Error('Could not find a visible Home chat input to focus');
+};
+
Given(
'用户在冷启动 Home 页面并延迟 Agent 路由加载',
{ timeout: 45_000 },
@@ -56,6 +81,19 @@ Given(
},
);
+When(
+ '用户在输入框中输入 {string}',
+ { timeout: 30_000 },
+ async function (this: CustomWorld, text: string) {
+ console.log(` 📍 Step: 在 Home 输入框中输入 "${text}"...`);
+
+ await focusHomeChatInput(this);
+ await this.page.keyboard.type(text, { delay: 20 });
+
+ console.log(' ✅ 已输入 Home 默认消息');
+ },
+);
+
When('用户按 Enter 从 Home 默认输入发送', { timeout: 45_000 }, async function (this: CustomWorld) {
console.log(' 📍 Step: 启用冷路由延迟并发送默认 Home 消息...');
diff --git a/src/routes/(main)/home/features/InputArea/useSend.test.ts b/src/routes/(main)/home/features/InputArea/useSend.test.ts
index a84b99acf4c..b92c68b9405 100644
--- a/src/routes/(main)/home/features/InputArea/useSend.test.ts
+++ b/src/routes/(main)/home/features/InputArea/useSend.test.ts
@@ -35,16 +35,31 @@ const fileState = vi.hoisted(() => ({
}));
const homeState = vi.hoisted(() => ({
+ agentGroups: [],
homeInputLoading: false,
inputActiveMode: null,
+ isAgentListInit: true,
+ pinnedAgents: [],
sendAsAgent: vi.fn(),
sendAsGroup: vi.fn(),
sendAsResearch: vi.fn(),
sendAsWrite: vi.fn(),
+ ungroupedAgents: [],
}));
const agentState = vi.hoisted(() => ({
+ agentMap: {
+ agt_inbox: {},
+ },
inboxAgentId: 'agt_inbox',
+ internal_dispatchAgentMap: vi.fn(),
+}));
+
+const globalState = vi.hoisted(() => ({
+ systemStatus: {
+ homeSelectedAgentId: undefined,
+ },
+ updateSystemStatus: vi.fn(),
}));
vi.mock('@/hooks/useQueryRoute', () => ({
@@ -52,7 +67,12 @@ vi.mock('@/hooks/useQueryRoute', () => ({
}));
vi.mock('@/store/agent', () => ({
- useAgentStore: (selector: (state: typeof agentState) => unknown) => selector(agentState),
+ useAgentStore: Object.assign(
+ (selector: (state: typeof agentState) => unknown) => selector(agentState),
+ {
+ getState: () => agentState,
+ },
+ ),
}));
vi.mock('@/store/agent/selectors', () => ({
@@ -61,6 +81,16 @@ vi.mock('@/store/agent/selectors', () => ({
},
}));
+vi.mock('@/store/global', () => ({
+ useGlobalStore: (selector: (state: typeof globalState) => unknown) => selector(globalState),
+}));
+
+vi.mock('@/store/global/selectors', () => ({
+ systemStatusSelectors: {
+ homeSelectedAgentId: (state: typeof globalState) => state.systemStatus.homeSelectedAgentId,
+ },
+}));
+
vi.mock('@/store/chat', () => {
const useChatStore = (selector: (state: typeof chatState) => unknown) => selector(chatState);
useChatStore.getState = () => chatState;