New module public/js/modules/shortcuts.js:
* registerShortcut({key, ctrl, shift, alt, match, guard, priority,
section, label, keys, handler}) — declarative shortcut registration
with priority ordering, custom match predicates, and runtime guards.
* Single document-level keydown dispatcher iterates the registry
(sorted by priority desc), matches key+modifiers or custom match(),
checks guard(), fires handler with preventDefault.
* guards object: board(), editor(), detail(), search(), email(),
canvas(), bodyFocused(), noOverlay(), isOpen(id) — reusable
predicates that replace the repeated blocker-array patterns.
* renderShortcutHelp() auto-generates the #shortcuts overlay content
from the registry, grouped by section. New shortcuts added via
registerShortcut appear in the help screen automatically.
* Shortcuts with guard: () => false are help-screen-only entries for
element-level shortcuts handled by their own modules (editor
textarea, search input, canvas overlay, etc.).
Migration (public/js/app.js):
* The ~200-line monolithic keydown handler is replaced by ~80
declarative registerShortcut() calls.
* Escape chain: 10 separate registrations with priorities 100→20,
each with its own guard (quick-capture, detail/zen, modal, search,
tasks, gallery, calendar, shortcuts, help). A hidden: true flag
suppresses them from the help screen; one visible entry with
guard: () => false shows "Esc — close any overlay".
* Global combos: Ctrl+K (search), Ctrl+N (quick capture), Ctrl+Z
(undo), F1 (help), ? (shortcuts).
* Editor: Ctrl+S (save), Ctrl+Shift+S (save+close), Ctrl+Enter
(save+close). Element-level shortcuts (Tab indent, Alt+arrows,
autocomplete triggers) registered as help-screen-only.
* Board bare keys: a/f/j/n/t/c//, Tab/Shift+Tab, 1-9, arrow nav,
Enter → preview, Delete/Backspace selected.
* Detail: ←/→ group navigation, Enter → editor.
* Help-screen-only: search ↑↓/Enter, board mouse actions, canvas
tool shortcuts (B/E/L/R/O/F/T/⌫), mail ⌫/⇧⌫, m (plugin).
Removed from board.js: the document-level Delete/Backspace listener
(now in the central registry with the same logic).
Help screen (public/index.php):
* The hardcoded 3-column shortcut HTML is replaced by an empty
.shortcut-help-content div that renderShortcutHelp() fills at boot.
* CSS: .shortcut-help-content section gets break-inside:avoid +
margin-bottom for clean column flow.
Test stabilization:
* card-interactions.test.js: due-pill, overdue-border, and
child-hidden-on-board tests now set state.activeBucket='all'
before _reloadAll and poll for the DOM element (40×50ms) instead
of a fixed sleep(200). Eliminates the flaky "card not found" when
activeBucket was leaked by a prior test.
* editor-features.test.js: "save creates card and closes editor"
polls for #modal to lose .open class (40×50ms) instead of a fixed
sleep(400). doSave(true) does 2-3 serial API calls before
closeModal which sometimes exceeded the old budget.
chore: bump version to 0.9.13
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
113 lines
3.7 KiB
JavaScript
113 lines
3.7 KiB
JavaScript
import { describe, it, afterEach, expect, $, click, type, sleep, closeAll, csrf } from './runner.js?v=3';
|
|
|
|
describe('Editor: Color Picker', () => {
|
|
afterEach(() => closeAll());
|
|
|
|
it('color presets render', async () => {
|
|
click('#add-btn');
|
|
await sleep(200);
|
|
const presets = document.querySelectorAll('#color-presets [data-color]');
|
|
expect(presets.length).toBeGreaterThan(5);
|
|
});
|
|
|
|
it('clicking preset changes card color', async () => {
|
|
click('#add-btn');
|
|
await sleep(200);
|
|
const preset = document.querySelector('#color-presets [data-color="#fb7185"]');
|
|
if (preset) {
|
|
click(preset);
|
|
await sleep(100);
|
|
expect($('#editor-color').style.background).toContain('251');
|
|
}
|
|
});
|
|
});
|
|
|
|
describe('Editor: Preview Toggle', () => {
|
|
afterEach(() => closeAll());
|
|
|
|
it('preview pane exists', async () => {
|
|
click('#add-btn');
|
|
await sleep(200);
|
|
expect($('#editor-preview')).toExist();
|
|
expect($('#preview-content')).toExist();
|
|
});
|
|
|
|
it('toggle-preview button exists', async () => {
|
|
click('#add-btn');
|
|
await sleep(200);
|
|
expect($('#toggle-preview')).toExist();
|
|
});
|
|
});
|
|
|
|
describe('Editor: Line Numbers', () => {
|
|
afterEach(() => closeAll());
|
|
|
|
it('gutter element exists', async () => {
|
|
click('#add-btn');
|
|
await sleep(200);
|
|
expect($('#editor-gutter')).toExist();
|
|
});
|
|
|
|
it('toggle-lines button exists', async () => {
|
|
click('#add-btn');
|
|
await sleep(200);
|
|
expect($('#toggle-lines')).toExist();
|
|
});
|
|
});
|
|
|
|
describe('Editor: Save Card', () => {
|
|
afterEach(() => closeAll());
|
|
|
|
it('save creates card and closes editor', async () => {
|
|
click('#add-btn');
|
|
await sleep(200);
|
|
type('#inp-title', '__test_save_flow__');
|
|
const body = $('#editor-body');
|
|
body.value = 'test body content';
|
|
body.dispatchEvent(new Event('input', { bubbles: true }));
|
|
await sleep(50);
|
|
|
|
click('#modal-save-close');
|
|
// doSave(true) does API PATCH + _reloadAll (2-3 network calls)
|
|
// before closeModal — poll until the modal is actually hidden
|
|
// instead of a fixed sleep that races against server speed.
|
|
for (let i = 0; i < 40; i++) {
|
|
if (!$('#modal')?.classList.contains('open')) break;
|
|
await sleep(50);
|
|
}
|
|
|
|
expect($('#modal')).toBeHidden();
|
|
// Card should exist
|
|
const cards = await fetch('api/cards').then(r => r.json());
|
|
const found = cards.find(c => c.title === '__test_save_flow__');
|
|
expect(found).toExist();
|
|
expect(found.body).toContain('test body content');
|
|
});
|
|
});
|
|
|
|
describe('Editor: Edit Existing Card', () => {
|
|
afterEach(() => closeAll());
|
|
|
|
it('editor loads existing card data', async () => {
|
|
const res = await fetch('api/cards', {
|
|
method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRF-Token': csrf() },
|
|
body: JSON.stringify({ title: '__test_edit_load__', body: 'existing body', color: '#8b5cf6' }),
|
|
}).then(r => r.json());
|
|
await window._reloadAll?.();
|
|
await sleep(200);
|
|
|
|
// Open via context menu
|
|
const cardEl = document.querySelector(`[data-id="${res.id}"]`);
|
|
if (!cardEl) return;
|
|
cardEl.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, clientX: 100, clientY: 100 }));
|
|
await sleep(150);
|
|
const editBtn = document.querySelector('#ctx-items [data-action="edit"]');
|
|
click(editBtn);
|
|
await sleep(300);
|
|
|
|
expect($('#modal')).toBeVisible();
|
|
expect($('#inp-title').value).toBe('__test_edit_load__');
|
|
expect($('#editor-body').value).toContain('existing body');
|
|
});
|
|
});
|