All files / core/blong-browser/src/components/TestRun TestRunBars.tsx

93.75% Statements 15/16
86.36% Branches 19/22
100% Functions 3/3
93.75% Lines 15/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129                7x     18x                   92x                                           195x 195x                 195x                     195x 195x                 195x           195x   195x 18x                                 177x 177x 177x                                                    
/**
 * The timeline half of the run tree-table: the sticky ruler, the bar cells and the now marker.
 * The bars are plain CSS boxes positioned by percentage, so every row shares the ruler's scale.
 */
import type {ITestRunRowLayout, ITestRunTreeLayout} from '../../types/testRun.js';
import {barPct, nowPct, timePct} from './testRunLayout.js';
import {assertionLabel, formatDuration} from './testRunModel.js';
 
const EMPTY_CELL = <span className="blong-test-run__cell" />;
 
export function TestRunRuler({layout}: {layout: ITestRunTreeLayout}) {
    return (
        <div
            className="blong-test-run__grid blong-test-run__ruler"
            aria-hidden="true"
        >
            {EMPTY_CELL}
            {EMPTY_CELL}
            {EMPTY_CELL}
            <div className="blong-test-run__track">
                {layout.ticks.map(tick => (
                    <span
                        key={tick.at}
                        className="blong-test-run__tick"
                        style={{left: `${timePct(tick.at, layout.t0, layout.t1)}%`}}
                    >
                        <span className="blong-test-run__tick-label">{tick.label}</span>
                    </span>
                ))}
            </div>
        </div>
    );
}
 
export interface ITestRunBarProps {
    row: ITestRunRowLayout;
    layout: ITestRunTreeLayout;
    /** Present only while the run is live; a finished run has no now marker. */
    now?: number;
    critical?: boolean;
}
 
export function TestRunBar({row, layout, now, critical}: ITestRunBarProps) {
    const queueMs = row.span && row.kind === 'step' ? row.span.queueEnd - row.span.start : 0;
    const tooltip = [
        row.label,
        formatDuration(row.duration),
        queueMs > 0 ? `queued ${formatDuration(queueMs)}` : undefined,
        row.assertions ? `assertions ${assertionLabel(row.assertions)}` : undefined,
    ]
        .filter(Boolean)
        .join(' ยท ');
 
    Iif (!row.span) {
        return (
            <div
                className="blong-test-run__track"
                title={tooltip}
            >
                <span className="blong-test-run__bar-empty" />
            </div>
        );
    }
 
    const {left, width, queueWidth} = barPct(row.span, layout.t0, layout.t1);
    const classes = [
        'blong-test-run__bar',
        `blong-test-run__bar--${row.status}`,
        row.kind === 'group' ? 'blong-test-run__bar--group' : '',
        critical ? 'blong-test-run__bar--critical' : '',
    ]
        .filter(Boolean)
        .join(' ');
    const nowMarker =
        now === undefined ? null : (
            <span
                className="blong-test-run__now"
                style={{left: `${nowPct(now, layout.t0, layout.t1)}%`}}
            />
        );
    const sr = <span className="blong-test-run__sr">duration {formatDuration(row.duration)}</span>;
 
    if (row.kind === 'group') {
        return (
            <div
                className="blong-test-run__track"
                title={tooltip}
            >
                <div
                    className={classes}
                    style={{left: `${left}%`, width: `${Math.max(width, 0.6)}%`}}
                />
                {nowMarker}
                {sr}
            </div>
        );
    }
 
    // The queue is a thin line so a long wait does not read as work; the solid bar is the
    // execution measured from the moment the step actually started.
    const executionLeft = left + queueWidth;
    const executionWidth = Math.max(0, width - queueWidth);
    return (
        <div
            className="blong-test-run__track"
            title={tooltip}
            data-step-name={row.stepName}
        >
            {queueMs > 0 && (
                <span
                    className="blong-test-run__queue-line"
                    style={{left: `${left}%`, width: `${queueWidth}%`}}
                />
            )}
            <div
                className={classes}
                style={{
                    left: `${executionLeft}%`,
                    width: `${Math.max(executionWidth, 1.2)}%`,
                }}
            >
                {row.status === 'failed' && <span className="blong-test-run__bar-fail" />}
            </div>
            {nowMarker}
            {sr}
        </div>
    );
}