feat(overlay): flash the row on a new time, ticking pit clock and split badges (1.88.0)
This commit is contained in:
1 parent
ee290a4ab8
commit
f5b77d5589
11 files changed
+304
-6
No files matched your search
@@ -0,0 +1,62 @@
|
||||
import assert from "node:assert/strict";
|
||||
|
||||
// Overlay live marks in a real browser: a new time flashes the row, a car in the pits gets a
|
||||
// ticking clock with a fuel pump next to its time, and a new split shows - on the regular
|
||||
// leaderboard and the OBS tower.
|
||||
export async function runOverlayLiveMarksSmoke({ evaluate }) {
|
||||
const result = await evaluate(`(async () => {
|
||||
const { renderOverlayLeaderboard, renderObsOverlay } = await import('/src/overlays.js');
|
||||
const { refreshLiveMarkNodes } = await import('/src/overlay_live_marks.js');
|
||||
const { escapeHtml } = await import('/src/html_escape.js');
|
||||
const frame = document.createElement('iframe');
|
||||
frame.style.cssText = 'position:fixed;left:0;top:0;width:1200px;height:700px;border:0;z-index:99999';
|
||||
document.body.append(frame);
|
||||
const doc = frame.contentDocument;
|
||||
const style = doc.createElement('link'); style.rel = 'stylesheet'; style.href = '/src/styles.css';
|
||||
const loaded = new Promise((resolve, reject) => { style.onload = resolve; style.onerror = reject; });
|
||||
doc.head.append(style); await loaded;
|
||||
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||
const deps = { t: (key) => key, escapeHtml, formatLap: (ms) => (ms / 1000).toFixed(3), formatTeamActiveMemberLabel: () => '', formatPredictedLapDelta: () => '-', getVisiblePassings: () => [], getEventName: () => 'Club', getSessionTypeLabel: () => 'Practice', getStartModeLabel: () => '', getStatusLabel: () => '', getObsOverlayConfig: () => ({ layout: 'broadcast', rows: 10, showClock: true, showLaps: true, showResult: true, showBest: true, showGap: true }), normalizeStartMode: (v) => v, renderPositionGrid: () => '', getSessionGridEntries: () => [], getSessionGridOrder: () => [] };
|
||||
const now = Date.now();
|
||||
let rows = [{ key: 'lm_a', displayName: 'Anna', laps: 3, resultDisplay: '3/0:41.000', bestLapMs: 13500, lastTimestamp: now - 5000 }, { key: 'lm_b', displayName: 'Bo', laps: 3, resultDisplay: '3/0:42.000', bestLapMs: 13700, lastTimestamp: now - 4000 }];
|
||||
const out = {};
|
||||
try {
|
||||
doc.body.innerHTML = '<div class="overlay-board"></div>';
|
||||
const board = doc.querySelector('.overlay-board');
|
||||
const draw = () => { board.innerHTML = renderOverlayLeaderboard(rows, deps, { sortable: false }); };
|
||||
draw();
|
||||
out.flashOnOpen = board.querySelectorAll('.is-passing').length;
|
||||
rows = rows.map((row) => row.key === 'lm_a' ? { ...row, laps: 4, lastTimestamp: now + 1 } : row);
|
||||
draw();
|
||||
const flashed = board.querySelector('.overlay-race-row.is-passing');
|
||||
out.flashed = flashed?.dataset.overlayCompetitor || '';
|
||||
out.animation = flashed ? getComputedStyle(flashed).animationName : '';
|
||||
rows = rows.map((row) => row.key === 'lm_b' ? { ...row, pitActive: true, pitEnteredAt: now } : row);
|
||||
draw();
|
||||
const clock = () => board.querySelector('[data-overlay-competitor="lm_b"] [data-pit-clock] b')?.textContent || '';
|
||||
out.pitIcon = Boolean(board.querySelector('[data-overlay-competitor="lm_b"] .overlay-pit-badge svg'));
|
||||
const before = clock();
|
||||
await wait(450);
|
||||
refreshLiveMarkNodes(doc);
|
||||
out.pitTicks = before !== clock() && /^0:00\\.[0-9]$/.test(clock());
|
||||
rows = rows.map((row) => row.key === 'lm_a' ? { ...row, lastSplitTimestamp: now + 2, lastSplitMs: 5123, lastSplitDeltaMs: -120 } : row);
|
||||
draw();
|
||||
out.split = board.querySelector('[data-overlay-competitor="lm_a"] .overlay-split-chip')?.textContent.trim() || '';
|
||||
doc.body.innerHTML = '<section class="overlay-shell-obs"></section>';
|
||||
rows = rows.map((row) => row.key === 'lm_a' ? { ...row, laps: 5, lastTimestamp: now + 3 } : row);
|
||||
doc.body.firstElementChild.innerHTML = renderObsOverlay({ name: 'Practice', eventId: 'e', status: 'running', type: 'open_practice' }, rows, {}, { remainingMs: 300000 }, {}, deps);
|
||||
out.obsFlash = doc.querySelectorAll('.obs-tv-row.is-passing').length;
|
||||
out.obsPit = Boolean(doc.querySelector('.obs-tv-row [data-pit-clock]'));
|
||||
} finally { frame.remove(); }
|
||||
return out;
|
||||
})()`);
|
||||
assert.equal(result.flashOnOpen, 0, "nothing flashes when the overlay opens");
|
||||
assert.equal(result.flashed, "lm_a", "the driver with the new time flashes");
|
||||
assert.equal(result.animation, "overlay-pass");
|
||||
assert.equal(result.pitIcon, true, "fuel pump next to the time");
|
||||
assert.equal(result.pitTicks, true, "the pit clock ticks without a redraw");
|
||||
assert.match(result.split, /^S 5\.123 −0\.120$/);
|
||||
assert.equal(result.obsFlash, 1, "the OBS tower flashes too");
|
||||
assert.equal(result.obsPit, true, "and shows the pit clock");
|
||||
console.log("PASS overlay live marks: a new time flashes the row, the pit clock ticks with a fuel pump, a new split shows - leaderboard and OBS tower");
|
||||
}
|
||||
Reference in new issue
Block a user