import { Anchor, Button, Group, Image, Modal, SegmentedControl, SimpleGrid, Stack, Text, TextInput, Title, UnstyledButton } from '@mantine/core'; import { IconExternalLink, IconListNumbers, IconLock, IconPhoto, IconPhotoOff, IconSearch } from '@/components/icons'; import { useMemo, useState } from 'react'; import { useEvidence, useRunScenarios } from '../../api/hooks'; import type { Evidence } from '../../api/types'; import { Can, ErrorAlert, Pager } from '../../components/common'; import { EmptyState, LoadingState } from '../../components/states'; import './report.css'; import { useSidePanelOptional } from '../../components/shell/SidePanel'; const PAGE = 6; const OUTCOME: Record = { passed: ['green', 'Passed'], failed: ['red', 'Failed'], skipped: ['neutral', 'Not run'] }; /** Proof of what the test browser did: per scenario, the values it entered and the screen it ended on. */ export type ProofFilter = 'all' | 'failed' | 'passed'; export function RunProof({ id, quick, oneColumn = false, fusionPod = null, filter: initialFilter = 'all' }: { id: string; quick: boolean; oneColumn?: boolean; fusionPod?: string | null; filter?: ProofFilter; }) { const ev = useEvidence(id); const sc = useRunScenarios(id); const panel = useSidePanelOptional(); const [q, setQ] = useState(''); const [offset, setOffset] = useState(0); const [filter, setFilter] = useState(initialFilter); const [big, setBig] = useState<{ src: string; title: string } | null>(null); const rows = useMemo(() => { const by = new Map(); for (const e of ev.data ?? []) if (e.case_id) by.set(e.case_id, [...(by.get(e.case_id) ?? []), e]); const titles = new Map((sc.data?.scenarios ?? []).map((s) => [s.id, s])); return [...by.entries()].map(([caseId, files]) => { const last = Math.max(...files.map((f) => f.attempt)); const mine = files.filter((f) => f.attempt === last); const shots = mine.filter((f) => f.content_type.startsWith('image/')); return { caseId, s: titles.get(caseId), shot: shots[shots.length - 1], video: mine.find((f) => f.content_type.startsWith('video/')) }; }).filter((r) => r.shot).sort((a, b) => a.caseId.localeCompare(b.caseId)); }, [ev.data, sc.data]); if (quick) return } title="No screens in a quick simulation" body="A quick simulation starts no browser. Start a full browser run to see the screens the test browser ended on." />; if (ev.isLoading || sc.isLoading) return ; if (ev.error) return void ev.refetch()} />; if (!rows.length) return } title="No screens yet" body="They appear here as each group of scenarios finishes." />; const needle = q.trim().toLowerCase(); const shown = rows.filter((r) => (!needle || `${r.caseId} ${r.s?.title ?? ''}`.toLowerCase().includes(needle)) && (filter === 'all' || (filter === 'failed' ? r.s?.outcome === 'failed' : r.s?.outcome === 'passed' || r.s?.outcome === 'flaky'))); const failedCount = rows.filter((r) => r.s?.outcome === 'failed').length; const where = fusionPod ? `Screens come from the Oracle Fusion pod ${fusionPod}.` : 'Screens come from the practice environment (the mock app), not Oracle Fusion.'; const page = shown.slice(offset, offset + PAGE); return ( } title="Your role cannot open test evidence" />}> For each scenario: the test data it used and the screen the test browser ended on, saved by the browser itself. Compare the two to check the entry. {oneColumn ? '' : ` ${where}`} } size="xs" w={oneColumn ? '100%' : 260} value={q} onChange={(e) => { setQ(e.currentTarget.value); setOffset(0); }} /> { setFilter(v as ProofFilter); setOffset(0); }} aria-label="Show screens" data={[{ value: 'all', label: 'All' }, { value: 'failed', label: `Failed ${failedCount}` }, { value: 'passed', label: 'Passed' }]} /> {shown.length} scenario{shown.length === 1 ? '' : 's'} with a saved screen {page.map(({ caseId, s, shot, video }) => { const [tone, word] = OUTCOME[s?.outcome ?? ''] ?? ['neutral', s?.outcome ?? 'tested']; const name = s?.title ?? caseId; const values = (s?.test_data ?? []).flatMap((d) => Object.entries(d.values)).filter(([, v]) => !/\{\{|POD-REQUIRED/.test(String(v))); return (
{name} {caseId}
{panel && } {word}
{shot.available === false ? (
This screenshot is no longer stored: the server restarted before screenshots were kept outside it.
) : ( <> setBig({ src: `/api/evidence/${shot.evidence_id}`, title: name })} title="See the screen full size" aria-label={`See the final screen of ${name} full size`}> {`final Open in a new tab )} {s?.expected_result &&
Expected result

{s.expected_result}

} {values.length > 0 && (
Test data used

{values.slice(0, 8).map(([k, v]) => `${k.replace(/_/g, ' ')}: ${v}`).join(' ยท ')}

)} {video && video.available !== false && Watch the recording}
); })}
{shown.length === 0 && No screens match this filter.} {oneColumn && {where}} setBig(null)} title={big ? `Screen: ${big.title}` : ''} size="xl" centered> {big && {`final} {big && Open in a new tab}
); }