/** * SteelBase Test Suite * Console commands available: * - runTestSuite() - Run all tests * - testPersistence() - Test persistence system * - testBackup() - Test backup/restore * - testConfig() - Test admin config */ (function() { 'use strict'; const TestRunner = { results: [], log(msg, type = 'info') { const prefix = { info: 'ℹ️', success: '✅', error: '❌', warn: '⚠️' }[type] || 'ℹ️'; console.log(`${prefix} ${msg}`); }, async waitForModules(timeout = 5000) { const start = Date.now(); while (Date.now() - start < timeout) { if (window.adminConfigManager && window.backupManager) { return true; } await new Promise(r => setTimeout(r, 100)); } return false; }, async testPersistence() { this.log('Testando persistência...', 'info'); try { if (!await this.waitForModules()) { throw new Error('Módulos não carregados'); } const config = window.adminConfigManager.getConfig(); window.adminConfigManager.updateConfig('test.run', Date.now()); const updated = window.adminConfigManager.getConfig(); const passed = updated.test?.run > 0; this.log(passed ? 'Persistência OK' : 'Falha na persistência', passed ? 'success' : 'error'); return passed; } catch (e) { this.log(`Erro: ${e.message}`, 'error'); return false; } }, async testBackup() { this.log('Testando backup...', 'info'); try { const backup = await window.backupManager.createBackup('Teste automático'); const list = window.backupManager.getBackups(); const passed = list.some(b => b.id === backup.id); if (passed) { window.backupManager.removeBackup(backup.id); } this.log(passed ? 'Backup OK' : 'Falha no backup', passed ? 'success' : 'error'); return passed; } catch (e) { this.log(`Erro: ${e.message}`, 'error'); return false; } }, async testConfig() { this.log('Testando configuração...', 'info'); try { const cfg = window.adminConfigManager?.getConfig(); const passed = cfg && cfg.app?.name; this.log(passed ? 'Configuração OK' : 'Falha na configuração', passed ? 'success' : 'error'); return passed; } catch (e) { this.log(`Erro: ${e.message}`, 'error'); return false; } }, async runAllTests() { this.log('🧪 SteelBase Test Suite', 'info'); this.log('='.repeat(30), 'info'); const results = { persistence: await this.testPersistence(), backup: await this.testBackup(), config: await this.testConfig() }; const total = Object.values(results).filter(Boolean).length; const totalTests = Object.keys(results).length; this.log('='.repeat(30), 'info'); this.log(`Resultado: ${total}/${totalTests} testes passaram`, total === totalTests ? 'success' : 'warn'); return results; } }; window.runTestSuite = () => TestRunner.runAllTests(); window.testPersistence = () => TestRunner.testPersistence(); window.testBackup = () => TestRunner.testBackup(); window.testConfig = () => TestRunner.testConfig(); console.log('✅ Test Suite carregado. Use runTestSuite() no console para executar.'); })();