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>
254 lines
11 KiB
JavaScript
254 lines
11 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Test Responsive Overlay UI
|
|
*
|
|
* Tests the new overlay editing UI with responsive button positioning:
|
|
* - Overlay positions directly on original content
|
|
* - Buttons in margin on wide displays (>1024px)
|
|
* - Buttons beneath editor on narrow displays (≤1024px)
|
|
*/
|
|
|
|
const { TestRunner } = require('./test_runner.js');
|
|
const runner = new TestRunner();
|
|
|
|
runner.describe('Responsive Overlay UI Tests', () => {
|
|
|
|
runner.it('should create overlay container with proper styling for text editor', 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 section with text content
|
|
const textMarkdown = '# Test Heading\n\nThis is test content for overlay UI.';
|
|
const sections = manager.createSectionsFromMarkdown(textMarkdown);
|
|
const textSection = sections[0];
|
|
|
|
// Mock original element height
|
|
const mockElement = document.createElement('div');
|
|
mockElement.setAttribute('data-section-id', textSection.id);
|
|
mockElement.style.height = '150px';
|
|
renderer.findSectionElement = () => mockElement;
|
|
|
|
// Show editor
|
|
renderer.showEditor(textSection.id, textSection.currentMarkdown);
|
|
|
|
// Verify overlay container exists
|
|
const overlayContainer = mockElement.querySelector('.ui-edit-overlay-container');
|
|
runner.expect(overlayContainer).toBeTruthy();
|
|
runner.expect(overlayContainer.style.position).toBe('relative');
|
|
runner.expect(overlayContainer.style.zIndex).toBe('1000');
|
|
runner.expect(overlayContainer.style.display).toBe('flex');
|
|
|
|
// Verify editor content area
|
|
const editorContent = overlayContainer.querySelector('.ui-edit-editor-content');
|
|
runner.expect(editorContent).toBeTruthy();
|
|
runner.expect(editorContent.style.flex).toBe('1');
|
|
|
|
// Verify controls are positioned correctly
|
|
const controls = overlayContainer.querySelector('.ui-edit-controls');
|
|
runner.expect(controls).toBeTruthy();
|
|
runner.expect(controls.style.flexDirection).toBe('column');
|
|
runner.expect(controls.style.minWidth).toBe('100px');
|
|
|
|
// Verify buttons exist
|
|
const acceptBtn = controls.querySelector('.ui-edit-button-accept');
|
|
const cancelBtn = controls.querySelector('.ui-edit-button-cancel');
|
|
const resetBtn = controls.querySelector('.ui-edit-button-reset');
|
|
runner.expect(acceptBtn).toBeTruthy();
|
|
runner.expect(cancelBtn).toBeTruthy();
|
|
runner.expect(resetBtn).toBeTruthy();
|
|
|
|
// Cleanup
|
|
document.body.removeChild(container);
|
|
}
|
|
});
|
|
|
|
runner.it('should create overlay container with proper styling for image editor', 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);
|
|
|
|
// Create section with image content
|
|
const imageMarkdown = '';
|
|
const sections = manager.createSectionsFromMarkdown(imageMarkdown);
|
|
const imageSection = sections[0];
|
|
|
|
// Mock original element height
|
|
const mockElement = document.createElement('div');
|
|
mockElement.setAttribute('data-section-id', imageSection.id);
|
|
mockElement.style.height = '250px';
|
|
renderer.findSectionElement = () => mockElement;
|
|
|
|
// Show image editor
|
|
renderer.showImageEditor(imageSection.id, imageSection);
|
|
|
|
// Verify overlay container exists with image editor classes
|
|
const overlayContainer = mockElement.querySelector('.ui-edit-image-editor-container.ui-edit-overlay-container');
|
|
runner.expect(overlayContainer).toBeTruthy();
|
|
runner.expect(overlayContainer.style.position).toBe('relative');
|
|
runner.expect(overlayContainer.style.zIndex).toBe('1000');
|
|
runner.expect(overlayContainer.style.display).toBe('flex');
|
|
|
|
// Verify image editor content area
|
|
const imageContent = overlayContainer.querySelector('.ui-edit-image-content');
|
|
runner.expect(imageContent).toBeTruthy();
|
|
runner.expect(imageContent.style.flex).toBe('1');
|
|
|
|
// Verify image preview exists
|
|
const imagePreview = imageContent.querySelector('.ui-edit-image-preview');
|
|
runner.expect(imagePreview).toBeTruthy();
|
|
|
|
// Verify controls are positioned correctly
|
|
const controls = overlayContainer.querySelector('.ui-edit-controls');
|
|
runner.expect(controls).toBeTruthy();
|
|
runner.expect(controls.style.flexDirection).toBe('column');
|
|
|
|
// Cleanup
|
|
document.body.removeChild(container);
|
|
}
|
|
});
|
|
|
|
runner.it('should include responsive CSS for narrow displays', 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);
|
|
|
|
// Create section
|
|
const textMarkdown = '# Test Content';
|
|
const sections = manager.createSectionsFromMarkdown(textMarkdown);
|
|
const textSection = sections[0];
|
|
|
|
const mockElement = document.createElement('div');
|
|
mockElement.setAttribute('data-section-id', textSection.id);
|
|
renderer.findSectionElement = () => mockElement;
|
|
|
|
// Show editor (this adds responsive CSS)
|
|
renderer.showEditor(textSection.id, textSection.currentMarkdown);
|
|
|
|
// Verify responsive style was added to document head
|
|
const responsiveStyles = Array.from(document.head.querySelectorAll('style')).find(style =>
|
|
style.textContent.includes('@media (max-width: 1024px)')
|
|
);
|
|
runner.expect(responsiveStyles).toBeTruthy();
|
|
|
|
// Verify CSS content includes proper responsive rules
|
|
const cssText = responsiveStyles.textContent;
|
|
runner.expect(cssText.includes('.ui-edit-overlay-container')).toBeTruthy();
|
|
runner.expect(cssText.includes('flex-direction: column !important')).toBeTruthy();
|
|
runner.expect(cssText.includes('.ui-edit-controls')).toBeTruthy();
|
|
runner.expect(cssText.includes('flex-direction: row !important')).toBeTruthy();
|
|
runner.expect(cssText.includes('justify-content: flex-end !important')).toBeTruthy();
|
|
|
|
// Cleanup
|
|
document.body.removeChild(container);
|
|
}
|
|
});
|
|
|
|
runner.it('should maintain minimum height based on original content', 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);
|
|
|
|
// Create section
|
|
const textMarkdown = '# Test\n\nMultiple\nlines\nof\ncontent\nto\ntest\nheight\npreservation.';
|
|
const sections = manager.createSectionsFromMarkdown(textMarkdown);
|
|
const textSection = sections[0];
|
|
|
|
// Mock element with specific height
|
|
const mockElement = document.createElement('div');
|
|
mockElement.setAttribute('data-section-id', textSection.id);
|
|
Object.defineProperty(mockElement, 'offsetHeight', {
|
|
get: () => 300
|
|
});
|
|
renderer.findSectionElement = () => mockElement;
|
|
|
|
// Show editor
|
|
renderer.showEditor(textSection.id, textSection.currentMarkdown);
|
|
|
|
// Verify overlay container maintains minimum height
|
|
const overlayContainer = mockElement.querySelector('.ui-edit-overlay-container');
|
|
runner.expect(overlayContainer.style.minHeight).toBe('300px');
|
|
|
|
// Verify textarea adapts to content height
|
|
const textarea = overlayContainer.querySelector('.ui-edit-textarea');
|
|
const textareaMinHeight = parseInt(textarea.style.minHeight);
|
|
runner.expect(textareaMinHeight).toBeGreaterThan(100); // Should be based on original height
|
|
|
|
// Cleanup
|
|
document.body.removeChild(container);
|
|
}
|
|
});
|
|
|
|
runner.it('should handle button styling for vertical layout in margin', 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);
|
|
|
|
const textMarkdown = '# Test Content';
|
|
const sections = manager.createSectionsFromMarkdown(textMarkdown);
|
|
const textSection = sections[0];
|
|
|
|
const mockElement = document.createElement('div');
|
|
mockElement.setAttribute('data-section-id', textSection.id);
|
|
renderer.findSectionElement = () => mockElement;
|
|
|
|
renderer.showEditor(textSection.id, textSection.currentMarkdown);
|
|
|
|
// Verify button styling
|
|
const buttons = mockElement.querySelectorAll('.ui-edit-controls button');
|
|
runner.expect(buttons.length).toBe(3); // Accept, Cancel, Reset
|
|
|
|
buttons.forEach(button => {
|
|
const styles = button.style;
|
|
runner.expect(styles.width).toBe('100%');
|
|
runner.expect(styles.padding).toBe('8px 12px');
|
|
runner.expect(styles.whiteSpace).toBe('nowrap');
|
|
});
|
|
|
|
// Cleanup
|
|
document.body.removeChild(container);
|
|
}
|
|
});
|
|
});
|
|
|
|
// Run the tests
|
|
if (require.main === module) {
|
|
console.log('📱 Running Responsive Overlay UI 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 - responsive overlay UI needs attention`);
|
|
} else {
|
|
console.log('✅ All responsive overlay UI tests passed!');
|
|
}
|
|
});
|
|
}
|
|
|
|
module.exports = runner; |