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
3.83 kB
import { afterEach, describe, expect, it } from 'vitest';
import type { Schemas } from '../../api/client';
import { groupRuns } from './AppSidebar';
import { DEFAULT_PREFS, readPrefs } from './prefs';
import { runState } from './StatusDot';
type RunSummary = Schemas['RunSummary'];
const run = (id: string, status: string, extra: Partial<RunSummary> = {}): RunSummary => ({
run_id: id, status, created_at: `2026-10-17T10:${id.padStart(2, '0')}:00`, modules: ['P2P'], decisions: {}, orchestrator: 'langgraph',
playwright_mode: 'stub', trigger: 'api', ...extra,
} as RunSummary);
describe('shell', () => {
afterEach(() => window.localStorage.clear());
it('maps every run status onto one dot state', () => {
expect(runState(run('1', 'queued'))).toBe('queued');
expect(runState(run('1', 'running'))).toBe('running');
expect(runState(run('1', 'waiting_approval', { pending_gate: 'approve_cases' }))).toBe('waiting');
expect(runState(run('1', 'waiting_review', { pending_gate: 'human_review' }))).toBe('waiting');
expect(runState(run('1', 'completed', { decisions: { P2P: 'GO' } }))).toBe('done-ready');
expect(runState(run('1', 'completed', { decisions: { P2P: 'GO', O2C: 'NO-GO' } }))).toBe('done-notready');
expect(runState(run('1', 'completed', { decision: 'HELD' }))).toBe('done-held');
expect(runState(run('1', 'completed'))).toBe('done');
expect(runState(run('1', 'failed'))).toBe('failed');
expect(runState(run('1', 'killed'))).toBe('failed');
expect(runState(run('1', 'cancelled'))).toBe('stopped');
expect(runState(run('1', 'interrupted'))).toBe('paused');
});
it('groups sidebar runs: all that need you, then running, then recent, at most 12', () => {
const items = [
...Array.from({ length: 10 }, (_, i) => run(String(i + 10), 'completed')),
run('1', 'running'), run('2', 'waiting_approval', { pending_gate: 'approve_cases' }), run('3', 'queued'),
run('4', 'waiting_review', { pending_gate: 'human_review' }),
];
const g = groupRuns(items, 12);
expect(g.map((x) => x.title)).toEqual(['Waiting for you', 'Running', 'Recent']);
expect(g[0].runs.map((r) => r.run_id)).toEqual(['2', '4']);
expect(g[1].runs.map((r) => r.run_id)).toEqual(['1', '3']);
expect(g.flatMap((x) => x.runs)).toHaveLength(12);
expect(g[2].runs[0].run_id).toBe('19'); // newest first
expect(groupRuns([run('5', 'completed')]).map((x) => x.title)).toEqual(['Recent']); // empty groups are hidden
});
it('reads per-user prefs safely, with defaults for missing or broken values', () => {
expect(readPrefs('alice')).toEqual(DEFAULT_PREFS);
window.localStorage.setItem('fpt.ui.alice', '{not json');
expect(readPrefs('alice')).toEqual(DEFAULT_PREFS);
window.localStorage.setItem('fpt.ui.alice', JSON.stringify({ sidebar: 'rail', panel: { width: 520, tab: 'nonsense' }, env: 3 }));
expect(readPrefs('alice')).toEqual({ sidebar: 'rail', panel: { open: true, width: 520, tab: 'live' }, env: 3 });
expect(readPrefs('bob')).toEqual(DEFAULT_PREFS);
});
});
describe('run stage card', () => {
it('is the one guide element, with a stage kicker and a progress line in words', async () => {
const { renderUi } = await import('../../test/utils');
const { StageCard } = await import('../../pages/run/RunStage');
const { screen } = await import('@testing-library/react');
renderUi(<StageCard stage="judge"><p>body</p></StageCard>);
expect(screen.getByTestId('run-guide')).toHaveAttribute('data-stage', 'judge');
expect(screen.getByText('Step 3 of 4: your decision')).toBeInTheDocument();
expect(screen.getByRole('img', { name: 'Progress of this test run: stage 3 of 4, Your decision' })).toBeInTheDocument();
});
});