92 lines
3.7 KiB
JavaScript
92 lines
3.7 KiB
JavaScript
import React from 'react';
|
|
import { render, screen, fireEvent, within } from '@testing-library/react';
|
|
|
|
jest.mock('lucide-react', () =>
|
|
new Proxy(
|
|
{},
|
|
{
|
|
get: (_t, prop) =>
|
|
prop === '__esModule' ? true : (props) => <span data-testid={`icon-${String(prop)}`} {...props} />,
|
|
}
|
|
)
|
|
);
|
|
|
|
import Agents from '@/pages/doormile/agents/Agents';
|
|
import { SNAPSHOT_AT, SNAPSHOT_LABEL, networkStats } from '@/lib/agentNetwork';
|
|
|
|
/**
|
|
* The Agents page.
|
|
*
|
|
* It is drawn from a hand-maintained snapshot (lib/agentNetwork.js) plus a
|
|
* scenario player (AgentFlowVisualizer) — neither is a feed from AI_engine,
|
|
* which exposes nothing this console can read. The risk these tests guard is
|
|
* the page PRESENTING that as live: a status board that looks real-time and is
|
|
* days old is worse than one that says how old it is.
|
|
*
|
|
* Rewritten 2026-09-29 for the flow-visualizer layout (the card grid these
|
|
* tests used to target is gone). The honesty checks were kept, not dropped.
|
|
*/
|
|
|
|
describe('the Agents page', () => {
|
|
it('says how old its figures are, as a machine-readable date', () => {
|
|
render(<Agents />);
|
|
const stamp = screen.getByText(new RegExp(SNAPSHOT_LABEL));
|
|
expect(stamp.tagName).toBe('TIME');
|
|
expect(stamp).toHaveAttribute('dateTime', SNAPSHOT_AT);
|
|
expect(stamp).toHaveTextContent(/Snapshot/);
|
|
});
|
|
|
|
it('does not call itself real-time or live', () => {
|
|
const { container } = render(<Agents />);
|
|
expect(screen.queryByText(/Real-Time/i)).not.toBeInTheDocument();
|
|
expect(screen.queryByText(/^Live Activity$/i)).not.toBeInTheDocument();
|
|
// The pulsing "on air" dot is gone from the header.
|
|
expect(container.querySelector('h1').parentElement.querySelector('.animate-pulse')).toBeNull();
|
|
});
|
|
|
|
it('labels the activity panel as a simulation', () => {
|
|
render(<Agents />);
|
|
expect(screen.getByText('Sample Activity')).toBeInTheDocument();
|
|
expect(screen.getByText(/Simulation · not live data/)).toBeInTheDocument();
|
|
});
|
|
|
|
it('takes its status counts from the snapshot, not hard-coded numbers', () => {
|
|
render(<Agents />);
|
|
const s = networkStats();
|
|
expect(screen.getByText(`${s.working} Processing`)).toBeInTheDocument();
|
|
expect(screen.getByText(`${s.degraded} Warning`)).toBeInTheDocument();
|
|
expect(screen.getByText(`${s.total - s.working - s.degraded} Idle`)).toBeInTheDocument();
|
|
});
|
|
|
|
it('states that no autonomy gate is on, out of the agents that have one', () => {
|
|
// The page's central claim: the swarm observes and alerts, and does not
|
|
// write to the system. The denominator is gated agents, not all agents.
|
|
render(<Agents />);
|
|
const s = networkStats();
|
|
expect(s.autonomyOn).toBe(0);
|
|
expect(screen.getByText(`Autonomy gates on: 0 / ${s.gated}`)).toBeInTheDocument();
|
|
});
|
|
|
|
it('lists all nine agents in the flow', () => {
|
|
render(<Agents />);
|
|
['JARVIS Orchestrator', 'Order', 'Dispatch', 'Exception', 'Route Optimizer', 'Fleet', 'Hub', 'Express Dispatch', 'Customer'].forEach(
|
|
(name) => {
|
|
expect(screen.getByRole('button', { name })).toBeInTheDocument();
|
|
}
|
|
);
|
|
});
|
|
|
|
it('opens the technical record of the agent that was clicked', () => {
|
|
render(<Agents />);
|
|
fireEvent.click(screen.getByRole('button', { name: 'Exception' }));
|
|
fireEvent.click(screen.getByRole('button', { name: /Technical Specs/ }));
|
|
expect(screen.getAllByText(/EXCEPTION_AGENT/).length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it('shows the grouped error counts from the run log', () => {
|
|
render(<Agents />);
|
|
const diagnostics = screen.getByText('System Diagnostics').closest('div.flex-col');
|
|
expect(within(diagnostics).getByText('8,594 occurrences')).toBeInTheDocument();
|
|
});
|
|
});
|