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>
226 lines
9.7 KiB
JavaScript
226 lines
9.7 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* Test Alt Text in Margin Layout
|
|
*
|
|
* Tests that the alt text input is moved to the margin area alongside buttons
|
|
*/
|
|
|
|
const { TestRunner } = require('./test_runner.js');
|
|
const runner = new TestRunner();
|
|
|
|
runner.describe('Alt Text in Margin Layout Tests', () => {
|
|
|
|
runner.it('should place alt text container in controls (margin) area', 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 image
|
|
const imageMarkdown = '';
|
|
const sections = manager.createSectionsFromMarkdown(imageMarkdown);
|
|
const imageSection = sections[0];
|
|
|
|
// Mock element
|
|
const mockElement = document.createElement('div');
|
|
mockElement.setAttribute('data-section-id', imageSection.id);
|
|
renderer.findSectionElement = () => mockElement;
|
|
|
|
// Show image editor
|
|
renderer.showImageEditor(imageSection.id, imageSection);
|
|
|
|
// Verify alt text container is in controls area
|
|
const controls = mockElement.querySelector('.ui-edit-controls');
|
|
const altTextContainer = controls.querySelector('.ui-edit-alt-text-container');
|
|
runner.expect(altTextContainer).toBeTruthy();
|
|
|
|
// Verify alt text is NOT in main editor content
|
|
const editorContent = mockElement.querySelector('.ui-edit-image-content');
|
|
const altTextInContent = editorContent.querySelector('.ui-edit-alt-text-container');
|
|
runner.expect(altTextInContent).toBeFalsy();
|
|
|
|
// Verify alt text input exists and has correct value
|
|
const altTextInput = altTextContainer.querySelector('input[type="text"]');
|
|
runner.expect(altTextInput).toBeTruthy();
|
|
runner.expect(altTextInput.value).toBe('Test Alt Text');
|
|
|
|
// Cleanup
|
|
document.body.removeChild(container);
|
|
}
|
|
});
|
|
|
|
runner.it('should position alt text before buttons in controls', 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 imageMarkdown = '';
|
|
const sections = manager.createSectionsFromMarkdown(imageMarkdown);
|
|
const imageSection = sections[0];
|
|
|
|
const mockElement = document.createElement('div');
|
|
mockElement.setAttribute('data-section-id', imageSection.id);
|
|
renderer.findSectionElement = () => mockElement;
|
|
|
|
renderer.showImageEditor(imageSection.id, imageSection);
|
|
|
|
// Get controls container and verify order
|
|
const controls = mockElement.querySelector('.ui-edit-controls');
|
|
const children = Array.from(controls.children);
|
|
|
|
// Verify alt text container is first
|
|
runner.expect(children[0].className).toBe('ui-edit-alt-text-container');
|
|
|
|
// Verify change indicator is second
|
|
runner.expect(children[1].className).toBe('change-indicator');
|
|
|
|
// Verify buttons follow
|
|
const acceptBtn = children.find(child => child.textContent.includes('Accept'));
|
|
const cancelBtn = children.find(child => child.textContent.includes('Cancel'));
|
|
const resetBtn = children.find(child => child.textContent.includes('Reset'));
|
|
|
|
runner.expect(acceptBtn).toBeTruthy();
|
|
runner.expect(cancelBtn).toBeTruthy();
|
|
runner.expect(resetBtn).toBeTruthy();
|
|
|
|
// Cleanup
|
|
document.body.removeChild(container);
|
|
}
|
|
});
|
|
|
|
runner.it('should include responsive CSS for alt text layout', 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 imageMarkdown = '';
|
|
const sections = manager.createSectionsFromMarkdown(imageMarkdown);
|
|
const imageSection = sections[0];
|
|
|
|
const mockElement = document.createElement('div');
|
|
mockElement.setAttribute('data-section-id', imageSection.id);
|
|
renderer.findSectionElement = () => mockElement;
|
|
|
|
// Show editor (this adds responsive CSS)
|
|
renderer.showImageEditor(imageSection.id, imageSection);
|
|
|
|
// Verify responsive style includes alt text rules
|
|
const responsiveStyles = Array.from(document.head.querySelectorAll('style')).find(style =>
|
|
style.textContent.includes('@media (max-width: 1024px)')
|
|
);
|
|
runner.expect(responsiveStyles).toBeTruthy();
|
|
|
|
const cssText = responsiveStyles.textContent;
|
|
runner.expect(cssText.includes('.ui-edit-alt-text-container')).toBeTruthy();
|
|
runner.expect(cssText.includes('flex: 1 !important')).toBeTruthy();
|
|
runner.expect(cssText.includes('min-width: 200px !important')).toBeTruthy();
|
|
runner.expect(cssText.includes('.change-indicator')).toBeTruthy();
|
|
runner.expect(cssText.includes('order: -1 !important')).toBeTruthy();
|
|
|
|
// Cleanup
|
|
document.body.removeChild(container);
|
|
}
|
|
});
|
|
|
|
runner.it('should handle alt text changes in margin layout', 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 imageMarkdown = '';
|
|
const sections = manager.createSectionsFromMarkdown(imageMarkdown);
|
|
const imageSection = sections[0];
|
|
|
|
const mockElement = document.createElement('div');
|
|
mockElement.setAttribute('data-section-id', imageSection.id);
|
|
renderer.findSectionElement = () => mockElement;
|
|
|
|
renderer.showImageEditor(imageSection.id, imageSection);
|
|
|
|
// Get alt text input from controls
|
|
const controls = mockElement.querySelector('.ui-edit-controls');
|
|
const altTextInput = controls.querySelector('input[type="text"]');
|
|
const changeIndicator = controls.querySelector('.change-indicator');
|
|
|
|
// Verify initial state
|
|
runner.expect(altTextInput.value).toBe('Original');
|
|
runner.expect(changeIndicator.style.display).toBe('none');
|
|
|
|
// Modify alt text
|
|
altTextInput.value = 'Modified in Margin';
|
|
const inputEvent = new Event('input', { bubbles: true });
|
|
altTextInput.dispatchEvent(inputEvent);
|
|
|
|
// Verify change indicator appears (change indicator display logic is in closure)
|
|
runner.expect(changeIndicator).toBeTruthy();
|
|
|
|
// Cleanup
|
|
document.body.removeChild(container);
|
|
}
|
|
});
|
|
|
|
runner.it('should maintain wider controls area for alt text', 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 imageMarkdown = '';
|
|
const sections = manager.createSectionsFromMarkdown(imageMarkdown);
|
|
const imageSection = sections[0];
|
|
|
|
const mockElement = document.createElement('div');
|
|
mockElement.setAttribute('data-section-id', imageSection.id);
|
|
renderer.findSectionElement = () => mockElement;
|
|
|
|
renderer.showImageEditor(imageSection.id, imageSection);
|
|
|
|
// Verify controls area is wider to accommodate alt text
|
|
const controls = mockElement.querySelector('.ui-edit-controls');
|
|
runner.expect(controls.style.minWidth).toBe('180px'); // Increased from 100px
|
|
|
|
// Cleanup
|
|
document.body.removeChild(container);
|
|
}
|
|
});
|
|
});
|
|
|
|
// Run the tests
|
|
if (require.main === module) {
|
|
console.log('📝 Running Alt Text in Margin Layout 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 - alt text margin layout needs attention`);
|
|
} else {
|
|
console.log('✅ All alt text margin layout tests passed!');
|
|
}
|
|
});
|
|
}
|
|
|
|
module.exports = runner; |