Class_generator/tests/ai-validation/test-modules-validation.js
StillHammer f5cef0c913 Add comprehensive testing suite with UI/UX and E2E integration tests
- Create complete integration test system (test-integration.js)
- Add UI/UX interaction testing with real event simulation (test-uiux-integration.js)
- Implement end-to-end scenario testing for user journeys (test-e2e-scenarios.js)
- Add console testing commands for rapid development testing (test-console-commands.js)
- Create comprehensive test guide documentation (TEST-GUIDE.md)
- Integrate test buttons in debug panel (F12 → 3 test types)
- Add vocabulary modal two-progress-bar system integration
- Fix flashcard retry system for "don't know" cards
- Update IntelligentSequencer for task distribution validation

🧪 Testing Coverage:
- 35+ integration tests (architecture/modules)
- 20+ UI/UX tests (real user interactions)
- 5 E2E scenarios (complete user journeys)
- Console commands for rapid testing
- Debug panel integration

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-28 23:04:38 +08:00

215 lines
8.3 KiB
JavaScript
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* Module Validation Test
* Test if the Open Analysis Modules can be loaded and initialized properly
*/
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
async function testModuleLoading() {
console.log('🧪 Testing Open Analysis Modules...\n');
const testResults = {
textAnalysis: false,
grammarAnalysis: false,
translation: false,
interfaceCompliance: false
};
try {
// Test 1: Load ExerciseModuleInterface
console.log('1⃣ Testing ExerciseModuleInterface...');
const { default: ExerciseModuleInterface } = await import('./src/DRS/interfaces/ExerciseModuleInterface.js');
console.log('✅ ExerciseModuleInterface loaded successfully');
// Test 2: Load TextAnalysisModule
console.log('\n2⃣ Testing TextAnalysisModule...');
const { default: TextAnalysisModule } = await import('./src/DRS/exercise-modules/TextAnalysisModule.js');
// Create mock dependencies
const mockDependencies = createMockDependencies();
// Try to instantiate
const textModule = new TextAnalysisModule(
mockDependencies.orchestrator,
mockDependencies.llmValidator,
mockDependencies.prerequisiteEngine,
mockDependencies.contextMemory
);
// Test interface compliance
const requiredMethods = ['canRun', 'present', 'validate', 'getProgress', 'cleanup', 'getMetadata'];
const missingMethods = requiredMethods.filter(method => typeof textModule[method] !== 'function');
if (missingMethods.length === 0) {
console.log('✅ TextAnalysisModule implements all required methods');
testResults.textAnalysis = true;
} else {
console.log('❌ TextAnalysisModule missing methods:', missingMethods);
}
// Test metadata
const metadata = textModule.getMetadata();
console.log('📋 TextAnalysisModule metadata:', metadata.name, metadata.version);
// Test 3: Load GrammarAnalysisModule
console.log('\n3⃣ Testing GrammarAnalysisModule...');
const { default: GrammarAnalysisModule } = await import('./src/DRS/exercise-modules/GrammarAnalysisModule.js');
const grammarModule = new GrammarAnalysisModule(
mockDependencies.orchestrator,
mockDependencies.llmValidator,
mockDependencies.prerequisiteEngine,
mockDependencies.contextMemory
);
const grammarMissingMethods = requiredMethods.filter(method => typeof grammarModule[method] !== 'function');
if (grammarMissingMethods.length === 0) {
console.log('✅ GrammarAnalysisModule implements all required methods');
testResults.grammarAnalysis = true;
} else {
console.log('❌ GrammarAnalysisModule missing methods:', grammarMissingMethods);
}
const grammarMetadata = grammarModule.getMetadata();
console.log('📋 GrammarAnalysisModule metadata:', grammarMetadata.name, grammarMetadata.version);
// Test 4: Load TranslationModule
console.log('\n4⃣ Testing TranslationModule...');
const { default: TranslationModule } = await import('./src/DRS/exercise-modules/TranslationModule.js');
const translationModule = new TranslationModule(
mockDependencies.orchestrator,
mockDependencies.llmValidator,
mockDependencies.prerequisiteEngine,
mockDependencies.contextMemory
);
const translationMissingMethods = requiredMethods.filter(method => typeof translationModule[method] !== 'function');
if (translationMissingMethods.length === 0) {
console.log('✅ TranslationModule implements all required methods');
testResults.translation = true;
} else {
console.log('❌ TranslationModule missing methods:', translationMissingMethods);
}
const translationMetadata = translationModule.getMetadata();
console.log('📋 TranslationModule metadata:', translationMetadata.name, translationMetadata.version);
// Test 5: Interface compliance
console.log('\n5⃣ Testing interface compliance...');
const allModules = [textModule, grammarModule, translationModule];
const interfaceCompliant = allModules.every(module => module instanceof ExerciseModuleInterface);
if (interfaceCompliant) {
console.log('✅ All modules extend ExerciseModuleInterface properly');
testResults.interfaceCompliance = true;
} else {
console.log('❌ Some modules do not properly extend ExerciseModuleInterface');
}
// Test 6: CanRun validation
console.log('\n6⃣ Testing canRun validation...');
const mockChapterContent = {
texts: ['Sample text for analysis'],
grammar: ['Sample grammar exercise'],
translations: ['Bonjour', 'Hello']
};
const canRunResults = allModules.map(module => {
try {
const canRun = module.canRun([], mockChapterContent);
return { module: module.constructor.name, canRun, error: null };
} catch (error) {
return { module: module.constructor.name, canRun: false, error: error.message };
}
});
canRunResults.forEach(result => {
if (result.error) {
console.log(`${result.module} canRun error:`, result.error);
} else {
console.log(`${result.canRun ? '✅' : '⚠️'} ${result.module} canRun:`, result.canRun);
}
});
} catch (error) {
console.error('❌ Critical error during testing:', error);
console.error('Stack trace:', error.stack);
}
// Summary
console.log('\n📊 Test Summary:');
console.log('================');
Object.entries(testResults).forEach(([test, passed]) => {
console.log(`${passed ? '✅' : '❌'} ${test}: ${passed ? 'PASSED' : 'FAILED'}`);
});
const allPassed = Object.values(testResults).every(result => result);
console.log(`\n${allPassed ? '🎉' : '⚠️'} Overall: ${allPassed ? 'ALL TESTS PASSED' : 'SOME TESTS FAILED'}`);
return testResults;
}
function createMockDependencies() {
return {
orchestrator: {
getSharedServices: () => ({
iaEngine: {
validateEducationalContent: async (prompt, options) => ({
content: JSON.stringify([{
question: "Test question",
expectations: "Test expectations",
targetLength: 100
}])
})
}
}),
handleExerciseCompletion: (data) => {
console.log('📊 Exercise completion handled:', data.moduleType);
}
},
llmValidator: {
isAvailable: () => true,
validateTextComprehension: async (text, response, context) => ({
success: true,
score: 0.8,
feedback: "Mock feedback for text comprehension",
suggestions: ["Mock suggestion 1", "Mock suggestion 2"]
}),
validateGrammar: async (response, context) => ({
success: true,
score: 0.75,
feedback: "Mock feedback for grammar",
explanation: "Mock grammar explanation",
suggestions: ["Mock grammar suggestion"]
}),
validateTranslation: async (original, translation, context) => ({
success: true,
score: 0.85,
feedback: "Mock feedback for translation",
fluencyScore: 0.8,
culturalContext: "Mock cultural context",
suggestions: ["Mock translation suggestion"]
})
},
prerequisiteEngine: {
checkPrerequisites: () => true
},
contextMemory: {
store: () => {},
retrieve: () => null
}
};
}
// Run the test
testModuleLoading().catch(error => {
console.error('❌ Test execution failed:', error);
process.exit(1);
});