agent-orchestrator/tests/e2e/specs/phase-a-agent.test.ts
Hibryda 1b838eb9fc fix(e2e): update selectors for redesigned UI (9 spec files)
- BTerminal → Agent Orchestrator (title, describe blocks, LLM context)
- Settings: .sidebar-panel → .settings-panel .settings-content,
  .dropdown-trigger → .dropdown-btn, .dropdown-option → .dropdown-item
- Settings open: [data-testid=settings-btn] + .panel-close
- Font controls: .size-control → .stepper, .size-btn → stepper button
- Terminal: data-testid selectors for toggle/tab-add
- Agent pane: .cost-bar → .status-strip/.done-bar, context meter conditional
- Project header: .cwd → .info-cwd
- Health: .health-dot → .status-dot
- Multi-project: proper this.skip() when single-project fixture
2026-03-18 04:45:22 +01:00

216 lines
8.6 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;
// status-strip contains cost/context info when session exists
return pane.querySelector('.status-strip') !== null
|| pane.querySelector('.done-bar') !== null
|| pane.querySelector('.running-indicator') !== null;
});
expect(hasCostArea).toBe(true);
});
it('should show context meter or usage meter (visible when agent is running)', async () => {
// Context meter is only shown during running state; at idle we just verify
// the status-strip area exists (it renders conditionally based on session)
const has = await browser.execute(() => {
const pane = document.querySelector('[data-testid="agent-pane"]');
if (!pane) return false;
// When idle, status-strip may be empty or show done-bar; when running, shows context-meter or UsageMeter
return pane.querySelector('.status-strip') !== 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);
}
});
});