// src/app/dev-tools.ts /** * Outils de développement pour DTFlux Titrage Client * À utiliser uniquement en mode développement */ import { TitleSheet, createEmptyTitleSheet } from './models/title-sheet.model'; export class DevTools { /** * Génère des données de test pour l'application */ static generateSampleTitleSheets(): TitleSheet[] { const sampleData = [ { FirstName: 'Jean-Michel', LastName: 'Dubois', Function1: 'Directeur Général', Function2: 'Marketing & Communication' }, { FirstName: 'Marie-Claire', LastName: 'Martin', Function1: 'Chef de Projet Senior', Function2: 'Innovation & Développement' }, { FirstName: 'Pierre-Alexandre', LastName: 'Bernard', Function1: 'Développeur Full Stack', Function2: 'Team Lead Frontend' }, { FirstName: 'Sophie', LastName: 'Laurent-Moreau', Function1: 'Designer UX/UI', Function2: 'Responsable Créative' }, { FirstName: 'Lucas', LastName: 'Moreau', Function1: 'Directeur Technique', Function2: 'Architecture & DevOps' }, { FirstName: 'Amélie', LastName: 'Rousseau', Function1: 'Product Owner', Function2: 'Stratégie Produit' }, { FirstName: 'Thomas', LastName: 'Lefevre', Function1: 'Data Scientist', Function2: 'Intelligence Artificielle' }, { FirstName: 'Camille', LastName: 'Durand', Function1: 'Responsable QA', Function2: 'Test Automation' }, { FirstName: 'Julien', LastName: 'Petit', Function1: 'Développeur Backend', Function2: 'Microservices & API' }, { FirstName: 'Élise', LastName: 'Garnier', Function1: 'Chef de Projet Digital', Function2: 'Transformation Numérique' }, { FirstName: 'Nicolas', LastName: 'Fabre', Function1: 'Architecte Solution', Function2: 'Cloud & Infrastructure' }, { FirstName: 'Laure', LastName: 'Morel', Function1: 'Business Analyst', Function2: 'Optimisation Processus' } ]; return sampleData.map(data => { const titleSheet = createEmptyTitleSheet(); const now = new Date(); const createdDate = new Date(now.getTime() - Math.random() * 30 * 24 * 60 * 60 * 1000); const modifiedDate = new Date(now.getTime() - Math.random() * 7 * 24 * 60 * 60 * 1000); return { ...titleSheet, ...data, // Décaler les dates de création pour simuler un historique CreatedAt: createdDate, LastModified: modifiedDate }; }); } /** * Génère des données de test avec des cas limites */ static generateEdgeCaseTitleSheets(): TitleSheet[] { const edgeCases = [ { FirstName: '', LastName: '', Function1: '', Function2: '' }, { FirstName: 'Jean-Baptiste-Alexandre-Emmanuel', LastName: 'De La Rochefoucauld-Montmorency', Function1: 'Directeur Général Adjoint en charge du Développement Commercial et des Relations Internationales', Function2: 'Responsable de la Stratégie d\'Expansion Européenne et des Partenariats Stratégiques' }, { FirstName: 'José-María', LastName: 'García-López', Function1: 'Spécialiste Intégration Systèmes', Function2: '' }, { FirstName: 'X', LastName: 'Y', Function1: 'A', Function2: 'B' }, { FirstName: 'Test avec des caractères spéciaux: éèàùç', LastName: 'ñóëüï@#$%&*', Function1: 'Fonction avec émojis 🚀 ✨ 💻', Function2: 'Unicode: 中文 русский العربية' } ]; return edgeCases.map(data => { const titleSheet = createEmptyTitleSheet(); const now = new Date(); return { ...titleSheet, ...data, CreatedAt: now, LastModified: now }; }); } /** * Simule une séquence de tests automatisés */ static async runAutomatedTest(titleSheetsService: any): Promise { console.log('🧪 Démarrage des tests automatisés...'); // Test 1: Ajout de données const sampleSheets = this.generateSampleTitleSheets(); console.log('📝 Ajout de', sampleSheets.length, 'fiches de test'); sampleSheets.forEach(sheet => titleSheetsService.saveTitleSheet(sheet)); await this.delay(1000); // Test 2: Modification d'une fiche const sheets = titleSheetsService.getAllTitleSheets(); if (sheets.length > 0) { const firstSheet = { ...sheets[0] }; firstSheet.Function1 = 'MODIFIÉ PAR TEST AUTOMATIQUE'; titleSheetsService.saveTitleSheet(firstSheet); console.log('✏️ Modification d\'une fiche'); } await this.delay(1000); // Test 3: Suppression d'une fiche if (sheets.length > 1) { titleSheetsService.deleteTitleSheet(sheets[1].Id); console.log('🗑️ Suppression d\'une fiche'); } await this.delay(1000); console.log('✅ Tests automatisés terminés'); } /** * Vérifie la performance de l'application avec beaucoup de données */ static generateLargeDataset(count: number = 1000): TitleSheet[] { console.log('📊 Génération de', count, 'fiches pour test de performance'); const titles = ['Manager', 'Developer', 'Designer', 'Analyst', 'Consultant', 'Specialist', 'Coordinator', 'Assistant']; const departments = ['IT', 'Marketing', 'Sales', 'HR', 'Finance', 'Operations', 'R&D', 'Support']; const firstNames = ['Jean', 'Marie', 'Pierre', 'Sophie', 'Lucas', 'Amélie', 'Thomas', 'Camille']; const lastNames = ['Martin', 'Bernard', 'Dubois', 'Laurent', 'Moreau', 'Lefevre', 'Durand', 'Rousseau']; return Array.from({ length: count }, (_, index) => { const titleSheet = createEmptyTitleSheet(); const now = new Date(); const createdDate = new Date(now.getTime() - Math.random() * 365 * 24 * 60 * 60 * 1000); const modifiedDate = new Date(now.getTime() - Math.random() * 30 * 24 * 60 * 60 * 1000); return { ...titleSheet, FirstName: firstNames[index % firstNames.length] + (index > firstNames.length ? ` ${Math.floor(index / firstNames.length)}` : ''), LastName: lastNames[index % lastNames.length], Function1: `${titles[index % titles.length]} ${departments[index % departments.length]}`, Function2: index % 3 === 0 ? `Senior ${titles[(index + 1) % titles.length]}` : '', CreatedAt: createdDate, LastModified: modifiedDate }; }); } /** * Nettoie toutes les données de test */ static clearAllTestData(titleSheetsService: any): void { const sheets = titleSheetsService.getAllTitleSheets(); sheets.forEach((sheet: TitleSheet) => { titleSheetsService.deleteTitleSheet(sheet.Id); }); console.log('🧹 Toutes les données de test ont été supprimées'); } /** * Utilitaire pour ajouter des délais dans les tests */ private static delay(ms: number): Promise { return new Promise(resolve => setTimeout(resolve, ms)); } /** * Affiche les statistiques de l'application */ static displayStats(titleSheetsService: any): void { const sheets = titleSheetsService.getAllTitleSheets(); const totalChars = sheets.reduce((sum: number, sheet: TitleSheet) => sum + sheet.FirstName.length + sheet.LastName.length + sheet.Function1.length + sheet.Function2.length, 0); const emptyFields = sheets.reduce((sum: number, sheet: TitleSheet) => { let empty = 0; if (!sheet.FirstName) empty++; if (!sheet.LastName) empty++; if (!sheet.Function1) empty++; if (!sheet.Function2) empty++; return sum + empty; }, 0); console.table({ 'Total fiches': sheets.length, 'Caractères totaux': totalChars, 'Champs vides': emptyFields, 'Moyenne caractères/fiche': Math.round(totalChars / (sheets.length || 1)), 'Complétude moyenne': Math.round(((sheets.length * 4 - emptyFields) / (sheets.length * 4 || 1)) * 100) + '%' }); } } // Exposer les outils de développement dans la console du navigateur if (typeof window !== 'undefined' && !!(window as any)['ng']) { (window as any)['DTFluxDevTools'] = DevTools; console.log('🛠️ DTFlux Dev Tools disponibles via window.DTFluxDevTools'); }