Files
markitect-main/history/javascript-dev-tests/test_keyboard_shortcuts.js
tegwick c4877543d5 refactor: clean up JavaScript development files and enhance automated testing
Complete cleanup and modernization of JavaScript testing infrastructure with
comprehensive automated test coverage and improved output formatting.

JavaScript Development Files Cleanup:
- Moved 53 manual development/debugging test files to history/javascript-dev-tests/
- Added comprehensive README documenting archived files and their purposes
- Cleaned main project directory of development artifacts

New Automated Test Suite (68 tests):
- keyboard-shortcuts.test.js: Tests Ctrl+Enter, Escape, accessibility features (8 tests)
- section-splitting.test.js: Tests heading detection, content parsing, ID generation (14 tests)
- image-editing.test.js: Tests dialog positioning, alt text, reset functionality (19 tests)
- button-events.test.js: Tests click handling, state management, event delegation (21 tests)

Integration Test Fixes:
- Fixed 13 failing integration tests by properly mocking component dependencies
- Updated tests to match actual component APIs instead of assumed interfaces
- Improved error handling and test reliability

Enhanced Test Output Formatting:
- Updated testdrive-jsui-test-all target to show clear test count summaries
- Separated JavaScript (68 tests) and Python (11 tests) results distinctly
- Added combined summary showing total coverage (79 tests)
- Improved error handling and visual formatting

Main Makefile Improvements:
- Fixed default target issue by adding .DEFAULT_GOAL := help
- Restored proper make help behavior when called without arguments

Key Achievements:
- Replaced 53 manual test files with 68 automated tests
- Achieved 100% test pass rate (79/79 tests passing)
- Enhanced CI/CD integration with clear test reporting
- Preserved all critical UI functionality in automated test coverage
- Improved developer experience with clearer test output

Testing Status:
-  68 JavaScript tests (Jest) - Core UI functionality
-  11 Python tests (pytest) - Integration bridge testing
-  100% automated test coverage for critical functionality
-  Clean, maintainable test codebase

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 23:16:47 +01:00

103 lines
3.5 KiB
JavaScript
Executable File

#!/usr/bin/env node
/**
* TDD Tests for Keyboard Shortcuts Recovery
*/
const { TestRunner, HTMLFileTester } = require('./test_runner.js');
const runner = new TestRunner();
// Test keyboard shortcuts functionality
runner.describe('Keyboard Shortcuts for Section Editing', () => {
runner.it('should have handleKeydown method in DOMRenderer', async () => {
// Clear cache and load editor
delete require.cache[require.resolve('/home/worsch/markitect_project/markitect/static/editor.js')];
require('/home/worsch/markitect_project/markitect/static/editor.js');
// Check if DOMRenderer has handleKeydown method
const DOMRenderer = global.DOMRenderer || require('/home/worsch/markitect_project/markitect/static/editor.js').DOMRenderer;
if (DOMRenderer) {
const renderer = new DOMRenderer({}, document.createElement('div'));
const hasHandleKeydown = typeof renderer.handleKeydown === 'function';
runner.expect(hasHandleKeydown).toBeTruthy();
}
});
runner.it('should bind keyboard handlers to textareas', async () => {
// This tests the integration - will check if textareas get keydown listeners
const { JSDOM } = require('jsdom');
const dom = new JSDOM(`
<div id="test-container"></div>
`);
global.document = dom.window.document;
global.window = dom.window;
// Load editor and create instances
require('/home/worsch/markitect_project/markitect/static/editor.js');
if (global.DOMRenderer && global.SectionManager) {
const manager = new global.SectionManager();
const renderer = new global.DOMRenderer(manager, dom.window.document.getElementById('test-container'));
// The handleKeydown method should exist
runner.expect(typeof renderer.handleKeydown).toBe('function');
}
});
runner.it('should handle Ctrl+Enter for accepting changes', async () => {
// Mock event for Ctrl+Enter
const mockEvent = {
ctrlKey: true,
key: 'Enter',
preventDefault: () => {},
target: { closest: () => null }
};
// Test that the method exists and can be called
if (global.DOMRenderer) {
const renderer = new global.DOMRenderer({}, document.createElement('div'));
// Should not throw error when called
try {
renderer.handleKeydown(mockEvent);
runner.expect(true).toBeTruthy();
} catch (error) {
runner.expect(false).toBeTruthy();
}
}
});
runner.it('should handle Escape for canceling changes', async () => {
// Mock event for Escape
const mockEvent = {
key: 'Escape',
preventDefault: () => {},
target: { closest: () => null }
};
if (global.DOMRenderer) {
const renderer = new global.DOMRenderer({}, document.createElement('div'));
// Should not throw error when called
try {
renderer.handleKeydown(mockEvent);
runner.expect(true).toBeTruthy();
} catch (error) {
runner.expect(false).toBeTruthy();
}
}
});
});
// Run the tests
if (require.main === module) {
console.log('⌨️ Running TDD Tests for Keyboard Shortcuts Recovery');
runner.run().then(() => {
console.log('✅ Test run complete - now implement keyboard shortcuts!');
});
}
module.exports = runner;