mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-09-13 01:05:34 +00:00
## #1297 B3 — Playwright E2E coverage for `public/channels.js` Pure-coverage PR. Adds five Playwright suites targeting the largest under-tested branches of `public/channels.js` (1950 LOC, was **19.9% statements** per the live coverage refinement in #1297 — the single biggest delta opportunity in the umbrella). No production code changes. ### Coverage exemption Per repo `AGENTS.md` TDD rule: this is the **net-new test coverage** case — there is no production change to gate, so a failing-then-passing red commit isn't applicable. All five suites exercise existing channels init() code paths that ship today. ### New test files | File | Scenarios exercised | | --- | --- | | `test-channels-list-render-e2e.js` | Sectioned sidebar (My Channels / Network / Encrypted) headers, encrypted collapse toggle + localStorage persistence, row badges + previews, color dot + color clear control, sidebar resize handle width persist | | `test-channels-selection-flow-e2e.js` | `selectChannel()` header update + URL replaceState, message row rendering (avatars, sender colors, packet links), node detail panel open via mouse + keyboard + close-with-focus-restore, deep-link route restoration, scroll button initial state | | `test-channels-add-modal-e2e.js` | Generate PSK Channel (key + QR + status banner + localStorage persist), Add PSK invalid hex error path, Add PSK valid hex success + close + My Channels row, Monitor Hashtag with and without leading `#`, empty-hashtag no-op, Scan QR unavailable fallback, Escape close, Remove ✕ flow | | `test-channels-share-color-e2e.js` | Share modal normal mode (dedicated `#chShareModal` with QR + Hex Key + Copy success label), Share modal error mode (`openShareModalError` when no stored key — field groups hidden), Escape close, `ChannelColorPicker.show` invocation on color-dot click, keyboard Enter on a `[data-share-channel]` span | | `test-channels-ws-batch-e2e.js` | `processWSBatch` via `_channelsProcessWSBatchForTest`: explicit-sender append, `"Sender: text"` parsing branch, packetHash dedup + observer accumulation, new-channel append (channel previously unseen), scroll-button branch when user not at bottom, region-filter exclusion code path | All five tests wired into `.github/workflows/deploy.yml` after the existing `test-channel-fluid-e2e.js` step. ### Preflight `bash ~/.openclaw/skills/pr-preflight/scripts/run-all.sh origin/master` → exit 0, all gates pass (PII, CSS vars, branch scope, etc.). Refs #1297 --------- Co-authored-by: openclaw-bot <openclaw-bot@users.noreply.github.com> Co-authored-by: openclaw-bot <bot@openclaw.local> Co-authored-by: mc-bot <bot@meshcore.local>
170 lines
7.6 KiB
JavaScript
170 lines
7.6 KiB
JavaScript
/**
|
|
* #1297 B3 — channels.js Add Channel modal full coverage.
|
|
*
|
|
* Exercises every Section 1/2/3 path in init():
|
|
* - Section 1: Generate PSK Channel (key + QR + status banner)
|
|
* - Section 2: Add PSK Channel — invalid hex error, valid hex success,
|
|
* status banner, channel appears in My Channels, remove flow
|
|
* - Section 2: Scan QR — fallback path when ChannelQR.scan is absent
|
|
* - Section 3: Monitor Hashtag (with and without leading `#`)
|
|
* - Escape closes the modal
|
|
*
|
|
* Usage: BASE_URL=http://localhost:13581 node test-channels-add-modal-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'); }
|
|
|
|
(async () => {
|
|
const browser = await chromium.launch({
|
|
headless: true,
|
|
executablePath: process.env.CHROMIUM_PATH || undefined,
|
|
args: ['--no-sandbox', '--disable-gpu', '--disable-dev-shm-usage'],
|
|
});
|
|
const ctx = await browser.newContext({ viewport: { width: 1280, height: 800 } });
|
|
// Auto-confirm window.confirm for remove flow.
|
|
// NOTE: only one dialog handler — Playwright errors if a dialog is
|
|
// accepted twice. Attach to the page after it's created.
|
|
const page = await ctx.newPage();
|
|
page.on('dialog', (d) => d.accept());
|
|
page.setDefaultTimeout(8000);
|
|
page.on('pageerror', (e) => console.error('[pageerror]', e.message));
|
|
|
|
console.log(`\n=== #1297 B3 channels add-modal E2E against ${BASE} ===`);
|
|
|
|
await page.goto(BASE + '/', { waitUntil: 'domcontentloaded' });
|
|
await page.evaluate(() => { try { localStorage.clear(); } catch (e) {} });
|
|
await page.goto(BASE + '/#/channels', { waitUntil: 'domcontentloaded' });
|
|
await page.waitForSelector('#chAddChannelBtn', { timeout: 8000 });
|
|
|
|
async function openAddModal() {
|
|
await page.click('#chAddChannelBtn');
|
|
await page.waitForSelector('#chAddChannelModal:not(.hidden)', { timeout: 3000 });
|
|
}
|
|
|
|
await step('Section 1: Generate PSK Channel produces a key + status banner', async () => {
|
|
await openAddModal();
|
|
await page.fill('#chGenerateName', 'CovGenerated');
|
|
await page.click('#chGenerateBtn');
|
|
// Status banner appears.
|
|
await page.waitForFunction(() => {
|
|
const s = document.getElementById('chAddStatus');
|
|
return s && s.style.display !== 'none' && /Generated/i.test(s.textContent);
|
|
}, { timeout: 5000 });
|
|
// QR output populated (either QR element or fallback text).
|
|
const filled = await page.evaluate(() => {
|
|
const out = document.getElementById('qr-output');
|
|
return !!(out && (out.querySelector('img, canvas, table, svg') ||
|
|
/Key generated/i.test(out.textContent || '')));
|
|
});
|
|
assert(filled, 'qr-output should be populated after generate');
|
|
// Key persists in localStorage under 'corescope_channel_keys'.
|
|
const stored = await page.evaluate(() => {
|
|
try { return JSON.parse(localStorage.getItem('corescope_channel_keys') || '{}'); }
|
|
catch (e) { return {}; }
|
|
});
|
|
assert(Object.keys(stored).length > 0,
|
|
'at least one key should be persisted, got: ' + JSON.stringify(stored));
|
|
// Close modal for next test.
|
|
await page.keyboard.press('Escape');
|
|
await page.waitForFunction(() => document.getElementById('chAddChannelModal')?.classList.contains('hidden'), { timeout: 3000 });
|
|
});
|
|
|
|
await step('Section 2: invalid hex shows inline error, does NOT close modal', async () => {
|
|
await openAddModal();
|
|
await page.fill('#chPskKey', 'NOT-HEX-VALUE');
|
|
await page.click('#chPskAddBtn');
|
|
await page.waitForFunction(() => {
|
|
const e = document.getElementById('chPskError');
|
|
return e && e.style.display !== 'none' && /32 hex/i.test(e.textContent);
|
|
}, { timeout: 3000 });
|
|
// Modal still open.
|
|
const stillOpen = await page.$('#chAddChannelModal:not(.hidden)');
|
|
assert(stillOpen, 'modal should remain open on invalid hex');
|
|
});
|
|
|
|
await step('Section 2: valid hex adds channel, closes modal, status banner', async () => {
|
|
const KEY = 'aabbccddeeff00112233445566778899';
|
|
await page.fill('#chPskKey', KEY);
|
|
await page.fill('#chPskName', 'CovPsk');
|
|
await page.click('#chPskAddBtn');
|
|
await page.waitForFunction(() => document.getElementById('chAddChannelModal')?.classList.contains('hidden'), { timeout: 5000 });
|
|
// Wait for the My Channels section to appear with our row.
|
|
await page.waitForFunction(() => {
|
|
const sec = document.querySelector('.ch-section-mychannels');
|
|
return sec && /CovPsk|Private Channel/i.test(sec.textContent);
|
|
}, { timeout: 5000 });
|
|
});
|
|
|
|
await step('Section 3: monitor hashtag strips leading # and adds row', async () => {
|
|
await openAddModal();
|
|
await page.fill('#chHashtagName', '#covhashtag');
|
|
await page.click('#chHashtagBtn');
|
|
await page.waitForFunction(() => document.getElementById('chAddChannelModal')?.classList.contains('hidden'), { timeout: 5000 });
|
|
await page.waitForFunction(() => {
|
|
const sec = document.querySelector('.ch-section-mychannels');
|
|
return sec && /covhashtag/i.test(sec.textContent);
|
|
}, { timeout: 5000 });
|
|
});
|
|
|
|
await step('Section 3: empty hashtag input is a no-op', async () => {
|
|
await openAddModal();
|
|
const beforeRows = await page.$$eval(
|
|
'.ch-section-mychannels .ch-item', (els) => els.length);
|
|
await page.fill('#chHashtagName', ' ');
|
|
await page.click('#chHashtagBtn');
|
|
// Modal stays open; nothing changes.
|
|
await page.waitForTimeout(200);
|
|
const stillOpen = await page.$('#chAddChannelModal:not(.hidden)');
|
|
assert(stillOpen, 'empty hashtag should be a no-op (modal stays open)');
|
|
const afterRows = await page.$$eval(
|
|
'.ch-section-mychannels .ch-item', (els) => els.length);
|
|
assert(beforeRows === afterRows,
|
|
'rows should not change on empty hashtag, before=' + beforeRows + ' after=' + afterRows);
|
|
await page.keyboard.press('Escape');
|
|
});
|
|
|
|
await step('Scan QR: clicking when ChannelQR.scan unavailable shows error', async () => {
|
|
await openAddModal();
|
|
// Force the unavailable path by deleting scan().
|
|
await page.evaluate(() => {
|
|
if (window.ChannelQR) { try { delete window.ChannelQR.scan; } catch (e) {} }
|
|
});
|
|
await page.click('#scan-qr-btn');
|
|
await page.waitForFunction(() => {
|
|
const e = document.getElementById('chPskError');
|
|
return e && e.style.display !== 'none' && /unavailable/i.test(e.textContent);
|
|
}, { timeout: 3000 });
|
|
await page.keyboard.press('Escape');
|
|
});
|
|
|
|
await step('Escape key closes add modal', async () => {
|
|
await openAddModal();
|
|
await page.keyboard.press('Escape');
|
|
await page.waitForFunction(() => document.getElementById('chAddChannelModal')?.classList.contains('hidden'), { timeout: 3000 });
|
|
});
|
|
|
|
await step('Remove channel: clicking ✕ removes row + clears localStorage key', async () => {
|
|
const removeBtn = await page.$(
|
|
'.ch-section-mychannels [data-remove-channel]');
|
|
if (!removeBtn) { console.log(' (skip — no user-added rows)'); return; }
|
|
const hash = await removeBtn.getAttribute('data-remove-channel');
|
|
await removeBtn.click(); // dialog auto-accepted
|
|
await page.waitForFunction((h) => {
|
|
return !document.querySelector('[data-remove-channel="' + CSS.escape(h) + '"]');
|
|
}, { timeout: 5000 }, hash);
|
|
});
|
|
|
|
await browser.close();
|
|
console.log(`\n=== B3 add-modal: ${passed} passed, ${failed} failed ===\n`);
|
|
process.exit(failed === 0 ? 0 : 1);
|
|
})().catch((e) => { console.error(e); process.exit(1); });
|