- iconManager MaterialIconManager.js zijn nu 'unified' in 1 component, en samen met translation utilities omgezet naar een meer moderne Vue composable
- De sidebar is nu eveneens omgezet naar een Vue component.
This commit is contained in:
143
test_translation_simple.js
Normal file
143
test_translation_simple.js
Normal file
@@ -0,0 +1,143 @@
|
||||
// Simple test script for the updated useTranslation composable
|
||||
// This can be run in the browser console when the chat client is loaded
|
||||
|
||||
console.log('Testing updated useTranslation composable...');
|
||||
|
||||
// Test basic translation functionality
|
||||
async function testTranslation() {
|
||||
try {
|
||||
// Test direct API call to /api/translate
|
||||
const response = await fetch('/api/translate', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
},
|
||||
credentials: 'same-origin',
|
||||
body: JSON.stringify({
|
||||
text: 'Hello world',
|
||||
target_lang: 'nl',
|
||||
source_lang: 'en',
|
||||
context: 'test'
|
||||
})
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
const result = await response.json();
|
||||
console.log('✅ Direct API test successful:', result);
|
||||
|
||||
if (result.success) {
|
||||
console.log('✅ Translation successful:', result.translated_text);
|
||||
} else {
|
||||
console.log('❌ Translation failed:', result.error);
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error('❌ Direct API test failed:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Test empty text handling
|
||||
async function testEmptyText() {
|
||||
try {
|
||||
const response = await fetch('/api/translate', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
},
|
||||
credentials: 'same-origin',
|
||||
body: JSON.stringify({
|
||||
text: '',
|
||||
target_lang: 'nl'
|
||||
})
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
console.log('✅ Empty text test result:', result);
|
||||
|
||||
if (!result.success && result.error.includes('empty')) {
|
||||
console.log('✅ Empty text validation working correctly');
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error('❌ Empty text test failed:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Test missing parameters
|
||||
async function testMissingParams() {
|
||||
try {
|
||||
const response = await fetch('/api/translate', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Requested-With': 'XMLHttpRequest'
|
||||
},
|
||||
credentials: 'same-origin',
|
||||
body: JSON.stringify({
|
||||
text: 'Hello world'
|
||||
// Missing target_lang
|
||||
})
|
||||
});
|
||||
|
||||
const result = await response.json();
|
||||
console.log('✅ Missing params test result:', result);
|
||||
|
||||
if (!result.success && result.error.includes('missing')) {
|
||||
console.log('✅ Parameter validation working correctly');
|
||||
}
|
||||
|
||||
return result;
|
||||
} catch (error) {
|
||||
console.error('❌ Missing params test failed:', error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Run all tests
|
||||
async function runAllTests() {
|
||||
console.log('🚀 Starting translation API tests...');
|
||||
|
||||
console.log('\n1. Testing basic translation...');
|
||||
await testTranslation();
|
||||
|
||||
console.log('\n2. Testing empty text validation...');
|
||||
await testEmptyText();
|
||||
|
||||
console.log('\n3. Testing missing parameters validation...');
|
||||
await testMissingParams();
|
||||
|
||||
console.log('\n✅ All tests completed!');
|
||||
}
|
||||
|
||||
// Export for manual testing
|
||||
if (typeof window !== 'undefined') {
|
||||
window.testTranslation = testTranslation;
|
||||
window.testEmptyText = testEmptyText;
|
||||
window.testMissingParams = testMissingParams;
|
||||
window.runAllTests = runAllTests;
|
||||
|
||||
console.log('Test functions available:');
|
||||
console.log('- testTranslation()');
|
||||
console.log('- testEmptyText()');
|
||||
console.log('- testMissingParams()');
|
||||
console.log('- runAllTests()');
|
||||
}
|
||||
|
||||
// Auto-run if in Node.js environment (for CI/CD)
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
module.exports = {
|
||||
testTranslation,
|
||||
testEmptyText,
|
||||
testMissingParams,
|
||||
runAllTests
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user