Files
meshcore-analyzer/test-table-fluid-e2e.js
T
Kpa-clawbot 52bb07d6c1 feat(#1056): fluid tables + +N hidden pill (packets/nodes/observers) (#1099)
## Summary

Implements priority-based responsive column hiding for the three primary
data tables (Packets, Nodes, Observers) per the parent task #1050
acceptance criteria, with a clickable **+N hidden** pill in the table
header to reveal collapsed columns.

## Approach

- New `TableResponsive` helper (defined once at the top of `packets.js`,
exposed on `window`) classifies `<th data-priority="N">` cells:
  - `1` = always visible
  - `2` = hide when viewport ≤ 1280
  - `3` = hide ≤ 1080
  - `4` = hide ≤ 900
  - `5` = hide ≤ 768
- Higher priority numbers drop first. The matching `<td>` cells in
`tbody` are tagged via `.col-hidden` (colspan-aware mapping).
- A `.col-hidden-pill` `<button>` is appended to the last visible
`<th>`. Clicking it sets a per-table reveal flag and clears all hidden
classes. Re-runs on `window.resize` (debounced) and a `ResizeObserver`
on the wrapping element.
- Each of `packets.js` / `nodes.js` / `observers.js` wraps its primary
table in `.table-fluid-wrap` and calls `TableResponsive.register` after
initial render.
- `style.css` removes legacy `min-width: 720px / 480px` floors on the
primary tables (which forced horizontal scroll) and lets columns flex
via `table-layout: auto` with `.col-time` switched to `clamp(72px, 8vw,
108px)`.

Per-column priorities chosen so identifier columns stay visible
(Time/Hash/Type/Name/Status) while numeric/secondary columns collapse
first.

## Files changed (matches Hard rules — only these)

- `public/packets.js` (`#pktTable` + `TableResponsive` helper)
- `public/nodes.js` (`#nodesTable`)
- `public/observers.js` (`#obsTable`)
- `public/style.css` (table sections only)
- `test-table-fluid-e2e.js` (new E2E)

## E2E

`BASE_URL=http://localhost:13581 node test-table-fluid-e2e.js` — covers
all three tables at 768/1080/1440 viewports, asserting:

- No horizontal table overflow within `.table-fluid-wrap`
- Visible `+N hidden` pill at narrow widths with the count `N` matching
the number of `th.col-hidden` cells
- Clicking the pill clears all `.col-hidden` classifiers (reveals every
column)

## Manual verification in openclaw browser (local fixture server)

| Page      | Viewport | Hidden | Pill         |
|-----------|---------:|-------:|--------------|
| observers |      768 |      8 | `+8 hidden`  |
| packets   |      768 |      7 | `+7 hidden`  |
| packets   |     1080 |      4 | `+4 hidden`  |
| nodes     |      768 |      3 | `+3 hidden`  |
| nodes     |     1440 |      0 | (no pill)    |

Pill click verified to reveal all columns.

## TDD

- Red commit: `5ad7573` — failing E2E (no `.col-hidden-pill` exists yet)
- Green commit: `7780090` — implementation; test passes manually against
fixture server.

Fixes #1056

---------

Co-authored-by: openclaw-bot <bot@openclaw.dev>
Co-authored-by: meshcore-bot <bot@meshcore.local>
Co-authored-by: openclaw-bot <bot@openclaw.local>
Co-authored-by: corescope-bot <bot@corescope.local>
2026-05-05 08:45:43 -07:00

132 lines
5.4 KiB
JavaScript

/**
* E2E (#1056): Fluid table columns + "+N hidden" pill.
*
* Boots Chromium against a local corescope-server and verifies that the
* primary tables (Packets, Nodes, Observers) collapse priority-tagged
* columns at narrow viewports, render a "+N hidden" pill in the header
* showing the count, and that clicking the pill reveals the hidden columns.
*
* Tested viewports: 768, 1080, 1440 (parent task: 768/1080/1440/1920).
*
* Usage: BASE_URL=http://localhost:13581 node test-table-fluid-e2e.js
*/
'use strict';
const { chromium } = require('playwright');
const BASE = process.env.BASE_URL || 'http://localhost:13581';
let passed = 0, failed = 0;
async function step(name, fn) {
try { await fn(); passed++; console.log(' ✓ ' + name); }
catch (e) { failed++; console.error(' ✗ ' + name + ': ' + e.message); }
}
function assert(c, m) { if (!c) throw new Error(m || 'assertion failed'); }
const PAGES = [
{ hash: '#/packets', tableSel: '#pktTable', name: 'packets' },
{ hash: '#/nodes', tableSel: '#nodesTable', name: 'nodes' },
{ hash: '#/observers', tableSel: '#obsTable', name: 'observers' },
];
const VIEWPORTS = [
{ w: 768, h: 900, expectHidden: true },
{ w: 1080, h: 900, expectHidden: true },
{ w: 1440, h: 900, expectHidden: false }, // wide enough — no hide expected (or 0)
{ w: 1920, h: 900, expectHidden: false }, // AC #5: also exercise 1920px
];
(async () => {
const browser = await chromium.launch({
headless: true,
executablePath: process.env.CHROMIUM_PATH || undefined,
args: ['--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage'],
});
console.log(`\n=== #1056 fluid tables E2E against ${BASE} ===`);
for (const vp of VIEWPORTS) {
const ctx = await browser.newContext({ viewport: { width: vp.w, height: vp.h } });
const page = await ctx.newPage();
page.setDefaultTimeout(8000);
page.on('pageerror', (e) => console.error('[pageerror]', e.message));
for (const p of PAGES) {
const tag = `${p.name}@${vp.w}`;
await step(`${tag}: page renders`, async () => {
await page.goto(BASE + '/' + p.hash, { waitUntil: 'domcontentloaded' });
await page.waitForSelector(p.tableSel, { timeout: 8000 });
// give responsive logic a tick
await page.waitForTimeout(300);
});
await step(`${tag}: no horizontal table scroll`, async () => {
const overflow = await page.evaluate((sel) => {
const t = document.querySelector(sel);
if (!t) return { ok: false, reason: 'no table' };
// Either the table itself or a wrapper must not horizontally overflow
// its container at this viewport.
const wrap = t.closest('.table-fluid-wrap, .obs-table-scroll, .table-scroll-wrap') || t.parentElement;
return {
tableW: t.scrollWidth,
wrapW: wrap.clientWidth,
// Allow a few px tolerance for sub-pixel rounding / scrollbar gutter.
ok: t.scrollWidth <= wrap.clientWidth + 8,
};
}, p.tableSel);
assert(overflow.ok, `table overflows: tableW=${overflow.tableW} wrapW=${overflow.wrapW}`);
});
await step(`${tag}: +N hidden pill state matches hidden columns`, async () => {
const info = await page.evaluate((sel) => {
const t = document.querySelector(sel);
if (!t) return { ok: false, reason: 'no table' };
const heads = Array.from(t.querySelectorAll('thead th'));
const hiddenHeads = heads.filter(h => h.classList.contains('col-hidden'));
const pill = t.querySelector('.col-hidden-pill');
return {
hiddenCount: hiddenHeads.length,
hasPill: !!pill,
pillText: pill ? pill.textContent.trim() : '',
pillVisible: pill ? pill.offsetParent !== null : false,
};
}, p.tableSel);
if (vp.expectHidden) {
assert(info.hiddenCount >= 1, `expected ≥1 hidden col at ${vp.w}px, got ${info.hiddenCount}`);
assert(info.hasPill && info.pillVisible, `expected visible +N pill at ${vp.w}px`);
assert(/\+\d+/.test(info.pillText), `pill text "${info.pillText}" missing +N marker`);
const m = info.pillText.match(/\+(\d+)/);
const n = m ? parseInt(m[1], 10) : -1;
assert(n === info.hiddenCount, `pill says +${n} but ${info.hiddenCount} columns are hidden`);
} else {
// wide: no hidden cols, pill should be absent or hidden
if (info.hasPill) assert(!info.pillVisible || /\+0/.test(info.pillText), `expected no/zero pill at ${vp.w}px, got "${info.pillText}"`);
}
});
if (vp.expectHidden) {
await step(`${tag}: clicking pill reveals hidden columns`, async () => {
// Click pill
const pillSel = `${p.tableSel} .col-hidden-pill`;
await page.click(pillSel);
await page.waitForTimeout(150);
const after = await page.evaluate((sel) => {
const t = document.querySelector(sel);
const heads = Array.from(t.querySelectorAll('thead th'));
return heads.filter(h => h.classList.contains('col-hidden')).length;
}, p.tableSel);
assert(after === 0, `expected 0 hidden cols after pill click, got ${after}`);
});
}
}
await ctx.close();
}
await browser.close();
console.log(`\n=== #1056 fluid tables E2E: ${passed} passed, ${failed} failed ===`);
process.exit(failed ? 1 : 0);
})();