agent-orchestrator/tests/e2e/specs/phase-a-agent.test.ts
Hibryda 718133f9f6 test(e2e): split + expand agent-scenarios into Phase A (22 → 47 tests)
- phase-a-structure.test.ts (156 lines, 14 tests): structural integrity,
  settings panel, sidebar gear, accent colors, project name/icon, grid layout
- phase-a-agent.test.ts (210 lines, 14 tests): agent pane, prompts,
  provider badge, cost display, context meter, status transitions
- phase-a-navigation.test.ts (297 lines, 19 tests): terminal tabs,
  command palette, focus switching, palette categories, shortcut hints
- Original agent-scenarios.test.ts (429 lines) deleted
- 25 new exhaustive tests added
2026-03-18 03:46:40 +01:00

210 lines
8.2 KiB
TypeScript

import { browser, expect } from '@wdio/globals';
// Phase A — Agent: Agent pane initial state + prompt submission + NEW agent tests.
// Shares a single Tauri app session with other phase-a-* spec files.
// ─── Helpers ──────────────────────────────────────────────────────────
async function waitForAgentStatus(status: string, timeout = 30_000): Promise<void> {
await browser.waitUntil(
async () => {
const attr = await browser.execute(() => {
const el = document.querySelector('[data-testid="agent-pane"]');
return el?.getAttribute('data-agent-status') ?? 'idle';
});
return attr === status;
},
{ timeout, timeoutMsg: `Agent did not reach status "${status}" within ${timeout}ms` },
);
}
async function agentPaneExists(): Promise<boolean> {
const el = await browser.$('[data-testid="agent-pane"]');
return el.isExisting();
}
async function sendAgentPrompt(text: string): Promise<void> {
const textarea = await browser.$('[data-testid="agent-prompt"]');
await textarea.waitForDisplayed({ timeout: 5000 });
await textarea.setValue(text);
await browser.pause(200);
const submitBtn = await browser.$('[data-testid="agent-submit"]');
await browser.execute((el) => (el as HTMLElement).click(), submitBtn);
}
async function getAgentStatus(): Promise<string> {
return browser.execute(() => {
const el = document.querySelector('[data-testid="agent-pane"]');
return el?.getAttribute('data-agent-status') ?? 'unknown';
});
}
async function getMessageCount(): Promise<number> {
return browser.execute(() => {
const area = document.querySelector('[data-testid="agent-messages"]');
return area ? area.children.length : 0;
});
}
// ─── Scenario 3: Agent pane initial state ────────────────────────────
describe('Scenario 3 — Agent Pane Initial State', () => {
it('should display agent pane in idle status', async () => {
if (!(await agentPaneExists())) {
await browser.execute(() => {
const tab = document.querySelector('[data-testid="project-tabs"] .ptab');
if (tab) (tab as HTMLElement).click();
});
await browser.pause(300);
}
const pane = await browser.$('[data-testid="agent-pane"]');
await expect(pane).toBeExisting();
expect(await getAgentStatus()).toBe('idle');
});
it('should show prompt textarea', async () => {
const textarea = await browser.$('[data-testid="agent-prompt"]');
await expect(textarea).toBeDisplayed();
});
it('should show submit button', async () => {
const btn = await browser.$('[data-testid="agent-submit"]');
await expect(btn).toBeExisting();
});
it('should have empty messages area initially', async () => {
const msgArea = await browser.$('[data-testid="agent-messages"]');
await expect(msgArea).toBeExisting();
const msgCount = await browser.execute(() => {
const area = document.querySelector('[data-testid="agent-messages"]');
return area ? area.querySelectorAll('.message').length : 0;
});
expect(msgCount).toBe(0);
});
it('should show agent provider name or badge', async () => {
const hasContent = await browser.execute(() => {
const session = document.querySelector('[data-testid="agent-session"]');
return session !== null && (session.textContent ?? '').length > 0;
});
expect(hasContent).toBe(true);
});
it('should show session ID or cost display area', async () => {
const hasCostArea = await browser.execute(() => {
const pane = document.querySelector('[data-testid="agent-pane"]');
if (!pane) return false;
return (pane.querySelector('.cost-bar') || pane.querySelector('.status-strip')) !== null;
});
expect(hasCostArea).toBe(true);
});
it('should show context meter (token usage bar)', async () => {
const has = await browser.execute(() => {
const pane = document.querySelector('[data-testid="agent-pane"]');
if (!pane) return false;
return (pane.querySelector('.context-meter') || pane.querySelector('.usage-meter')) !== null;
});
expect(has).toBe(true);
});
it('should have tool call/result collapsible sections area', async () => {
const ready = await browser.execute(() => {
const area = document.querySelector('[data-testid="agent-messages"]');
return area !== null && area instanceof HTMLElement;
});
expect(ready).toBe(true);
});
});
// ─── Scenario 7: Agent prompt interaction (requires Claude CLI) ──────
describe('Scenario 7 — Agent Prompt Submission', () => {
it('should accept text in prompt textarea', async () => {
const textarea = await browser.$('[data-testid="agent-prompt"]');
await textarea.waitForDisplayed({ timeout: 5000 });
await textarea.setValue('Say hello');
await browser.pause(200);
expect(await textarea.getValue()).toBe('Say hello');
await textarea.clearValue();
});
it('should enable submit button when prompt has text', async () => {
const textarea = await browser.$('[data-testid="agent-prompt"]');
await textarea.setValue('Test prompt');
await browser.pause(200);
const isDisabled = await browser.execute(() => {
const btn = document.querySelector('[data-testid="agent-submit"]');
return btn ? (btn as HTMLButtonElement).disabled : true;
});
expect(isDisabled).toBe(false);
await textarea.clearValue();
});
it('should show stop button during agent execution (if Claude available)', async function () {
await sendAgentPrompt('Reply with exactly: AGOR_TEST_OK');
try { await waitForAgentStatus('running', 15_000); } catch {
console.log('Agent did not start — Claude CLI may not be available. Skipping.');
this.skip(); return;
}
const status = await getAgentStatus();
if (status === 'running') {
const stopBtn = await browser.$('[data-testid="agent-stop"]');
await expect(stopBtn).toBeDisplayed();
}
try { await waitForAgentStatus('idle', 40_000); } catch {
console.log('Agent did not complete within 40s — skipping completion checks.');
this.skip(); return;
}
expect(await getMessageCount()).toBeGreaterThan(0);
});
it('should show agent status transitions (idle -> running -> idle)', async function () {
expect(await getAgentStatus()).toBe('idle');
await sendAgentPrompt('Reply with one word: OK');
try { await waitForAgentStatus('running', 15_000); } catch {
console.log('Agent did not start — skipping status transition test.');
this.skip(); return;
}
expect(await getAgentStatus()).toBe('running');
try { await waitForAgentStatus('idle', 40_000); } catch {
this.skip(); return;
}
expect(await getAgentStatus()).toBe('idle');
});
it('should show message count increasing during execution', async function () {
const countBefore = await getMessageCount();
await sendAgentPrompt('Reply with exactly: AGOR_MSG_COUNT_TEST');
try { await waitForAgentStatus('running', 15_000); } catch {
this.skip(); return;
}
try { await waitForAgentStatus('idle', 40_000); } catch {
this.skip(); return;
}
expect(await getMessageCount()).toBeGreaterThan(countBefore);
});
it('should disable prompt input while agent is running', async function () {
await sendAgentPrompt('Reply with exactly: AGOR_DISABLE_TEST');
try { await waitForAgentStatus('running', 15_000); } catch {
this.skip(); return;
}
const uiState = await browser.execute(() => {
const textarea = document.querySelector('[data-testid="agent-prompt"]') as HTMLTextAreaElement | null;
const stopBtn = document.querySelector('[data-testid="agent-stop"]');
return {
textareaDisabled: textarea?.disabled ?? false,
stopBtnVisible: stopBtn !== null && (stopBtn as HTMLElement).offsetParent !== null,
};
});
expect(uiState.textareaDisabled || uiState.stopBtnVisible).toBe(true);
try { await waitForAgentStatus('idle', 40_000); } catch {
await browser.execute(() => {
const btn = document.querySelector('[data-testid="agent-stop"]');
if (btn) (btn as HTMLElement).click();
});
await browser.pause(2000);
}
});
});