mirror of
https://github.com/Kpa-clawbot/meshcore-analyzer.git
synced 2026-05-11 22:54:44 +00:00
282074b19d
## Summary **PR 3/3 of #1034** — wires the existing `window.ChannelQR` module (PR2 #1035) into the existing channel modal placeholders (PR1 #1037). ### Changes **`public/channels.js`** - **Generate handler** (`#chGenerateBtn`): replaced the "QR coming in next update" placeholder text with a real call to `window.ChannelQR.generate(label || channelName, keyHex, qrOut)`. Renders QR canvas + `meshcore://channel/add?...` URL + Copy Key inline into `#qr-output`. - **Scan handler** (`#scan-qr-btn`): removed `disabled` attribute, refreshed title, and added a click handler that calls `window.ChannelQR.scan()`. On success it populates `#chPskKey` (from `result.secret`) and `#chPskName` (from `result.name`); on cancel it's a no-op; on error it surfaces the message via `#chPskError`. The Share button on sidebar entries was already wired to `ChannelQR.generate` in PR1 (no change needed). ### TDD 1. **Red commit** (`178020b`): `test-channel-qr-wiring.js` — 12 assertions, 7 failed against the placeholder code (Generate handler still printed "coming in next update", scan button still disabled). 2. **Green commit** (`e708f3f`): wiring added → all 12 assertions pass. ### E2E (rule 18) `test-e2e-playwright.js` gains 3 Playwright tests (run against the live Go server with fixture DB in CI): - Generate → asserts `#qr-output canvas` and the `meshcore://channel/add` URL appear after the click. - Scan button is enabled (no `disabled` attribute). - Stubs `ChannelQR.scan` to return `{name, secret}`, clicks the button, asserts `#chPskKey` + `#chPskName` are populated. ### CI registration Added `node test-channel-qr-wiring.js` and `node test-channel-modal-ux.js` to the JS unit-test step in `.github/workflows/deploy.yml` (and `test-all.sh`). ### Closes Closes #1034 (final PR in the redesign series). --------- Co-authored-by: OpenClaw Bot <bot@openclaw.local>
162 lines
6.9 KiB
JavaScript
162 lines
6.9 KiB
JavaScript
/**
|
|
* E2E (#1034 PR1): Channel Add modal + sectioned sidebar.
|
|
*
|
|
* Boots a headless Chromium against a locally running corescope-server and
|
|
* exercises:
|
|
* - sidebar [+ Add Channel] opens modal
|
|
* - modal renders three labeled sections + privacy footer + QR placeholders
|
|
* - close (✕) hides modal
|
|
* - sectioned sidebar renders My Channels / Network / Encrypted sections
|
|
* - PSK add flow: invalid hex → error; valid hex → modal closes
|
|
*
|
|
* Usage: BASE_URL=http://localhost:38201 node test-channel-modal-e2e.js
|
|
*/
|
|
'use strict';
|
|
const { chromium } = require('playwright');
|
|
|
|
const BASE = process.env.BASE_URL || 'http://localhost:38201';
|
|
|
|
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();
|
|
const page = await ctx.newPage();
|
|
page.setDefaultTimeout(8000);
|
|
page.on('pageerror', (e) => console.error('[pageerror]', e.message));
|
|
|
|
console.log(`\n=== #1034 PR1 E2E against ${BASE} ===`);
|
|
|
|
await step('navigate to /channels', async () => {
|
|
await page.goto(BASE + '/#/channels', { waitUntil: 'domcontentloaded' });
|
|
await page.waitForSelector('#chAddChannelBtn', { timeout: 8000 });
|
|
});
|
|
|
|
await step('Add Channel button is visible', async () => {
|
|
const text = await page.textContent('#chAddChannelBtn');
|
|
assert(/Add Channel/.test(text), 'button text: ' + text);
|
|
});
|
|
|
|
await step('modal hidden on load', async () => {
|
|
const isHidden = await page.evaluate(() => {
|
|
const m = document.getElementById('chAddChannelModal');
|
|
return !!m && (m.classList.contains('hidden') || m.hasAttribute('hidden'));
|
|
});
|
|
assert(isHidden, 'modal should start hidden');
|
|
});
|
|
|
|
await step('clicking [+ Add Channel] opens modal', async () => {
|
|
await page.click('#chAddChannelBtn');
|
|
await page.waitForSelector('#chAddChannelModal:not(.hidden)', { timeout: 3000 });
|
|
const visible = await page.isVisible('#chAddChannelModal');
|
|
assert(visible, 'modal should be visible after click');
|
|
});
|
|
|
|
await step('modal renders all three section titles', async () => {
|
|
const html = await page.innerHTML('#chAddChannelModal');
|
|
assert(html.includes('Generate PSK Channel'), 'section 1 missing');
|
|
assert(html.includes('Add Private Channel (PSK)'), 'section 2 missing');
|
|
assert(html.includes('Monitor Hashtag Channel'), 'section 3 missing');
|
|
});
|
|
|
|
await step('modal renders QR placeholders', async () => {
|
|
assert(await page.isVisible('#qr-output'), '#qr-output missing');
|
|
const scanBtn = await page.$('#scan-qr-btn');
|
|
assert(scanBtn, '#scan-qr-btn missing');
|
|
const disabled = await scanBtn.getAttribute('disabled');
|
|
assert(disabled === null, '#scan-qr-btn must be enabled (wired in #1034 PR3)');
|
|
});
|
|
|
|
await step('modal renders privacy footer', async () => {
|
|
const footer = await page.textContent('#chAddChannelModal .ch-modal-footer');
|
|
assert(/Keys stay in your browser/.test(footer), 'footer text missing: ' + footer);
|
|
assert(/passive observer/.test(footer), 'passive observer text missing');
|
|
});
|
|
|
|
await step('modal renders case-sensitivity warning', async () => {
|
|
const warn = await page.textContent('#chAddChannelModal .ch-modal-warn');
|
|
assert(/[Cc]ase-sensitive/.test(warn), 'warning missing: ' + warn);
|
|
});
|
|
|
|
await step('PSK add: invalid hex shows inline error', async () => {
|
|
await page.fill('#chPskKey', 'not-hex');
|
|
await page.click('#chPskAddBtn');
|
|
await page.waitForFunction(() => {
|
|
const e = document.getElementById('chPskError');
|
|
return e && e.style.display !== 'none' && /hex/i.test(e.textContent);
|
|
}, { timeout: 3000 });
|
|
});
|
|
|
|
await step('close button (✕) hides modal', async () => {
|
|
await page.click('#chModalClose');
|
|
await page.waitForFunction(() => {
|
|
const m = document.getElementById('chAddChannelModal');
|
|
return m && m.classList.contains('hidden');
|
|
}, { timeout: 3000 });
|
|
});
|
|
|
|
await step('sidebar renders three sections (My Channels / Network / Encrypted)', async () => {
|
|
// Wait for channel list to populate from API (or render empty-state).
|
|
await page.waitForFunction(() => {
|
|
const el = document.getElementById('chList');
|
|
if (!el) return false;
|
|
return el.querySelector('.ch-section-mychannels') &&
|
|
el.querySelector('.ch-section-network') &&
|
|
el.querySelector('.ch-section-encrypted');
|
|
}, { timeout: 8000 });
|
|
const headers = await page.$$eval('.ch-section-header', els => els.map(e => e.textContent.trim()));
|
|
const joined = headers.join(' | ');
|
|
assert(/My Channels/.test(joined), 'My Channels header missing: ' + joined);
|
|
assert(/Network/.test(joined), 'Network header missing');
|
|
assert(/Encrypted/.test(joined), 'Encrypted header missing');
|
|
});
|
|
|
|
await step('Encrypted section is collapsed by default', async () => {
|
|
const collapsed = await page.getAttribute('.ch-section-encrypted', 'data-encrypted-collapsed');
|
|
assert(collapsed === 'true', 'expected data-encrypted-collapsed=true, got ' + collapsed);
|
|
const bodyHidden = await page.evaluate(() => {
|
|
const b = document.getElementById('chEncryptedBody');
|
|
return b ? b.hasAttribute('hidden') : null;
|
|
});
|
|
assert(bodyHidden === true, 'encrypted body should be hidden initially');
|
|
});
|
|
|
|
await step('clicking Encrypted toggle expands it', async () => {
|
|
await page.click('#chEncryptedToggle');
|
|
const bodyHidden = await page.evaluate(() => {
|
|
const b = document.getElementById('chEncryptedBody');
|
|
return b ? b.hasAttribute('hidden') : null;
|
|
});
|
|
assert(bodyHidden === false, 'encrypted body should be visible after toggle');
|
|
});
|
|
|
|
await step('PSK add: valid hex closes modal and persists key', async () => {
|
|
await page.click('#chAddChannelBtn');
|
|
await page.waitForSelector('#chAddChannelModal:not(.hidden)');
|
|
const validHex = 'cafebabe' + '00112233' + '44556677' + '8899aabb';
|
|
await page.fill('#chPskKey', validHex);
|
|
await page.fill('#chPskName', 'E2E Test Channel');
|
|
await page.click('#chPskAddBtn');
|
|
await page.waitForFunction(() => {
|
|
const m = document.getElementById('chAddChannelModal');
|
|
return m && m.classList.contains('hidden');
|
|
}, { timeout: 5000 });
|
|
const stored = await page.evaluate(() => localStorage.getItem('corescope_channel_keys') || '');
|
|
assert(/cafebabe/i.test(stored), 'expected stored key in localStorage corescope_channel_keys, got: ' + stored);
|
|
});
|
|
|
|
await browser.close();
|
|
|
|
console.log(`\n=== Results: passed ${passed} failed ${failed} ===`);
|
|
process.exit(failed > 0 ? 1 : 0);
|
|
})().catch(e => { console.error(e); process.exit(1); });
|