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>
This commit is contained in:
202
history/javascript-dev-tests/test_image_editor_debug.js
Normal file
202
history/javascript-dev-tests/test_image_editor_debug.js
Normal file
@@ -0,0 +1,202 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Debug Image Editor Issues
|
||||
*
|
||||
* Tests to identify why the image editor is not working
|
||||
*/
|
||||
|
||||
const { TestRunner } = require('./test_runner.js');
|
||||
const runner = new TestRunner();
|
||||
|
||||
runner.describe('Image Editor Debug Tests', () => {
|
||||
|
||||
runner.it('should successfully call showImageEditor method', async () => {
|
||||
// Load editor
|
||||
delete require.cache[require.resolve('/home/worsch/markitect_project/markitect/static/editor.js')];
|
||||
require('/home/worsch/markitect_project/markitect/static/editor.js');
|
||||
|
||||
if (global.DOMRenderer && global.SectionManager) {
|
||||
const container = document.createElement('div');
|
||||
container.innerHTML = '<div id="markdown-content"></div>';
|
||||
document.body.appendChild(container);
|
||||
|
||||
const manager = new global.SectionManager();
|
||||
const renderer = new global.DOMRenderer(manager, container);
|
||||
|
||||
// Create image section
|
||||
const imageMarkdown = '';
|
||||
const sections = manager.createSectionsFromMarkdown(imageMarkdown);
|
||||
const imageSection = sections[0];
|
||||
|
||||
runner.expect(imageSection.isImage()).toBeTruthy();
|
||||
|
||||
const mockElement = document.createElement('div');
|
||||
mockElement.setAttribute('data-section-id', imageSection.id);
|
||||
Object.defineProperties(mockElement, {
|
||||
getBoundingClientRect: {
|
||||
value: () => ({ top: 100, right: 400, bottom: 200, left: 50, width: 350, height: 100 })
|
||||
}
|
||||
});
|
||||
|
||||
renderer.findSectionElement = () => mockElement;
|
||||
|
||||
// Try to show image editor
|
||||
try {
|
||||
renderer.showImageEditor(imageSection.id, imageSection);
|
||||
|
||||
// Check if floating menu was created
|
||||
const floatingMenu = document.querySelector('.ui-edit-floating-menu[data-edit-type="image"]');
|
||||
runner.expect(floatingMenu).toBeTruthy();
|
||||
|
||||
// Check if it has image-specific content
|
||||
const imagePreview = floatingMenu.querySelector('.ui-edit-image-preview');
|
||||
const altTextInput = floatingMenu.querySelector('input[type="text"]');
|
||||
|
||||
runner.expect(imagePreview).toBeTruthy();
|
||||
runner.expect(altTextInput).toBeTruthy();
|
||||
runner.expect(altTextInput.value).toBe('Test Image');
|
||||
|
||||
// Cleanup
|
||||
floatingMenu.remove();
|
||||
} catch (error) {
|
||||
console.error('Error in showImageEditor:', error);
|
||||
runner.expect(false).toBeTruthy(); // Fail the test
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
document.body.removeChild(container);
|
||||
}
|
||||
});
|
||||
|
||||
runner.it('should detect image sections correctly', async () => {
|
||||
if (global.SectionManager) {
|
||||
const manager = new global.SectionManager();
|
||||
|
||||
// Test various image formats
|
||||
const imageMarkdowns = [
|
||||
'',
|
||||
'',
|
||||
'',
|
||||
''
|
||||
];
|
||||
|
||||
imageMarkdowns.forEach((markdown, index) => {
|
||||
const sections = manager.createSectionsFromMarkdown(markdown);
|
||||
const section = sections[0];
|
||||
|
||||
console.log(`Testing markdown ${index}: ${markdown}`);
|
||||
console.log(`Section type: ${section.constructor.name}`);
|
||||
console.log(`isImage(): ${section.isImage()}`);
|
||||
|
||||
runner.expect(section.isImage()).toBeTruthy();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
runner.it('should handle image editor button creation without errors', async () => {
|
||||
if (global.DOMRenderer && global.SectionManager) {
|
||||
const container = document.createElement('div');
|
||||
container.innerHTML = '<div id="markdown-content"></div>';
|
||||
document.body.appendChild(container);
|
||||
|
||||
const manager = new global.SectionManager();
|
||||
const renderer = new global.DOMRenderer(manager, container);
|
||||
|
||||
// Test button creation methods
|
||||
try {
|
||||
const testBtn1 = renderer.createButton('Test', 'test-class', () => {});
|
||||
runner.expect(testBtn1).toBeTruthy();
|
||||
runner.expect(testBtn1.tagName).toBe('BUTTON');
|
||||
|
||||
const testBtn2 = renderer.createButton('✓ Accept', 'ui-edit-accept', () => {});
|
||||
runner.expect(testBtn2).toBeTruthy();
|
||||
runner.expect(testBtn2.textContent).toBe('✓ Accept');
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error creating buttons:', error);
|
||||
runner.expect(false).toBeTruthy();
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
document.body.removeChild(container);
|
||||
}
|
||||
});
|
||||
|
||||
runner.it('should check for syntax errors in image editor method', async () => {
|
||||
if (global.DOMRenderer && global.SectionManager) {
|
||||
const container = document.createElement('div');
|
||||
container.innerHTML = '<div id="markdown-content"></div>';
|
||||
document.body.appendChild(container);
|
||||
|
||||
const manager = new global.SectionManager();
|
||||
const renderer = new global.DOMRenderer(manager, container);
|
||||
|
||||
// Verify method exists and is callable
|
||||
runner.expect(typeof renderer.showImageEditor).toBe('function');
|
||||
|
||||
const imageMarkdown = '';
|
||||
const sections = manager.createSectionsFromMarkdown(imageMarkdown);
|
||||
const imageSection = sections[0];
|
||||
|
||||
const mockElement = document.createElement('div');
|
||||
mockElement.setAttribute('data-section-id', imageSection.id);
|
||||
Object.defineProperties(mockElement, {
|
||||
getBoundingClientRect: {
|
||||
value: () => ({ top: 100, right: 400, bottom: 200, left: 50, width: 350, height: 100 })
|
||||
}
|
||||
});
|
||||
|
||||
renderer.findSectionElement = () => mockElement;
|
||||
|
||||
// Check if we can at least start the method without throwing
|
||||
let methodStarted = false;
|
||||
try {
|
||||
// Mock createFloatingMenu to see if we get that far
|
||||
const originalCreateFloatingMenu = renderer.createFloatingMenu;
|
||||
renderer.createFloatingMenu = function() {
|
||||
methodStarted = true;
|
||||
return originalCreateFloatingMenu.apply(this, arguments);
|
||||
};
|
||||
|
||||
renderer.showImageEditor(imageSection.id, imageSection);
|
||||
runner.expect(methodStarted).toBeTruthy();
|
||||
|
||||
} catch (error) {
|
||||
console.error('Method failed before reaching createFloatingMenu:', error);
|
||||
console.error('Stack trace:', error.stack);
|
||||
runner.expect(false).toBeTruthy();
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
document.body.removeChild(container);
|
||||
const floatingMenu = document.querySelector('.ui-edit-floating-menu');
|
||||
if (floatingMenu) floatingMenu.remove();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Run the tests
|
||||
if (require.main === module) {
|
||||
console.log('🔍 Running Image Editor Debug Tests');
|
||||
runner.run().then(() => {
|
||||
const results = runner.results;
|
||||
const failed = results.filter(r => r.status === 'FAIL').length;
|
||||
|
||||
if (failed > 0) {
|
||||
console.log(`❌ ${failed} test(s) failed - image editor has issues`);
|
||||
results.forEach(result => {
|
||||
if (result.status === 'FAIL') {
|
||||
console.log(`\nFailed test: ${result.name}`);
|
||||
if (result.error) {
|
||||
console.log(`Error: ${result.error}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.log('✅ All image editor debug tests passed!');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = runner;
|
||||
Reference in New Issue
Block a user