This commit implements 5 major JavaScript features that were lost during refactoring, using systematic Test-Driven Development methodology: **Core Features Implemented:** - Advanced EditState enum with pending changes preservation - Keyboard shortcuts (Ctrl+Enter accept, Escape cancel) - Section splitting with dynamic heading detection - Real-time status tracking with 2-second periodic updates - Intelligent filename generation with 4-method fallback system **Technical Improvements:** - Comprehensive TDD test suites for all functionality - Professional status panel with color-coded indicators - Smart filename generation (options→title→URL→heading→timestamp) - Event-driven architecture with custom event emission - State preservation during editing transitions **Files Added:** - markitect/static/editor.js - Complete JavaScript functionality - test_*.js - Comprehensive TDD test suites - LOST_FUNCTIONALITY_ANALYSIS.md - Detailed feature comparison - TEST_ENVIRONMENT.md - TDD setup documentation **Updated Documentation:** - TODO.md - Status tracking and progress documentation All features are fully tested and integrated into the existing codebase. The TDD approach proved highly effective for systematic functionality recovery. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
249 lines
7.4 KiB
JavaScript
Executable File
249 lines
7.4 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
/**
|
|
* HTML Editor Test Runner
|
|
*
|
|
* This script provides a test environment for our HTML editor functionality
|
|
* using puppeteer for headless browser testing.
|
|
*/
|
|
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
// Simple test framework
|
|
class TestRunner {
|
|
constructor() {
|
|
this.tests = [];
|
|
this.results = [];
|
|
this.currentTest = null;
|
|
}
|
|
|
|
describe(description, testFn) {
|
|
console.log(`\n📋 Test Suite: ${description}`);
|
|
console.log('━'.repeat(50));
|
|
testFn();
|
|
}
|
|
|
|
it(description, testFn) {
|
|
this.tests.push({ description, testFn });
|
|
}
|
|
|
|
async run() {
|
|
console.log(`\n🚀 Running ${this.tests.length} tests...\n`);
|
|
|
|
for (const test of this.tests) {
|
|
this.currentTest = test;
|
|
try {
|
|
console.log(` 🧪 ${test.description}`);
|
|
await test.testFn();
|
|
this.results.push({ ...test, status: 'PASS' });
|
|
console.log(` ✅ PASS`);
|
|
} catch (error) {
|
|
this.results.push({ ...test, status: 'FAIL', error });
|
|
console.log(` ❌ FAIL: ${error.message}`);
|
|
}
|
|
}
|
|
|
|
this.printSummary();
|
|
}
|
|
|
|
printSummary() {
|
|
const passed = this.results.filter(r => r.status === 'PASS').length;
|
|
const failed = this.results.filter(r => r.status === 'FAIL').length;
|
|
|
|
console.log('\n' + '═'.repeat(50));
|
|
console.log(`📊 Test Results: ${passed} passed, ${failed} failed`);
|
|
|
|
if (failed > 0) {
|
|
console.log('\n❌ Failed Tests:');
|
|
this.results.filter(r => r.status === 'FAIL').forEach(test => {
|
|
console.log(` • ${test.description}: ${test.error.message}`);
|
|
});
|
|
}
|
|
|
|
console.log('═'.repeat(50));
|
|
}
|
|
|
|
expect(actual) {
|
|
return {
|
|
toBe: (expected) => {
|
|
if (actual !== expected) {
|
|
throw new Error(`Expected ${expected}, got ${actual}`);
|
|
}
|
|
},
|
|
toContain: (expected) => {
|
|
if (!actual.includes(expected)) {
|
|
throw new Error(`Expected "${actual}" to contain "${expected}"`);
|
|
}
|
|
},
|
|
toBeTruthy: () => {
|
|
if (!actual) {
|
|
throw new Error(`Expected truthy value, got ${actual}`);
|
|
}
|
|
},
|
|
toBeFalsy: () => {
|
|
if (actual) {
|
|
throw new Error(`Expected falsy value, got ${actual}`);
|
|
}
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
// HTML File Tester
|
|
class HTMLFileTester {
|
|
constructor(htmlFilePath) {
|
|
this.htmlFilePath = htmlFilePath;
|
|
this.html = null;
|
|
this.jsdom = null;
|
|
this.window = null;
|
|
this.document = null;
|
|
}
|
|
|
|
async load() {
|
|
try {
|
|
// Try to use jsdom if available
|
|
const { JSDOM } = require('jsdom');
|
|
this.html = fs.readFileSync(this.htmlFilePath, 'utf8');
|
|
|
|
// Create a DOM environment
|
|
this.jsdom = new JSDOM(this.html, {
|
|
runScripts: "dangerously",
|
|
resources: "usable",
|
|
pretendToBeVisual: true
|
|
});
|
|
|
|
this.window = this.jsdom.window;
|
|
this.document = this.window.document;
|
|
|
|
// Wait for content to load
|
|
await new Promise(resolve => {
|
|
if (this.document.readyState === 'complete') {
|
|
resolve();
|
|
} else {
|
|
this.window.addEventListener('load', resolve);
|
|
}
|
|
});
|
|
|
|
return true;
|
|
} catch (error) {
|
|
// Fallback to simple HTML parsing
|
|
this.html = fs.readFileSync(this.htmlFilePath, 'utf8');
|
|
console.log('⚠️ Using fallback HTML parsing (install jsdom for full testing)');
|
|
return false;
|
|
}
|
|
}
|
|
|
|
hasElement(selector) {
|
|
if (this.document) {
|
|
return !!this.document.querySelector(selector);
|
|
}
|
|
// Fallback: simple text search
|
|
return this.html.includes(selector);
|
|
}
|
|
|
|
getElement(selector) {
|
|
if (this.document) {
|
|
return this.document.querySelector(selector);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
hasJavaScript(functionName) {
|
|
return this.html.includes(functionName);
|
|
}
|
|
|
|
hasDebugMode() {
|
|
return this.html.includes('DEBUG_MODE');
|
|
}
|
|
|
|
getDebugMode() {
|
|
const match = this.html.match(/const DEBUG_MODE = ['"`](\w+)['"`];/);
|
|
return match ? match[1] : null;
|
|
}
|
|
|
|
simulate(action, selector) {
|
|
if (!this.document) {
|
|
throw new Error('Cannot simulate actions without DOM environment');
|
|
}
|
|
|
|
const element = this.document.querySelector(selector);
|
|
if (!element) {
|
|
throw new Error(`Element not found: ${selector}`);
|
|
}
|
|
|
|
switch (action) {
|
|
case 'click':
|
|
element.click();
|
|
break;
|
|
case 'focus':
|
|
element.focus();
|
|
break;
|
|
default:
|
|
throw new Error(`Unknown action: ${action}`);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Main test runner instance
|
|
const runner = new TestRunner();
|
|
|
|
// Export for use
|
|
module.exports = { TestRunner, HTMLFileTester, runner };
|
|
|
|
// If run directly, run basic tests
|
|
if (require.main === module) {
|
|
console.log('🧪 HTML Editor Test Runner');
|
|
console.log('Usage: node test_runner.js [html-file-path]');
|
|
|
|
const htmlFile = process.argv[2] || '/tmp/test_complete_functionality.html';
|
|
|
|
if (!fs.existsSync(htmlFile)) {
|
|
console.error(`❌ File not found: ${htmlFile}`);
|
|
process.exit(1);
|
|
}
|
|
|
|
// Basic structural tests
|
|
runner.describe('HTML Structure Tests', () => {
|
|
let tester;
|
|
|
|
runner.it('should load HTML file successfully', async () => {
|
|
tester = new HTMLFileTester(htmlFile);
|
|
const loaded = await tester.load();
|
|
runner.expect(loaded || tester.html).toBeTruthy();
|
|
});
|
|
|
|
runner.it('should have markdown content container', async () => {
|
|
runner.expect(tester.hasElement('#markdown-content')).toBeTruthy();
|
|
});
|
|
|
|
runner.it('should have debug system', async () => {
|
|
runner.expect(tester.hasDebugMode()).toBeTruthy();
|
|
});
|
|
|
|
runner.it('should use console debug mode', async () => {
|
|
runner.expect(tester.getDebugMode()).toBe('console');
|
|
});
|
|
|
|
runner.it('should have section editor functions', async () => {
|
|
runner.expect(tester.hasJavaScript('MarkitectCleanEditor')).toBeTruthy();
|
|
runner.expect(tester.hasJavaScript('showImageEditor')).toBeTruthy();
|
|
runner.expect(tester.hasJavaScript('setupAutoResize')).toBeTruthy();
|
|
});
|
|
|
|
runner.it('should have image manipulation functions', async () => {
|
|
runner.expect(tester.hasJavaScript('replaceImage')).toBeTruthy();
|
|
runner.expect(tester.hasJavaScript('resizeImage')).toBeTruthy();
|
|
runner.expect(tester.hasJavaScript('addImageCaption')).toBeTruthy();
|
|
runner.expect(tester.hasJavaScript('removeImage')).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
// Run the tests
|
|
runner.run().then(() => {
|
|
console.log('\n🏁 Testing complete!');
|
|
}).catch(error => {
|
|
console.error('❌ Test runner failed:', error);
|
|
process.exit(1);
|
|
});
|
|
} |