patchwise-agent-studio / web /src /pages /run /LiveOverlay.test.ts
EnergyVenom's picture
Tidy the web app: pages by area, CSS in load order, web/README.md (b2a039d)
fb43301 verified
Raw History Blame Contribute Delete
5.03 kB
import { describe, expect, it } from 'vitest';
import type { LiveStatus } from '../../api/types';
import { liveOverlay, RELOAD_AFTER_MS, type LiveCtx } from './LiveView';
const live = (over: Partial<LiveStatus> = {}): LiveStatus => ({
run_id: 'r1', available: true, reason: null, active: true, stale: false, attempt: 0, action: null, action_n: 0, masked: false, chunk: null, chunks: null,
scenario_id: 'P2P-REQ-001', scenario_title: 'Create a requisition', page_title: null, path: null, status: 'running', frame_ts: '2026-10-24T10:00:00+00:00',
progress: { done: 0, total: 5 }, area: null, step: null, role: null, results: { passed: 0, failed: 0, recent: [] }, up_next: [], failed: null, ...over,
}) as LiveStatus;
const ctx = (over: Partial<LiveCtx> = {}): LiveCtx => ({ status: 'running', gate: null, canWatch: true, quick: false, everActive: true, slow: false, frozen: false, reconnectingFor: 0, frameAgeS: 2, ...over });
describe('the live browser states (liveOverlay)', () => {
it('live: a clean picture with a LIVE badge, pause and fullscreen', () => {
const o = liveOverlay(live(), ctx());
expect(o.kind).toBe('live');
expect(o.title).toBe('');
expect(o.badge).toEqual({ label: 'LIVE', tone: 'red' });
expect(o.controls).toEqual({ pause: true, jump: false, fullscreen: true, reload: false });
});
it('starting: the browser was asked to open and no picture has arrived; everything is disabled; a slow start says why', () => {
const o = liveOverlay(live({ frame_ts: null }), ctx());
expect(o.kind).toBe('starting');
expect(o.title).toBe('Starting the browser…');
expect(o.badge?.label).toBe('STARTING');
expect(o.controls).toEqual({ pause: false, jump: false, fullscreen: false, reload: false });
expect(liveOverlay(live({ frame_ts: null }), ctx({ slow: true })).text).toMatch(/taking longer than usual to show a picture/);
});
it('hidden sign-in: passwords are never shown, only fullscreen is offered', () => {
const o = liveOverlay(live({ masked: true }), ctx());
expect(o.kind).toBe('masked');
expect(o.text).toBe('Sign-in screen hidden. Passwords are never shown here.');
expect(o.badge?.label).toBe('LIVE');
expect(o.controls).toEqual({ pause: false, jump: false, fullscreen: true, reload: false });
});
it('reconnecting: orange badge, the last picture age, and a reload button only after 30 seconds', () => {
const early = liveOverlay(live({ stale: true }), ctx({ frameAgeS: 8, reconnectingFor: 5_000 }));
expect(early.kind).toBe('reconnecting');
expect(early.badge).toEqual({ label: 'RECONNECTING', tone: 'orange' });
expect(early.text).toContain('(8 s ago)');
expect(early.controls.reload).toBe(false);
expect(liveOverlay(live({ stale: true }), ctx({ reconnectingFor: RELOAD_AFTER_MS })).controls.reload).toBe(true);
});
it('paused for your review: waiting on a gate says which decision it is waiting for', () => {
const a = liveOverlay(live({ active: false }), ctx({ status: 'waiting_approval', gate: 'approve_cases' }));
expect(a.kind).toBe('paused');
expect(a.text).toContain('approve the scenarios');
expect(a.badge?.label).toBe('PAUSED');
expect(liveOverlay(live({ active: false }), ctx({ status: 'waiting_review', gate: 'human_review' })).text).toContain('decide the failure');
});
it('you paused the view: the picture is frozen, the test keeps running, Jump to live is offered', () => {
const o = liveOverlay(live(), ctx({ frozen: true }));
expect(o.kind).toBe('frozen');
expect(o.text).toBe('View paused. The test is still running.');
expect(o.controls.jump).toBe(true);
});
it('preparing the next batch, then ended', () => {
const idle = live({ active: false });
expect(liveOverlay(idle, ctx({ everActive: true })).text).toBe('Preparing the next batch of scenarios…');
expect(liveOverlay(idle, ctx({ everActive: false })).text).toMatch(/browser opens when the scenarios start/);
const done = liveOverlay(idle, ctx({ status: 'completed' }));
expect(done.kind).toBe('ended');
expect(done.badge?.label).toBe('ENDED');
expect(done.title).toBe('Testing has finished');
});
it('unavailable, quick simulation and no permission replace the picture with words and have no controls', () => {
const un = liveOverlay(live({ available: false, active: false, reason: 'Live view is switched off for this installation.' }), ctx());
expect(un).toMatchObject({ kind: 'unavailable', replaces: true, badge: null, text: 'Live view is switched off for this installation.' });
expect(liveOverlay(undefined, ctx({ quick: true })).kind).toBe('quick');
expect(liveOverlay(live(), ctx({ canWatch: false })).text).toMatch(/consultant, QA approver or admin role/);
for (const o of [un, liveOverlay(undefined, ctx({ quick: true }))]) expect(o.controls).toEqual({ pause: false, jump: false, fullscreen: false, reload: false });
});
});