Skip to content

Commit 3d0d099

Browse files
committed
fix: allow text selection on test filenames in CompareGold
1 parent d319029 commit 3d0d099

4 files changed

Lines changed: 29 additions & 5 deletions

File tree

build/tools/CompareGold/wwwroot/app.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ async function reload() {
5656
}
5757
// Load thresholds for this suite
5858
const tRes = await fetch(`/api/thresholds?suite=${enc(suite)}`);
59-
const thresholdRules = await tRes.json();
59+
const thresholdRules = tRes.ok ? await tRes.json() : [];
6060
// Only include suite if it has any images
6161
if (gold.length > 0 || Object.values(srcImgs).some(imgs => imgs.length > 0))
6262
suiteData[suite] = { gold, sourceImages: srcImgs, thresholdRules };
@@ -274,7 +274,8 @@ function renderTable() {
274274
} else if (!img.hasGold) {
275275
cellHtml = '<span class="cell new">○ new</span>';
276276
} else if (stats) {
277-
const cls = stats.diffPixels === 0 ? 'pass' : 'fail';
277+
const result = checkCellThreshold(img.suite, img.name, stats);
278+
const cls = result.passed ? 'pass' : 'fail';
278279
cellHtml = `<span class="cell ${cls}">${cls === 'pass' ? '✓' : '✗'} d=${stats.maxDiff}</span>`;
279280
} else {
280281
cellHtml = `<span class="cell" data-stats-key="${esc(statsKey)}" style="color:#666">...</span>`;
@@ -296,7 +297,11 @@ function renderTable() {
296297
}
297298

298299
tr.innerHTML = cells;
299-
tr.onclick = () => toggleExpand(key);
300+
tr.onmousedown = (e) => { tr._clickX = e.clientX; tr._clickY = e.clientY; };
301+
tr.onclick = (e) => {
302+
if (Math.abs(e.clientX - tr._clickX) > 3 || Math.abs(e.clientY - tr._clickY) > 3) return;
303+
toggleExpand(key);
304+
};
300305
tbody.appendChild(tr);
301306

302307
if (isExp) {
@@ -526,10 +531,27 @@ async function runStatsQueue() {
526531
statsRunning = false;
527532
}
528533

534+
function checkCellThreshold(suite, name, stats) {
535+
const data = suiteData[suite];
536+
const rules = data?.thresholdRules || [];
537+
const [platApi, device] = currentPlatform.split('/');
538+
const dotIdx = platApi?.indexOf('.') ?? -1;
539+
const plat = dotIdx >= 0 ? platApi.substring(0, dotIdx) : platApi;
540+
const api = dotIdx >= 0 ? platApi.substring(dotIdx + 1) : null;
541+
const allow = resolveThreshold(rules, name, plat, api, device);
542+
if (stats.pixelDiffs) return checkThreshold(stats.pixelDiffs, allow);
543+
// Fallback for stats without pixelDiffs
544+
return { passed: stats.diffPixels === 0, details: [] };
545+
}
546+
529547
function updateCellInline(key, stats) {
530548
const el = document.querySelector(`[data-stats-key="${CSS.escape(key)}"]`);
531549
if (!el) return;
532-
const cls = stats.diffPixels === 0 ? 'pass' : 'fail';
550+
const parts = key.split(':');
551+
const suite = parts[1];
552+
const name = parts.slice(2).join(':');
553+
const result = checkCellThreshold(suite, name, stats);
554+
const cls = result.passed ? 'pass' : 'fail';
533555
el.className = `cell ${cls}`;
534556
el.removeAttribute('style');
535557
el.removeAttribute('data-stats-key');

build/tools/CompareGold/wwwroot/diff.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ function resolveThreshold(rules, imageName, platform, api, device) {
115115
}
116116

117117
// Check pixelDiffs against allow buckets. Returns { passed, details[] }
118+
// Only explicitly specified ranges are checked. Unspecified ranges are not limited.
118119
function checkThreshold(pixelDiffs, allow) {
119120
if (!allow) {
120121
// Default: 3+: 0

build/tools/CompareGold/wwwroot/style.css

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ th { text-align: left; padding: 8px 10px; border-bottom: 2px solid #333; font-si
3535
th:hover { color: #4fc3f7; }
3636
th.right { text-align: right; }
3737
td { padding: 6px 10px; border-bottom: 1px solid #222244; vertical-align: top; }
38-
tr.row { cursor: pointer; user-select: none; }
38+
tr.row { cursor: pointer; }
39+
tr.row .thumb, tr.row .cell, tr.row .cb { user-select: none; }
3940
tr.row:hover { background: #222244; }
4041
tr.row.expanded { background: #1a2a4a; }
4142
tr.row.kb-focus, tr.suite-row.kb-focus { outline: 1px solid #4fc3f7; outline-offset: -1px; }
File renamed without changes.

0 commit comments

Comments
 (0)