Added comprehensive plugin system for independent JavaScript UI development: **Plugin Infrastructure:** - Extended existing MarkiTect plugin system with RenderingEnginePlugin base class - Added RENDERING plugin type to PluginType enum - Created RenderingConfig for asset management and deployment - Implemented RenderingEngineManager for plugin discovery and lifecycle **TestDrive JSUI Plugin:** - Extracted JavaScript UI components to independent testdrive-jsui plugin - Created standalone development environment (no Python required) - Implemented compass-positioned control panels (NW, NE, E, SE) - Added clean JSON configuration interface for Python↔JavaScript data transfer **Asset Management:** - Development mode: serve assets directly from plugin source directory - Production mode: deploy to _markitect/plugins/[plugin-name]/ structure - Configurable asset URLs and deployment strategies - Support for external dependencies (CDN resources) **Standalone Development:** - testdrive-jsui/test.html for browser-based development - Package.json with npm scripts for development server - Complete separation of JavaScript development from Python environment - Hot reload and standard web development workflow **Integration Demo:** - demo_plugin_integration.py showcasing all plugin capabilities - Standalone, plugin discovery, production deployment examples - Asset URL generation for different deployment modes This enables JavaScript-first development while maintaining clean integration with the MarkiTect Python ecosystem. Developers can now work on UI components independently using standard web development tools and workflows. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
218 lines
7.0 KiB
JavaScript
218 lines
7.0 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
/**
|
|
* TDD Test for Document Controls Component Extraction
|
|
*
|
|
* Tests the extraction of DocumentControls from the monolithic editor.js
|
|
* DocumentControls handles the floating control panel and its actions.
|
|
*/
|
|
|
|
const RefactorTestRunner = require('./refactor-test-runner.js');
|
|
|
|
const runner = new RefactorTestRunner();
|
|
|
|
// Define expected DocumentControls API
|
|
const EXPECTED_DOCUMENTCONTROLS_API = [
|
|
'constructor',
|
|
'create',
|
|
'destroy',
|
|
'show',
|
|
'hide',
|
|
'addButton',
|
|
'removeButton',
|
|
'setEventHandlers',
|
|
'updateStatus',
|
|
'getControlPanel'
|
|
];
|
|
|
|
runner.describe('DocumentControls Component Extraction', () => {
|
|
|
|
runner.it('should define expected API methods', () => {
|
|
const expectedMethods = EXPECTED_DOCUMENTCONTROLS_API;
|
|
runner.expect(expectedMethods.length).toBe(10);
|
|
runner.expect(expectedMethods).toContain('create');
|
|
runner.expect(expectedMethods).toContain('addButton');
|
|
runner.expect(expectedMethods).toContain('setEventHandlers');
|
|
});
|
|
|
|
runner.it('should load extracted DocumentControls component', () => {
|
|
// Load the extracted component
|
|
delete require.cache[require.resolve('../components/document-controls.js')];
|
|
|
|
try {
|
|
const module = require('../components/document-controls.js');
|
|
runner.expect(module.DocumentControls).toBeTruthy();
|
|
|
|
// Set global for other tests
|
|
global.ExtractedDocumentControls = module.DocumentControls;
|
|
} catch (error) {
|
|
throw new Error(`Failed to load extracted DocumentControls: ${error.message}`);
|
|
}
|
|
});
|
|
|
|
runner.it('should preserve constructor functionality', () => {
|
|
const DocumentControls = global.ExtractedDocumentControls;
|
|
|
|
const controls = new DocumentControls();
|
|
runner.expect(controls).toBeInstanceOf(DocumentControls);
|
|
runner.expect(controls.controlPanel).toBeFalsy(); // Initially null
|
|
runner.expect(controls.buttons).toBeInstanceOf(Map);
|
|
});
|
|
|
|
runner.it('should preserve control panel creation functionality', () => {
|
|
const DocumentControls = global.ExtractedDocumentControls;
|
|
|
|
const controls = new DocumentControls();
|
|
controls.create();
|
|
|
|
const panel = controls.getControlPanel();
|
|
runner.expect(panel).toBeTruthy();
|
|
runner.expect(panel.id).toBe('markitect-global-controls');
|
|
|
|
// Check that panel is added to DOM
|
|
const domPanel = document.getElementById('markitect-global-controls');
|
|
runner.expect(domPanel).toBeTruthy();
|
|
|
|
// Cleanup
|
|
controls.destroy();
|
|
});
|
|
|
|
runner.it('should preserve button creation functionality', () => {
|
|
const DocumentControls = global.ExtractedDocumentControls;
|
|
|
|
const controls = new DocumentControls();
|
|
controls.create();
|
|
|
|
// Default buttons should be created
|
|
runner.expect(controls.buttons.has('save-document')).toBeTruthy();
|
|
runner.expect(controls.buttons.has('reset-all')).toBeTruthy();
|
|
runner.expect(controls.buttons.has('show-status')).toBeTruthy();
|
|
runner.expect(controls.buttons.has('toggle-debug')).toBeTruthy();
|
|
|
|
// Check DOM elements exist
|
|
runner.expect(document.getElementById('save-document')).toBeTruthy();
|
|
runner.expect(document.getElementById('reset-all')).toBeTruthy();
|
|
runner.expect(document.getElementById('show-status')).toBeTruthy();
|
|
runner.expect(document.getElementById('toggle-debug')).toBeTruthy();
|
|
|
|
// Cleanup
|
|
controls.destroy();
|
|
});
|
|
|
|
runner.it('should support custom button addition', () => {
|
|
const DocumentControls = global.ExtractedDocumentControls;
|
|
|
|
const controls = new DocumentControls();
|
|
controls.create();
|
|
|
|
// Add custom button
|
|
const customButton = controls.addButton('custom-test', '🎯 Test', '#ff6600');
|
|
runner.expect(customButton).toBeTruthy();
|
|
runner.expect(customButton.id).toBe('custom-test');
|
|
runner.expect(customButton.textContent).toBe('🎯 Test');
|
|
|
|
// Check button is in map and DOM
|
|
runner.expect(controls.buttons.has('custom-test')).toBeTruthy();
|
|
runner.expect(document.getElementById('custom-test')).toBeTruthy();
|
|
|
|
// Cleanup
|
|
controls.destroy();
|
|
});
|
|
|
|
runner.it('should support event handler configuration', () => {
|
|
const DocumentControls = global.ExtractedDocumentControls;
|
|
|
|
const controls = new DocumentControls();
|
|
controls.create();
|
|
|
|
let saveClicked = false;
|
|
let resetClicked = false;
|
|
|
|
const handlers = {
|
|
'save-document': () => { saveClicked = true; },
|
|
'reset-all': () => { resetClicked = true; }
|
|
};
|
|
|
|
controls.setEventHandlers(handlers);
|
|
|
|
// Simulate button clicks
|
|
const saveBtn = document.getElementById('save-document');
|
|
const resetBtn = document.getElementById('reset-all');
|
|
|
|
saveBtn.click();
|
|
resetBtn.click();
|
|
|
|
runner.expect(saveClicked).toBeTruthy();
|
|
runner.expect(resetClicked).toBeTruthy();
|
|
|
|
// Cleanup
|
|
controls.destroy();
|
|
});
|
|
|
|
runner.it('should support show/hide functionality', () => {
|
|
const DocumentControls = global.ExtractedDocumentControls;
|
|
|
|
const controls = new DocumentControls();
|
|
controls.create();
|
|
|
|
const panel = controls.getControlPanel();
|
|
|
|
// Test hiding
|
|
controls.hide();
|
|
runner.expect(panel.style.display).toBe('none');
|
|
|
|
// Test showing
|
|
controls.show();
|
|
runner.expect(panel.style.display).toBe('block');
|
|
|
|
// Cleanup
|
|
controls.destroy();
|
|
});
|
|
|
|
runner.it('should preserve destroy functionality', () => {
|
|
const DocumentControls = global.ExtractedDocumentControls;
|
|
|
|
const controls = new DocumentControls();
|
|
controls.create();
|
|
|
|
// Verify panel exists
|
|
runner.expect(document.getElementById('markitect-global-controls')).toBeTruthy();
|
|
|
|
// Destroy
|
|
controls.destroy();
|
|
|
|
// Verify panel is removed
|
|
runner.expect(document.getElementById('markitect-global-controls')).toBeFalsy();
|
|
runner.expect(controls.controlPanel).toBeFalsy();
|
|
});
|
|
|
|
runner.it('should support status updates', () => {
|
|
const DocumentControls = global.ExtractedDocumentControls;
|
|
|
|
const controls = new DocumentControls();
|
|
controls.create();
|
|
|
|
// Test status update
|
|
controls.updateStatus({ totalSections: 5, editingSections: 2 });
|
|
|
|
// The status should be reflected in the panel (implementation specific)
|
|
const panel = controls.getControlPanel();
|
|
runner.expect(panel).toBeTruthy();
|
|
|
|
// Cleanup
|
|
controls.destroy();
|
|
});
|
|
});
|
|
|
|
module.exports = {
|
|
runner,
|
|
EXPECTED_DOCUMENTCONTROLS_API
|
|
};
|
|
|
|
// Run tests if called directly
|
|
if (require.main === module) {
|
|
console.log('🧪 Testing DocumentControls Component Extraction');
|
|
runner.run().then(() => {
|
|
console.log('✅ DocumentControls extraction tests completed');
|
|
});
|
|
} |