diff --git a/server/web/assets/app.js b/server/web/assets/app.js index b26116b..8cd748f 100644 --- a/server/web/assets/app.js +++ b/server/web/assets/app.js @@ -1327,6 +1327,14 @@ function renderMTRStats(stats) { if (!hostParts.ip && !hostParts.host) { hostCell.textContent = '--'; } + const marker = stat && stat.response && stat.response.kind === 'unreachable' + ? String(stat.response.marker || '').trim() : ''; + if (marker) { + const markerSpan = document.createElement('span'); + markerSpan.className = 'mtr-response-marker'; + markerSpan.textContent = ` ${marker}`; + hostCell.appendChild(markerSpan); + } if (geoText) { const geoDiv = document.createElement('div'); geoDiv.className = 'attempt__geo'; @@ -1339,14 +1347,6 @@ function renderMTRStats(stats) { mplsDiv.textContent = mplsText; hostCell.appendChild(mplsDiv); } - const marker = stat && stat.response && stat.response.kind === 'unreachable' - ? String(stat.response.marker || '').trim() : ''; - if (marker) { - const markerSpan = document.createElement('span'); - markerSpan.className = 'mtr-response-marker'; - markerSpan.textContent = ` ${marker}`; - hostCell.appendChild(markerSpan); - } tbody.appendChild(row); }); diff --git a/server/web/assets/mtr_truncation.test.cjs b/server/web/assets/mtr_truncation.test.cjs index 6ca885d..08e2e47 100644 --- a/server/web/assets/mtr_truncation.test.cjs +++ b/server/web/assets/mtr_truncation.test.cjs @@ -11,15 +11,23 @@ function loadAppRawIngestor() { const classList = {add() {}, remove() {}, toggle() {}}; const element = () => ({ classList, + children: [], dataset: {}, parentElement: {classList}, addEventListener() {}, + appendChild(child) { + this.children.push(child); + return child; + }, }); + const resultNode = element(); const context = vm.createContext({ console, document: { body: {classList}, - getElementById: element, + createElement: element, + createTextNode: (text) => ({nodeType: 3, textContent: text}), + getElementById: (id) => id === 'result' ? resultNode : element(), addEventListener() {}, }, window: { @@ -30,7 +38,7 @@ function loadAppRawIngestor() { const appPath = path.join(__dirname, 'app.js'); vm.runInContext(fs.readFileSync(appPath, 'utf8'), context, {filename: appPath}); - return (records, summary) => { + const ingest = (records, summary) => { context.__records = records; context.__summary = summary; vm.runInContext(` @@ -42,6 +50,14 @@ function loadAppRawIngestor() { `, context); return JSON.parse(JSON.stringify(context.__rows)); }; + + ingest.render = (stats) => { + context.__stats = stats; + resultNode.children = []; + vm.runInContext('renderMTRStats(__stats);', context); + return resultNode; + }; + return ingest; } const rows = [ @@ -102,3 +118,27 @@ test('unreachable marker follows the current path edge, not a stale raw response }); assert.equal(responseForRow(row, {hop: 2, reason: 'destination_reached'}), undefined); }); + +test('unreachable marker stays beside the host before block metadata', () => { + const app = loadAppRawIngestor(); + const result = app.render([{ + ttl: 2, + sent: 1, + received: 1, + loss_count: 0, + ip: '192.0.2.2', + host: 'router.example', + geo: {country: 'CN'}, + mpls: ['L=100'], + response: {kind: 'unreachable', marker: '!H'}, + }]); + const table = result.children[0]; + const tbody = table.children[1]; + const row = tbody.children[0]; + const hostCell = row.children[6]; + + assert.deepEqual( + hostCell.children.map((child) => child.className).filter(Boolean), + ['mtr-hostname', 'mtr-response-marker', 'attempt__geo', 'mtr-mpls'], + ); +});