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>
227 lines
9.6 KiB
JavaScript
227 lines
9.6 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Test Image UI Closure
|
|
*
|
|
* Tests to verify that accept, cancel, and reset buttons properly close the image editing UI
|
|
*/
|
|
|
|
const { TestRunner } = require('./test_runner.js');
|
|
const runner = new TestRunner();
|
|
|
|
runner.describe('Image UI Closure Tests', () => {
|
|
|
|
runner.it('should remove image editor container when hideEditor is called', 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');
|
|
const manager = new global.SectionManager();
|
|
const renderer = new global.DOMRenderer(manager, container);
|
|
|
|
// Create a section element with an image editor container
|
|
const sectionElement = document.createElement('div');
|
|
sectionElement.setAttribute('data-section-id', 'test-section');
|
|
|
|
const imageEditorContainer = document.createElement('div');
|
|
imageEditorContainer.className = 'ui-edit-image-editor-container';
|
|
sectionElement.appendChild(imageEditorContainer);
|
|
|
|
// Mock findSectionElement to return our test element
|
|
renderer.findSectionElement = () => sectionElement;
|
|
|
|
// Verify container exists before hiding
|
|
runner.expect(sectionElement.querySelector('.ui-edit-image-editor-container')).toBeTruthy();
|
|
|
|
// Call hideEditor
|
|
renderer.hideEditor('test-section');
|
|
|
|
// Verify container was removed
|
|
runner.expect(sectionElement.querySelector('.ui-edit-image-editor-container')).toBeFalsy();
|
|
}
|
|
});
|
|
|
|
runner.it('should remove text editor container when hideEditor is called', async () => {
|
|
if (global.DOMRenderer && global.SectionManager) {
|
|
const container = document.createElement('div');
|
|
const manager = new global.SectionManager();
|
|
const renderer = new global.DOMRenderer(manager, container);
|
|
|
|
// Create a section element with a text editor container
|
|
const sectionElement = document.createElement('div');
|
|
sectionElement.setAttribute('data-section-id', 'test-section');
|
|
|
|
const textEditorContainer = document.createElement('div');
|
|
textEditorContainer.className = 'ui-edit-editor-container';
|
|
sectionElement.appendChild(textEditorContainer);
|
|
|
|
// Mock findSectionElement to return our test element
|
|
renderer.findSectionElement = () => sectionElement;
|
|
|
|
// Verify container exists before hiding
|
|
runner.expect(sectionElement.querySelector('.ui-edit-editor-container')).toBeTruthy();
|
|
|
|
// Call hideEditor
|
|
renderer.hideEditor('test-section');
|
|
|
|
// Verify container was removed
|
|
runner.expect(sectionElement.querySelector('.ui-edit-editor-container')).toBeFalsy();
|
|
}
|
|
});
|
|
|
|
runner.it('should handle case where no editor containers exist', async () => {
|
|
if (global.DOMRenderer && global.SectionManager) {
|
|
const container = document.createElement('div');
|
|
const manager = new global.SectionManager();
|
|
const renderer = new global.DOMRenderer(manager, container);
|
|
|
|
// Create a section element with no editor containers
|
|
const sectionElement = document.createElement('div');
|
|
sectionElement.setAttribute('data-section-id', 'test-section');
|
|
|
|
// Mock findSectionElement to return our test element
|
|
renderer.findSectionElement = () => sectionElement;
|
|
|
|
// Call hideEditor - should not throw error
|
|
try {
|
|
renderer.hideEditor('test-section');
|
|
runner.expect(true).toBeTruthy(); // Should reach here without error
|
|
} catch (error) {
|
|
runner.expect(false).toBeTruthy(); // Should not throw
|
|
}
|
|
}
|
|
});
|
|
|
|
runner.it('should handle both editor types in same element', async () => {
|
|
if (global.DOMRenderer && global.SectionManager) {
|
|
const container = document.createElement('div');
|
|
const manager = new global.SectionManager();
|
|
const renderer = new global.DOMRenderer(manager, container);
|
|
|
|
// Create a section element with both editor containers
|
|
const sectionElement = document.createElement('div');
|
|
sectionElement.setAttribute('data-section-id', 'test-section');
|
|
|
|
const textEditorContainer = document.createElement('div');
|
|
textEditorContainer.className = 'ui-edit-editor-container';
|
|
sectionElement.appendChild(textEditorContainer);
|
|
|
|
const imageEditorContainer = document.createElement('div');
|
|
imageEditorContainer.className = 'ui-edit-image-editor-container';
|
|
sectionElement.appendChild(imageEditorContainer);
|
|
|
|
// Mock findSectionElement to return our test element
|
|
renderer.findSectionElement = () => sectionElement;
|
|
|
|
// Verify both containers exist before hiding
|
|
runner.expect(sectionElement.querySelector('.ui-edit-editor-container')).toBeTruthy();
|
|
runner.expect(sectionElement.querySelector('.ui-edit-image-editor-container')).toBeTruthy();
|
|
|
|
// Call hideEditor
|
|
renderer.hideEditor('test-section');
|
|
|
|
// Verify both containers were removed
|
|
runner.expect(sectionElement.querySelector('.ui-edit-editor-container')).toBeFalsy();
|
|
runner.expect(sectionElement.querySelector('.ui-edit-image-editor-container')).toBeFalsy();
|
|
}
|
|
});
|
|
|
|
runner.it('should verify accept button closes UI by calling hideEditor', async () => {
|
|
if (global.DOMRenderer && global.SectionManager) {
|
|
const container = document.createElement('div');
|
|
const manager = new global.SectionManager();
|
|
const renderer = new global.DOMRenderer(manager, container);
|
|
|
|
// Create section with image
|
|
const imageMarkdown = '';
|
|
const sections = manager.createSectionsFromMarkdown(imageMarkdown);
|
|
const imageSection = sections[0];
|
|
|
|
// Start editing
|
|
manager.startEditing(imageSection.id);
|
|
|
|
// Test that hideEditor is available and can be called
|
|
runner.expect(typeof renderer.hideEditor).toBe('function');
|
|
|
|
// Simulate what accept button does
|
|
try {
|
|
manager.acceptChanges(imageSection.id);
|
|
renderer.hideEditor(imageSection.id);
|
|
runner.expect(true).toBeTruthy(); // Should complete without error
|
|
} catch (error) {
|
|
runner.expect(false).toBeTruthy(); // Should not throw
|
|
}
|
|
}
|
|
});
|
|
|
|
runner.it('should verify cancel button closes UI by calling hideEditor', async () => {
|
|
if (global.DOMRenderer && global.SectionManager) {
|
|
const container = document.createElement('div');
|
|
const manager = new global.SectionManager();
|
|
const renderer = new global.DOMRenderer(manager, container);
|
|
|
|
// Create section with image
|
|
const imageMarkdown = '';
|
|
const sections = manager.createSectionsFromMarkdown(imageMarkdown);
|
|
const imageSection = sections[0];
|
|
|
|
// Start editing
|
|
manager.startEditing(imageSection.id);
|
|
|
|
// Simulate what cancel button does
|
|
try {
|
|
manager.cancelChanges(imageSection.id);
|
|
renderer.hideEditor(imageSection.id);
|
|
runner.expect(true).toBeTruthy(); // Should complete without error
|
|
} catch (error) {
|
|
runner.expect(false).toBeTruthy(); // Should not throw
|
|
}
|
|
}
|
|
});
|
|
|
|
runner.it('should verify reset button closes UI by calling hideEditor', async () => {
|
|
if (global.DOMRenderer && global.SectionManager) {
|
|
const container = document.createElement('div');
|
|
const manager = new global.SectionManager();
|
|
const renderer = new global.DOMRenderer(manager, container);
|
|
|
|
// Create section with image
|
|
const imageMarkdown = '';
|
|
const sections = manager.createSectionsFromMarkdown(imageMarkdown);
|
|
const imageSection = sections[0];
|
|
|
|
// Start editing
|
|
manager.startEditing(imageSection.id);
|
|
|
|
// Simulate what reset button does
|
|
try {
|
|
manager.resetSection(imageSection.id);
|
|
renderer.hideEditor(imageSection.id);
|
|
// Should also update content
|
|
renderer.updateSectionContent(imageSection.id, imageSection.currentMarkdown);
|
|
runner.expect(true).toBeTruthy(); // Should complete without error
|
|
} catch (error) {
|
|
runner.expect(false).toBeTruthy(); // Should not throw
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
// Run the tests
|
|
if (require.main === module) {
|
|
console.log('🎭 Running Image UI Closure 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 - UI closure needs attention`);
|
|
} else {
|
|
console.log('✅ All image UI closure tests passed!');
|
|
}
|
|
});
|
|
}
|
|
|
|
module.exports = runner; |