File size: 3,239 Bytes
a289b2a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | import { Group, Text, Tooltip } from '@mantine/core';
import { IconAlertTriangle, IconArrowRight, IconCircleCheck, IconCircleDashed, IconMinus, IconX } from '@tabler/icons-react';
import type { ReactNode } from 'react';
import type { ProcessStep } from '../api/types';
import { STEP_STATE } from '../glossary';
const ICON: Record<string, ReactNode> = {
failing: <IconX size={12} aria-hidden />, gap: <IconAlertTriangle size={12} aria-hidden />, not_tested: <IconCircleDashed size={12} aria-hidden />,
passed: <IconCircleCheck size={12} aria-hidden />, not_affected: <IconMinus size={12} aria-hidden />,
};
function detail(s: ProcessStep) {
const parts = [STEP_STATE[s.state]?.label ?? s.state];
if (s.scenarios) parts.push(`${s.scenarios} scenario(s) in this test run: ${s.passed} passed${s.flaky ? `, ${s.flaky} passed on retry` : ''}${s.failed ? `, ${s.failed} failing` : ''}${s.not_run ? `, ${s.not_run} not run yet` : ''}`);
else parts.push(`${s.library} scenario(s) in the library`);
if (s.touched) parts.push('changed by this patch');
return parts.join(' · ');
}
export function StepChip({ s }: { s: ProcessStep }) {
const st = STEP_STATE[s.state] ?? { label: s.state, tone: 'neutral' };
return (
<Tooltip label={detail(s)} multiline w={280} withArrow>
<span className="fpt-pill" data-tone={st.tone} tabIndex={0} role="listitem" aria-label={`${s.name}: ${detail(s)}`}
data-testid={`step-${s.name}`} data-state={s.state} style={{ padding: '4px 10px', fontSize: 12 }}>
{ICON[s.state]}{s.name}
{s.scenarios > 0 && <span style={{ opacity: 0.75, fontWeight: 400 }}>{s.passed + s.flaky}/{s.scenarios}</span>}
</span>
</Tooltip>
);
}
/** A module's business process: the flow steps in order (from the coverage map), cross-cutting steps beside it. */
export function ProcessFlow({ steps, mainOnly = false }: { steps: ProcessStep[]; mainOnly?: boolean }) {
const flow = steps.filter((s) => !s.cross_cutting && !s.group);
const addon = steps.filter((s) => !s.cross_cutting && s.group);
const cross = steps.filter((s) => s.cross_cutting);
const row = (list: ProcessStep[], arrows: boolean) => (
<div role="list" style={{ display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: 6 }}>
{list.map((s, i) => (
<span key={s.key} style={{ display: 'inline-flex', alignItems: 'center', gap: 6 }}>
{arrows && i > 0 && <IconArrowRight size={12} color="var(--fpt-dim)" aria-hidden />}
<StepChip s={s} />
</span>
))}
</div>
);
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
{row(flow, true)}
{!mainOnly && addon.length > 0 && <div><Text size="xs" c="dimmed" mb={4}>{addon[0].group}</Text>{row(addon, false)}</div>}
{!mainOnly && cross.length > 0 && <div><Text size="xs" c="dimmed" mb={4}>Across the whole process</Text>{row(cross, false)}</div>}
</div>
);
}
export function StepLegend() {
return (
<Group gap={6} aria-label="legend">
{Object.entries(STEP_STATE).map(([k, v]) => <span key={k} className="fpt-pill" data-tone={v.tone}>{ICON[k]}{v.label}</span>)}
</Group>
);
}
|