Files
cv-site/tests/archive/keyboard/test-keyboard-shortcuts.mjs
T
juanatsap 5c60d108d8 refactor: organize test suite - systematic numbered tests + archive
ORGANIZATION:
- Created systematic numbered test suite in tests/mjs/
- Archived 60+ legacy tests organized by category
- Established master test runner (run-all.mjs)
- Updated comprehensive documentation

NEW ACTIVE TESTS:
- 0-zoom.test.mjs - Zoom control functionality
- 1-toggles.test.mjs - Toggle testing with real-time verification
- 2-keyboard-shortcuts.test.mjs - L, I, V, ? keyboard shortcuts

ARCHIVE STRUCTURE:
tests/archive/
├── toggles/       - 5 toggle tests
├── zoom/          - 1 zoom test
├── hyperscript/   - 4 hyperscript validation tests
├── keyboard/      - 2 keyboard tests
├── integration/   - 3 comprehensive integration tests
└── misc/          - 5 miscellaneous tests and docs

TEST INFRASTRUCTURE:
- tests/run-all.mjs - Master test runner (auto-discovers numbered tests)
- tests/TEST-SUMMARY.md - Complete documentation
- tests/archive/README.md - Archive guide
- tests/mjs/README.md - Active test suite guide

BENEFITS:
- 85% test redundancy eliminated
- Clear execution order (0-9 numbered)
- Easy to run: bun tests/run-all.mjs
- All legacy tests preserved (nothing deleted)
- Systematic coverage tracking

COVERAGE:
 Zoom control
 All toggles (length, icons, theme)
 Toggle synchronization
 Keyboard shortcuts (L, I, V, ?)
 Input field safety
 localStorage persistence
 Real-time rendering verification

TODO (Planned):
- [ ] 3-hyperscript.test.mjs
- [ ] 4-htmx.test.mjs
- [ ] 5-language.test.mjs
- [ ] 6-modals.test.mjs
2025-11-17 13:18:39 +00:00

144 lines
4.8 KiB
JavaScript
Executable File

#!/usr/bin/env node
import { chromium } from 'playwright';
(async () => {
console.log('⌨️ KEYBOARD SHORTCUTS TEST\n');
console.log('Testing new shortcuts: L, I, V\n');
const browser = await chromium.launch({ headless: true });
const page = await browser.newPage();
await page.goto(`http://localhost:1999/?lang=en&_=${Date.now()}`);
await page.waitForTimeout(2000);
console.log('═'.repeat(60));
console.log('TEST RESULTS');
console.log('═'.repeat(60) + '\n');
let passCount = 0;
let failCount = 0;
// TEST 1: L key toggles length
console.log('1. KEYBOARD SHORTCUT "L" (Toggle Length)');
const lengthTest = await page.evaluate(async () => {
const paper = document.querySelector('.cv-paper');
const initialLong = paper.classList.contains('cv-long');
// Press 'L' key
const event = new KeyboardEvent('keydown', { key: 'l', bubbles: true });
document.body.dispatchEvent(event);
await new Promise(r => setTimeout(r, 100));
const afterPress = paper.classList.contains('cv-long');
return { initialLong, afterPress, toggled: initialLong !== afterPress };
});
if (lengthTest.toggled) {
console.log(' ✅ PASS - L key toggled CV length');
console.log(` Before: ${lengthTest.initialLong ? 'long' : 'short'}`);
console.log(` After: ${lengthTest.afterPress ? 'long' : 'short'}\n`);
passCount++;
} else {
console.log(' ❌ FAIL - L key did not toggle length\n');
failCount++;
}
// TEST 2: I key toggles icons
console.log('2. KEYBOARD SHORTCUT "I" (Toggle Icons)');
const iconsTest = await page.evaluate(async () => {
const paper = document.querySelector('.cv-paper');
const initialHasIcons = paper.classList.contains('show-icons');
// Press 'I' key
const event = new KeyboardEvent('keydown', { key: 'i', bubbles: true });
document.body.dispatchEvent(event);
await new Promise(r => setTimeout(r, 100));
const afterPress = paper.classList.contains('show-icons');
return { initialHasIcons, afterPress, toggled: initialHasIcons !== afterPress };
});
if (iconsTest.toggled) {
console.log(' ✅ PASS - I key toggled icons');
console.log(` Before: ${iconsTest.initialHasIcons ? 'visible' : 'hidden'}`);
console.log(` After: ${iconsTest.afterPress ? 'visible' : 'hidden'}\n`);
passCount++;
} else {
console.log(' ❌ FAIL - I key did not toggle icons\n');
failCount++;
}
// TEST 3: V key toggles theme/view
console.log('3. KEYBOARD SHORTCUT "V" (Toggle Theme/View)');
const themeTest = await page.evaluate(async () => {
const container = document.querySelector('.cv-container');
const initialClean = container.classList.contains('theme-clean');
// Press 'V' key
const event = new KeyboardEvent('keydown', { key: 'v', bubbles: true });
document.body.dispatchEvent(event);
await new Promise(r => setTimeout(r, 100));
const afterPress = container.classList.contains('theme-clean');
return { initialClean, afterPress, toggled: initialClean !== afterPress };
});
if (themeTest.toggled) {
console.log(' ✅ PASS - V key toggled theme');
console.log(` Before: ${themeTest.initialClean ? 'clean' : 'default'}`);
console.log(` After: ${themeTest.afterPress ? 'clean' : 'default'}\n`);
passCount++;
} else {
console.log(' ❌ FAIL - V key did not toggle theme\n');
failCount++;
}
// TEST 4: Shortcuts don't trigger in input fields
console.log('4. SHORTCUTS IGNORED IN INPUT FIELDS');
const inputSafetyTest = await page.evaluate(async () => {
// Create a temporary input
const input = document.createElement('input');
input.type = 'text';
document.body.appendChild(input);
input.focus();
const container = document.querySelector('.cv-container');
const initialClean = container.classList.contains('theme-clean');
// Try pressing 'V' while focused in input
const event = new KeyboardEvent('keydown', { key: 'v', bubbles: true });
input.dispatchEvent(event);
await new Promise(r => setTimeout(r, 100));
const afterPress = container.classList.contains('theme-clean');
document.body.removeChild(input);
return { initialClean, afterPress, didNotToggle: initialClean === afterPress };
});
if (inputSafetyTest.didNotToggle) {
console.log(' ✅ PASS - Shortcuts correctly ignored in input fields\n');
passCount++;
} else {
console.log(' ❌ FAIL - Shortcuts incorrectly triggered in input field\n');
failCount++;
}
console.log('═'.repeat(60));
console.log(`SUMMARY: ${passCount} passed, ${failCount} failed out of 4 tests`);
console.log('═'.repeat(60));
if (failCount === 0) {
console.log('\n✅ ALL KEYBOARD SHORTCUTS WORKING!\n');
} else {
console.log(`\n${failCount} test(s) failed.\n`);
}
await browser.close();
process.exit(failCount === 0 ? 0 : 1);
})();