Files
markitect-main/history/javascript-dev-tests/test_filename_generation.js
tegwick c4877543d5 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>
2025-11-09 23:16:47 +01:00

161 lines
7.0 KiB
JavaScript

#!/usr/bin/env node
/**
* TDD Tests for Intelligent Save Filename Generation Recovery
*/
const { TestRunner } = require('./test_runner.js');
const runner = new TestRunner();
// Test intelligent filename generation functionality
runner.describe('Intelligent Save Filename Generation System', () => {
runner.it('should have generateSaveFilename method in MarkitectCleanEditor', 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.MarkitectCleanEditor) {
const container = document.createElement('div');
const editor = new global.MarkitectCleanEditor('# Test\n\nContent', container);
const hasGenerateSaveFilename = typeof editor.generateSaveFilename === 'function';
runner.expect(hasGenerateSaveFilename).toBeTruthy();
}
});
runner.it('should use original filename from options when available', async () => {
if (global.MarkitectCleanEditor) {
const container = document.createElement('div');
const editor = new global.MarkitectCleanEditor('# Test\n\nContent', container, {
originalFilename: 'my-document.md'
});
const filename = editor.generateSaveFilename();
runner.expect(filename).toBe('my-document.md');
}
});
runner.it('should extract filename from page title when no original filename', async () => {
if (global.MarkitectCleanEditor) {
// Set a mock document title
const originalTitle = document.title;
document.title = 'My Amazing Document | Website';
const container = document.createElement('div');
const editor = new global.MarkitectCleanEditor('# Test\n\nContent', container);
const filename = editor.generateSaveFilename();
runner.expect(filename).toBe('My-Amazing-Document.md');
// Restore original title
document.title = originalTitle;
}
});
runner.it('should extract filename from URL pathname when no title', async () => {
if (global.MarkitectCleanEditor) {
// Mock window.location
const originalLocation = global.location;
global.location = { pathname: '/docs/user-guide/getting-started' };
const container = document.createElement('div');
const editor = new global.MarkitectCleanEditor('# Test\n\nContent', container);
const filename = editor.generateSaveFilename();
runner.expect(filename).toBe('getting-started.md');
// Restore original location
global.location = originalLocation;
}
});
runner.it('should extract filename from first heading when other methods fail', async () => {
if (global.MarkitectCleanEditor) {
const container = document.createElement('div');
const markdownContent = '# Advanced JavaScript Patterns\n\nThis is a guide to advanced patterns.';
const editor = new global.MarkitectCleanEditor(markdownContent, container);
const filename = editor.generateSaveFilename();
runner.expect(filename).toBe('Advanced-JavaScript-Patterns.md');
}
});
runner.it('should use timestamp when all other methods fail', async () => {
if (global.MarkitectCleanEditor) {
const container = document.createElement('div');
const markdownContent = 'Just some content without any headings or special info.';
const editor = new global.MarkitectCleanEditor(markdownContent, container);
const filename = editor.generateSaveFilename();
// Should start with 'document-' and end with '.md'
runner.expect(filename.startsWith('document-')).toBeTruthy();
runner.expect(filename.endsWith('.md')).toBeTruthy();
// Should contain timestamp
const timestampPart = filename.replace('document-', '').replace('.md', '');
runner.expect(timestampPart.length).toBeGreaterThan(8); // YYYYMMDD format or longer
}
});
runner.it('should sanitize filenames to be filesystem-safe', async () => {
if (global.MarkitectCleanEditor) {
const container = document.createElement('div');
const markdownContent = '# This/Has\\Bad:Characters*And?More<Stuff>\n\nContent';
const editor = new global.MarkitectCleanEditor(markdownContent, container);
const filename = editor.generateSaveFilename();
// Should not contain filesystem-unsafe characters
runner.expect(filename).not.toMatch(/[\/\\:*?"<>|]/);
runner.expect(filename).toBe('This-Has-Bad-Characters-And-More-Stuff.md');
}
});
runner.it('should handle edge cases like empty content gracefully', async () => {
if (global.MarkitectCleanEditor) {
const container = document.createElement('div');
const editor = new global.MarkitectCleanEditor('', container);
const filename = editor.generateSaveFilename();
runner.expect(filename.endsWith('.md')).toBeTruthy();
runner.expect(filename.length).toBeGreaterThan(3); // More than just '.md'
}
});
runner.it('should prefer higher priority methods over lower priority', async () => {
if (global.MarkitectCleanEditor) {
const container = document.createElement('div');
const markdownContent = '# Content Heading\n\nSome content';
const editor = new global.MarkitectCleanEditor(markdownContent, container, {
originalFilename: 'priority-test.md'
});
const filename = editor.generateSaveFilename();
// Should use original filename (method 1) over heading (method 4)
runner.expect(filename).toBe('priority-test.md');
}
});
runner.it('should have helper methods for each fallback strategy', async () => {
if (global.MarkitectCleanEditor) {
const container = document.createElement('div');
const editor = new global.MarkitectCleanEditor('# Test\n\nContent', container);
// Test helper methods exist
runner.expect(typeof editor.sanitizeFilename).toBe('function');
runner.expect(typeof editor.extractFilenameFromTitle).toBe('function');
runner.expect(typeof editor.extractFilenameFromUrl).toBe('function');
runner.expect(typeof editor.extractFilenameFromHeading).toBe('function');
runner.expect(typeof editor.generateTimestampFilename).toBe('function');
}
});
});
// Run the tests
if (require.main === module) {
console.log('💾 Running TDD Tests for Intelligent Filename Generation Recovery');
runner.run().then(() => {
console.log('✅ Test run complete - now implement filename generation!');
});
}
module.exports = runner;