mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-06-04 04:51:17 +00:00
test(#1360): RED — assert pill body emits letter + count
Pure-string assertions over public/map.js mirroring #1356 pattern. Fails on current master where pill body is just `letter`. Wires test-issue-1360-pill-letter-count.js into deploy.yml right after test-issue-1356-map-a11y.js.
This commit is contained in:
@@ -107,6 +107,7 @@ jobs:
|
||||
node test-area-filter.js
|
||||
node test-issue-1293-marker-shapes.js
|
||||
node test-issue-1356-map-a11y.js
|
||||
node test-issue-1360-pill-letter-count.js
|
||||
|
||||
- name: Verify proto syntax
|
||||
run: |
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/**
|
||||
* #1360 — regression(map): #1357 cluster role pills lost the count number.
|
||||
*
|
||||
* Pill body must contain BOTH the role letter (WCAG carrier from #1356)
|
||||
* AND the per-role count (the data sighted operators need at a glance).
|
||||
*
|
||||
* Pure-string assertions over public/map.js (mirrors #1356 test pattern).
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
let passed = 0, failed = 0;
|
||||
function assert(cond, msg) {
|
||||
if (cond) { passed++; console.log(' ✓ ' + msg); }
|
||||
else { failed++; console.error(' ✗ ' + msg); }
|
||||
}
|
||||
|
||||
const mapSrc = fs.readFileSync(path.join(__dirname, 'public', 'map.js'), 'utf8');
|
||||
|
||||
console.log('\n=== #1360: pill body emits letter + count (not letter alone) ===');
|
||||
|
||||
// A. Source must concatenate letter and n (the count) into the pill body.
|
||||
// Acceptable shapes: `letter + n`, `letter + String(n)`, `(letter + n)`.
|
||||
const concatRe = /letter\s*\+\s*(?:String\()?\s*n\b/;
|
||||
assert(concatRe.test(mapSrc),
|
||||
'map.js concatenates letter + n (or letter + String(n)) for pill body');
|
||||
|
||||
// B. The pill body must NOT be bare `letter` followed immediately by '</span>'.
|
||||
// i.e. reject `... + letter + '</span>'` with nothing in between.
|
||||
const bareLetterRe = /\+\s*letter\s*\+\s*['"]<\/span>/;
|
||||
assert(!bareLetterRe.test(mapSrc),
|
||||
'pill body is no longer just letter (no `+ letter + "</span>"` pattern)');
|
||||
|
||||
// C. Simulate makeClusterIcon by exercising __meshcoreMapInternals if loadable
|
||||
// in Node — fallback: pattern-check the rendered HTML template.
|
||||
// map.js is browser-oriented (Leaflet IIFE) so we string-test the template.
|
||||
// Build a synthetic expected pill body: a letter from R/C/M/S/O + digits.
|
||||
// The assertion below validates the rendered shape via regex over the
|
||||
// template's emitted output pattern.
|
||||
const pillTemplateRe = /<span class="mc-pill[\s\S]{0,400}letter\s*\+\s*(?:String\()?\s*n/;
|
||||
assert(pillTemplateRe.test(mapSrc),
|
||||
'pill HTML template body interpolates letter + n inside the span');
|
||||
|
||||
// D. Letter is still the first character of the pill body (preserves #1356
|
||||
// WCAG carrier ordering — assistive scanning sees the role letter first).
|
||||
// The concatenation must be `letter + n`, not `n + letter`.
|
||||
const reverseRe = /\bn\s*\+\s*letter\b/;
|
||||
assert(!reverseRe.test(mapSrc),
|
||||
'letter precedes count in concatenation (letter + n, not n + letter)');
|
||||
|
||||
// E. Acceptance criterion from the issue: pill body matches /^[RCMSO]\d+$/
|
||||
// for non-zero counts. Verify ROLE_LETTERS maps to the expected set.
|
||||
const roleLettersRe = /ROLE_LETTERS\s*=\s*\{([\s\S]*?)\}/;
|
||||
const rlMatch = mapSrc.match(roleLettersRe);
|
||||
assert(rlMatch, 'ROLE_LETTERS map is defined in map.js');
|
||||
if (rlMatch) {
|
||||
const letters = (rlMatch[1].match(/'[A-Z]'/g) || []).map(function (s) { return s[1]; });
|
||||
const expected = ['R', 'C', 'M', 'S', 'O'];
|
||||
const haveAll = expected.every(function (l) { return letters.indexOf(l) !== -1; });
|
||||
assert(haveAll,
|
||||
'ROLE_LETTERS includes R, C, M, S, O so pill body matches /^[RCMSO]\\d+$/');
|
||||
}
|
||||
|
||||
console.log('\n=== Summary ===');
|
||||
console.log(' Passed: ' + passed);
|
||||
console.log(' Failed: ' + failed);
|
||||
console.log('\n#1360 ' + (failed === 0 ? 'PASS' : 'FAIL'));
|
||||
process.exit(failed === 0 ? 0 : 1);
|
||||
Reference in New Issue
Block a user