131 lines
4.3 KiB
JavaScript
131 lines
4.3 KiB
JavaScript
// static/admin/js/testing-hub.js
|
||
|
||
// Setup logging
|
||
const TESTING_HUB_LOG_LEVEL = 3;
|
||
|
||
const testingLog = {
|
||
error: (...args) => TESTING_HUB_LOG_LEVEL >= 1 && console.error('❌ [TESTING HUB ERROR]', ...args),
|
||
warn: (...args) => TESTING_HUB_LOG_LEVEL >= 2 && console.warn('⚠️ [TESTING HUB WARN]', ...args),
|
||
info: (...args) => TESTING_HUB_LOG_LEVEL >= 3 && console.info('ℹ️ [TESTING HUB INFO]', ...args),
|
||
debug: (...args) => TESTING_HUB_LOG_LEVEL >= 4 && console.log('🔍 [TESTING HUB DEBUG]', ...args)
|
||
};
|
||
|
||
/**
|
||
* Testing Hub Alpine.js Component
|
||
* Central hub for all test suites and QA tools
|
||
*/
|
||
function adminTestingHub() {
|
||
return {
|
||
// ✅ CRITICAL: Inherit base layout functionality
|
||
...data(),
|
||
|
||
// ✅ CRITICAL: Set page identifier
|
||
currentPage: 'testing',
|
||
|
||
// Test suites data
|
||
testSuites: [
|
||
{
|
||
id: 'auth-flow',
|
||
name: 'Authentication Flow',
|
||
description: 'Test login, logout, token expiration, redirects, and protected route access.',
|
||
url: '/admin/test/auth-flow',
|
||
icon: 'lock-closed',
|
||
color: 'blue',
|
||
testCount: 6,
|
||
features: [
|
||
'Login with valid/invalid credentials',
|
||
'Token expiration handling',
|
||
'Protected route access & redirects',
|
||
'localStorage state monitoring'
|
||
]
|
||
},
|
||
{
|
||
id: 'vendors-users',
|
||
name: 'Data Migration & CRUD',
|
||
description: 'Test vendor and user creation, listing, editing, deletion, and data migration scenarios.',
|
||
url: '/admin/test/vendors-users-migration',
|
||
icon: 'database',
|
||
color: 'orange',
|
||
testCount: 10,
|
||
features: [
|
||
'Vendor CRUD operations',
|
||
'User management & roles',
|
||
'Data migration validation',
|
||
'Form validation & error handling'
|
||
]
|
||
}
|
||
],
|
||
|
||
// Stats
|
||
stats: {
|
||
totalSuites: 2,
|
||
totalTests: 16,
|
||
coverage: 'Auth, CRUD',
|
||
avgDuration: '< 5 min'
|
||
},
|
||
|
||
// Loading state
|
||
loading: false,
|
||
|
||
// ✅ CRITICAL: Proper initialization with guard
|
||
async init() {
|
||
testingLog.info('=== TESTING HUB INITIALIZING ===');
|
||
|
||
// Prevent multiple initializations
|
||
if (window._testingHubInitialized) {
|
||
testingLog.warn('Testing hub already initialized, skipping...');
|
||
return;
|
||
}
|
||
window._testingHubInitialized = true;
|
||
|
||
// Calculate stats
|
||
this.calculateStats();
|
||
|
||
testingLog.info('=== TESTING HUB INITIALIZATION COMPLETE ===');
|
||
},
|
||
|
||
/**
|
||
* Calculate test statistics
|
||
*/
|
||
calculateStats() {
|
||
this.stats.totalSuites = this.testSuites.length;
|
||
this.stats.totalTests = this.testSuites.reduce((sum, suite) => sum + suite.testCount, 0);
|
||
testingLog.debug('Stats calculated:', this.stats);
|
||
},
|
||
|
||
/**
|
||
* Get color classes for test suite cards
|
||
*/
|
||
getColorClasses(color) {
|
||
const colorMap = {
|
||
blue: {
|
||
gradient: 'from-blue-500 to-blue-600',
|
||
button: 'bg-blue-600 hover:bg-blue-700'
|
||
},
|
||
orange: {
|
||
gradient: 'from-orange-500 to-orange-600',
|
||
button: 'bg-orange-600 hover:bg-orange-700'
|
||
},
|
||
green: {
|
||
gradient: 'from-green-500 to-green-600',
|
||
button: 'bg-green-600 hover:bg-green-700'
|
||
},
|
||
purple: {
|
||
gradient: 'from-purple-500 to-purple-600',
|
||
button: 'bg-purple-600 hover:bg-purple-700'
|
||
}
|
||
};
|
||
return colorMap[color] || colorMap.blue;
|
||
},
|
||
|
||
/**
|
||
* Navigate to test suite
|
||
*/
|
||
goToTest(url) {
|
||
testingLog.info('Navigating to test suite:', url);
|
||
window.location.href = url;
|
||
}
|
||
};
|
||
}
|
||
|
||
testingLog.info('Testing hub module loaded'); |