File size: 6,288 Bytes
7270c96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
const { chromium } = require('@playwright/test');

async function testDashboard() {
  console.log('🧪 بدء اختبار لوحة التحكم...\n');
  
  const browser = await chromium.launch({ headless: true });
  const context = await browser.newContext();
  const page = await context.newPage();
  
  let testsPassed = 0;
  let testsFailed = 0;
  
  // Collect console errors
  const consoleErrors = [];
  page.on('console', msg => {
    if (msg.type() === 'error') {
      consoleErrors.push(msg.text());
    }
  });
  
  try {
    // Test 1: Dashboard loads
    console.log('📋 اختبار 1: تحميل لوحة التحكم...');
    await page.goto('file:///workspace/auto-guardian-docs/dashboard/index.html');
    await page.waitForLoadState('domcontentloaded');
    
    const title = await page.title();
    console.log(`   ✅ عنوان الصفحة: ${title}`);
    testsPassed++;
    
    // Test 2: Main elements exist
    console.log('\n📋 اختبار 2: التحقق من العناصر الرئيسية...');
    
    const dashboard = await page.locator('.dashboard').isVisible();
    const sidebar = await page.locator('.sidebar').isVisible();
    const header = await page.locator('.header').isVisible();
    const stats = await page.locator('.stats-grid').isVisible();
    
    if (dashboard && sidebar && header && stats) {
      console.log('   ✅ جميع العناصر الرئيسية موجودة');
      testsPassed++;
    } else {
      console.log('   ❌ بعض العناصر مفقودة');
      testsFailed++;
    }
    
    // Test 3: Stats cards
    console.log('\n📋 اختبار 3: بطاقات الإحصائيات...');
    const statCards = await page.locator('.stat-card').count();
    if (statCards === 4) {
      console.log(`   ✅ 4 بطاقات إحصائيات موجودة`);
      testsPassed++;
    } else {
      console.log(`   ❌ عدد البطاقات: ${statCards} (متوقع: 4)`);
      testsFailed++;
    }
    
    // Test 4: Charts
    console.log('\n📋 اختبار 4: الرسوم البيانية...');
    const areaChart = await page.locator('.area-chart').isVisible();
    const donutChart = await page.locator('.donut-chart').isVisible();
    const donutTotal = await page.locator('#donutTotal').textContent();
    
    if (areaChart && donutChart) {
      console.log(`   ✅ الرسوم البيانية ظاهرة (الإجمالي: ${donutTotal})`);
      testsPassed++;
    } else {
      console.log('   ❌ الرسوم البيانية غير ظاهرة');
      testsFailed++;
    }
    
    // Test 5: Navigation
    console.log('\n📋 اختبار 5: قائمة التنقل...');
    const navItems = await page.locator('.nav-item').count();
    console.log(`   ✅ ${navItems} عنصر في قائمة التنقل`);
    testsPassed++;
    
    // Test 6: Settings panel
    console.log('\n📋 اختبار 6: لوحة الإعدادات...');
    await page.click('[data-view="settings"]');
    await page.waitForTimeout(500);
    const settingsActive = await page.locator('#settingsPanel').getAttribute('class');
    
    if (settingsActive.includes('active')) {
      console.log('   ✅ لوحة الإعدادات تفتح بشكل صحيح');
      testsPassed++;
    } else {
      console.log('   ❌ لوحة الإعدادات لا تفتح');
      testsFailed++;
    }
    
    // Test 7: Issues list
    console.log('\n📋 اختبار 7: قائمة المشاكل...');
    const issuesList = await page.locator('.issues-list').isVisible();
    const issueItems = await page.locator('.issue-item').count();
    
    if (issuesList && issueItems > 0) {
      console.log(`   ✅ قائمة المشاكل ظاهرة (${issueItems} مشكلة)`);
      testsPassed++;
    } else {
      console.log('   ❌ قائمة المشاكل غير ظاهرة');
      testsFailed++;
    }
    
    // Test 8: Repositories list
    console.log('\n📋 اختبار 8: قائمة المستودعات...');
    const reposList = await page.locator('.repos-list').isVisible();
    const repoItems = await page.locator('.repo-item').count();
    
    if (reposList && repoItems > 0) {
      console.log(`   ✅ قائمة المستودعات ظاهرة (${repoItems} مستودع)`);
      testsPassed++;
    } else {
      console.log('   ❌ قائمة المستودعات غير ظاهرة');
      testsFailed++;
    }
    
    // Test 9: Search functionality
    console.log('\n📋 اختبار 9: وظيفة البحث...');
    await page.fill('#searchInput', 'auth');
    await page.waitForTimeout(300);
    const searchResults = await page.locator('.search-results').getAttribute('class');
    
    if (searchResults.includes('active')) {
      console.log('   ✅ البحث يعمل بشكل صحيح');
      testsPassed++;
    } else {
      console.log('   ❌ البحث لا يعمل');
      testsFailed++;
    }
    
    // Test 10: Toast notifications
    console.log('\n📋 اختبار 10: إشعارات Toast...');
    const toastContainer = await page.locator('.toast-container').isVisible();
    if (toastContainer) {
      console.log('   ✅ حاوية الإشعارات موجودة');
      testsPassed++;
    } else {
      console.log('   ❌ حاوية الإشعارات غير موجودة');
      testsFailed++;
    }
    
  } catch (error) {
    console.error('\n❌ حدث خطأ أثناء الاختبار:', error.message);
    testsFailed++;
  } finally {
    await browser.close();
  }
  
  // Print results
  console.log('\n' + '='.repeat(50));
  console.log('📊 نتائج الاختبار:');
  console.log('='.repeat(50));
  console.log(`✅ اختبارات ناجحة: ${testsPassed}`);
  console.log(`❌ اختبارات فاشلة: ${testsFailed}`);
  console.log(`📝 إجمالي الاختبارات: ${testsPassed + testsFailed}`);
  
  if (consoleErrors.length > 0) {
    console.log('\n⚠️ أخطاء في Console:');
    consoleErrors.forEach((err, i) => console.log(`   ${i+1}. ${err}`));
  } else {
    console.log('\n✅ لا توجد أخطاء في Console');
  }
  
  console.log('='.repeat(50));
  
  return testsFailed === 0;
}

testDashboard().then(success => {
  process.exit(success ? 0 : 1);
});