Files
meshcore-analyzer/test-channel-sidebar-layout.js
T
Kpa-clawbot c00b585ee5 fix(channels): UX follow-ups to #1037 (touch target, '0 messages', share, locality, #meshcore) (#1040)
## Summary

Seven UX follow-ups to the channel modal/sidebar redesign in #1037.

## Fixes

1. **✕ touch target** — was 13px font + 0×4 padding, far below WCAG
2.5.5 / Apple HIG 44×44px. Bumped `.ch-remove-btn` to a 44×44 hit area
without disturbing desktop layout.
2. **"0 messages" preview** — user-added (PSK) channel rows showed `0
messages` even when dozens were decrypted. `messageCount` only tracks
server-known activity, not PSK decrypts. Drop the misleading fallback:
when no last message is known and the count is zero/absent, render
nothing.
3. **Privacy footer wording** — old copy "Clear browser data to remove
stored keys" was misleading after #1037 added per-channel ✕. Reworded to
point users at the ✕ button.
4. **Reshare affordance** — each user-added row now exposes a `⤴` Share
button that re-opens the QR + key for that channel via
`ChannelQR.generate` (with a plain-hex + `meshcore://channel/add?...`
URL fallback when the QR vendor lib isn't loaded). Reuses the Add
Channel modal; cleared on close.
5. **Drop "(your key)" suffix** from the row preview. The 🔑 badge
already conveys ownership; the suffix was noise. The key hex itself is
now only revealed on explicit Share, not in the sidebar.
6. **Make browser-local nature obvious** — the prior framing made
local-only sound like a feature when it's actually a constraint users
need to plan around. Adds:
- Prominent `.ch-modal-callout` in the Add Channel modal: *"Channels are
saved to **THIS browser only**. They won't appear on other devices or
browsers, and clearing browser data will remove them."*
   - `🖥️ (this browser)` marker in the **My Channels** section header
- Remove-confirm prompt now explicitly says *"permanently remove the key
from this browser"*
7. **#meshcore, not #LongFast** — `#LongFast` is Meshtastic's default
channel name. The meshcore network's analogous default is `#meshcore`.
Updated placeholder + case-sensitivity example in the modal.

## TDD

- Red commit `878d872` — failing assertions for fixes 1–6.
- Green commit `444cf81` — implementation.
- Red commit `6cab596` — failing assertions for fix 7.
- Green commit `9adc1a3` — `#meshcore` swap.

`test-channel-ux-followup.js` (18 assertions) passes. Existing
`test-channel-modal-ux.js` (33) and `test-channel-sidebar-layout.js` (8)
remain green.

## Files
- `public/channels.js` — row template, share handler, modal
callout/footer, sidebar header, confirm copy, placeholder swap
- `public/style.css` — `.ch-remove-btn` / `.ch-share-btn` 44×44,
`.ch-modal-callout`, `.ch-section-locality`
- `test-channel-ux-followup.js` — new test file

---------

Co-authored-by: clawbot <clawbot@local>
2026-05-04 19:57:53 -07:00

81 lines
3.9 KiB
JavaScript

/**
* Regression: channel sidebar layout for user-added (PSK) channels was
* broken by #1024 (✕ remove + 🔑 badge) interacting with the outer
* `.ch-item` <button> wrapper.
*
* Root cause: HTML5 disallows nesting <button> inside <button>. The parser
* implicitly closes the outer `.ch-item` button as soon as it hits the
* inner `<button class="ch-remove-btn">`. This re-parents the remove
* button + everything after it (the `.ch-item-preview` "X: msg" line)
* outside the channel entry, producing the visible bug:
*
* [icon] Levski 🔑 <-- outer button closes early here
* ✕ <-- orphaned, "floats"
* KpaPocket: Тест <-- preview text orphaned
* [icon] #bookclub ...
*
* This test asserts the rendered template does NOT contain a nested
* `<button>` inside the `.ch-item` button. Plus the "No key" toggle gets
* clearer copy and stays grouped with the channel controls.
*/
'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 chSrc = fs.readFileSync(path.join(__dirname, 'public/channels.js'), 'utf8');
const cssSrc = fs.readFileSync(path.join(__dirname, 'public/style.css'), 'utf8');
console.log('\n=== Sidebar layout: no nested <button> inside .ch-item ===');
// The bug: a literal `<button class="ch-remove-btn"` inside the
// `.ch-item` template. After fix, the remove affordance must be a
// non-<button> element (e.g. <span role="button">) so HTML parsing
// keeps it inside the channel entry.
assert(!/<button[^>]*class="ch-remove-btn"/.test(chSrc),
'remove (✕) affordance must NOT be a <button> element (would close outer .ch-item button)');
// Remove control must still be discoverable (data attribute keeps the
// existing click handler in `addEventListener('click', ...)`).
// PR #1040 refactored to an iconBtn() helper, so the literal
// `data-remove-channel="..."` no longer appears verbatim in source —
// check that the helper is wired with the right data attribute instead.
assert(/data-remove-channel/.test(chSrc),
'remove affordance still carries data-remove-channel for click delegation');
console.log('\n=== Sidebar layout: ✕ visible on user-added rows (not opacity:0) ===');
// Bug compounded: even if the button rendered correctly, opacity:0
// hide-until-hover made it impossible to discover on touch devices.
// The user-added (PSK) row should expose ✕ at full visibility.
// PR #1040: shared base class .ch-icon-btn carries the opacity rule.
const baseRule = cssSrc.match(/\.ch-icon-btn\s*\{[^}]*\}/);
const removeRule = cssSrc.match(/\.ch-remove-btn\s*\{[^}]*\}/);
assert(baseRule || removeRule, 'found .ch-icon-btn or .ch-remove-btn CSS rule');
if (baseRule) {
assert(!/opacity:\s*0\s*[;}]/.test(baseRule[0]),
'.ch-icon-btn (base for ✕) must not be opacity:0 by default (was invisible on touch)');
}
console.log('\n=== Encrypted section: header exists and is collapsible (#1037 redesign) ===');
// #1037 replaced the binary "No key" visibility toggle with a sectioned
// sidebar — encrypted (no-key) channels live in their own collapsible
// section grouped with the rest. The old toggle is intentionally gone.
assert(/ch-section-encrypted/.test(chSrc),
'sidebar renders a dedicated Encrypted section');
assert(/id="chEncryptedToggle"/.test(chSrc),
'Encrypted section header is a toggle (button#chEncryptedToggle)');
assert(/aria-expanded=/.test(chSrc) && /aria-controls="chEncryptedBody"/.test(chSrc),
'toggle exposes ARIA collapsible state (aria-expanded + aria-controls)');
assert(/Encrypted \(\$\{encrypted\.length\}\)/.test(chSrc),
'Encrypted header shows live count');
console.log('\n=== Results ===');
console.log('Passed: ' + passed + ', Failed: ' + failed);
process.exit(failed > 0 ? 1 : 0);