-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-and-debug.js
More file actions
402 lines (339 loc) · 13.7 KB
/
test-and-debug.js
File metadata and controls
402 lines (339 loc) · 13.7 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
/**
* Portfolio Website Testing and Debugging Script
* This script helps identify and fix issues in the portfolio website
*/
class PortfolioTester {
constructor() {
this.issues = [];
this.warnings = [];
this.successes = [];
this.testResults = {};
}
// Initialize testing
init() {
console.log('🔍 Portfolio Website Testing Started');
console.log('=====================================');
this.runAllTests();
this.generateReport();
}
// Run all tests
runAllTests() {
this.testHTMLStructure();
this.testCSSLoading();
this.testJavaScriptIntegration();
this.testResponsiveDesign();
this.testAccessibility();
this.testCrossBrowserCompatibility();
this.testPerformance();
this.testUserInteractions();
}
// Test HTML Structure
testHTMLStructure() {
console.log('\n📄 Testing HTML Structure...');
// Check essential elements
const essentialElements = [
'header', 'main', 'footer', 'nav',
'#home', '#about', '#projects', '#skills', '#contact'
];
essentialElements.forEach(selector => {
const element = document.querySelector(selector);
if (element) {
this.addSuccess(`✅ ${selector} found`);
} else {
this.addIssue(`❌ ${selector} missing`);
}
});
// Check meta tags
const metaTags = [
'viewport', 'description', 'title', 'charset'
];
metaTags.forEach(meta => {
const metaElement = document.querySelector(`meta[name="${meta}"], meta[charset]`);
if (metaElement) {
this.addSuccess(`✅ Meta tag: ${meta}`);
} else {
this.addIssue(`❌ Meta tag missing: ${meta}`);
}
});
// Check script loading
const scripts = document.querySelectorAll('script[src]');
scripts.forEach(script => {
this.addSuccess(`✅ Script loaded: ${script.src}`);
});
}
// Test CSS Loading
testCSSLoading() {
console.log('\n🎨 Testing CSS Loading...');
const stylesheets = document.querySelectorAll('link[rel="stylesheet"]');
stylesheets.forEach(sheet => {
this.addSuccess(`✅ Stylesheet loaded: ${sheet.href}`);
});
// Check if CSS variables are working
const root = document.documentElement;
const computedStyle = getComputedStyle(root);
const primaryColor = computedStyle.getPropertyValue('--primary');
if (primaryColor && primaryColor.trim() !== '') {
this.addSuccess('✅ CSS variables working');
} else {
this.addWarning('⚠️ CSS variables may not be loading properly');
}
}
// Test JavaScript Integration
testJavaScriptIntegration() {
console.log('\n⚡ Testing JavaScript Integration...');
// Check if main.js functions are available
const mobileMenuToggle = document.querySelector('.mobile-menu-toggle');
if (mobileMenuToggle) {
this.addSuccess('✅ Mobile menu toggle found');
} else {
this.addIssue('❌ Mobile menu toggle missing');
}
// Check if enhanced features are working
const projectCards = document.querySelectorAll('.project-card');
if (projectCards.length > 0) {
this.addSuccess(`✅ Found ${projectCards.length} project cards`);
} else {
this.addIssue('❌ No project cards found');
}
// Check form validation
const contactForm = document.getElementById('contact-form');
if (contactForm) {
this.addSuccess('✅ Contact form found');
} else {
this.addIssue('❌ Contact form missing');
}
// Test console logging
console.log('Testing console logging...');
this.addSuccess('✅ Console logging working');
}
// Test Responsive Design
testResponsiveDesign() {
console.log('\n📱 Testing Responsive Design...');
// Check viewport meta tag
const viewport = document.querySelector('meta[name="viewport"]');
if (viewport) {
this.addSuccess('✅ Viewport meta tag present');
} else {
this.addIssue('❌ Viewport meta tag missing');
}
// Check media queries (simulate different screen sizes)
const screenSizes = [
{ width: 1920, height: 1080, name: 'Desktop' },
{ width: 768, height: 1024, name: 'Tablet' },
{ width: 375, height: 667, name: 'Mobile' }
];
screenSizes.forEach(size => {
this.simulateScreenSize(size.width, size.height);
this.addSuccess(`✅ Responsive test for ${size.name} (${size.width}x${size.height})`);
});
// Reset to default
this.simulateScreenSize(1920, 1080);
}
// Test Accessibility
testAccessibility() {
console.log('\n♿ Testing Accessibility...');
// Check ARIA attributes
const elementsWithAria = document.querySelectorAll('[aria-label], [aria-labelledby], [aria-describedby]');
if (elementsWithAria.length > 0) {
this.addSuccess(`✅ Found ${elementsWithAria.length} elements with ARIA attributes`);
} else {
this.addWarning('⚠️ No ARIA attributes found');
}
// Check alt attributes on images
const images = document.querySelectorAll('img');
let imagesWithAlt = 0;
images.forEach(img => {
if (img.alt && img.alt.trim() !== '') {
imagesWithAlt++;
}
});
if (imagesWithAlt === images.length) {
this.addSuccess('✅ All images have alt attributes');
} else {
this.addIssue(`❌ ${images.length - imagesWithAlt} images missing alt attributes`);
}
// Check semantic HTML
const semanticElements = ['header', 'nav', 'main', 'section', 'article', 'footer'];
semanticElements.forEach(element => {
const elements = document.querySelectorAll(element);
if (elements.length > 0) {
this.addSuccess(`✅ Semantic element <${element}> used`);
}
});
}
// Test Cross Browser Compatibility
testCrossBrowserCompatibility() {
console.log('\n🌐 Testing Cross Browser Compatibility...');
// Check for vendor prefixes in CSS
const styleSheets = Array.from(document.styleSheets);
let hasVendorPrefixes = false;
try {
styleSheets.forEach(sheet => {
if (sheet.cssRules) {
Array.from(sheet.cssRules).forEach(rule => {
if (rule.cssText.includes('-webkit-') ||
rule.cssText.includes('-moz-') ||
rule.cssText.includes('-ms-')) {
hasVendorPrefixes = true;
}
});
}
});
} catch (e) {
// CORS error, skip this test
}
if (hasVendorPrefixes) {
this.addSuccess('✅ Vendor prefixes found for cross-browser support');
} else {
this.addWarning('⚠️ No vendor prefixes detected');
}
// Check for modern JavaScript features
const modernFeatures = [
'Promise' in window,
'fetch' in window,
'IntersectionObserver' in window,
'localStorage' in window
];
modernFeatures.forEach((feature, index) => {
const featureNames = ['Promise', 'fetch', 'IntersectionObserver', 'localStorage'];
if (feature) {
this.addSuccess(`✅ Modern feature supported: ${featureNames[index]}`);
} else {
this.addWarning(`⚠️ Modern feature not supported: ${featureNames[index]}`);
}
});
}
// Test Performance
testPerformance() {
console.log('\n⚡ Testing Performance...');
// Check image optimization
const images = document.querySelectorAll('img');
let optimizedImages = 0;
images.forEach(img => {
if (img.loading === 'lazy') {
optimizedImages++;
}
});
if (optimizedImages === images.length) {
this.addSuccess('✅ All images have lazy loading');
} else {
this.addWarning(`⚠️ ${images.length - optimizedImages} images missing lazy loading`);
}
// Check script loading
const scripts = document.querySelectorAll('script[src]');
let deferredScripts = 0;
scripts.forEach(script => {
if (script.defer || script.async) {
deferredScripts++;
}
});
if (deferredScripts === scripts.length) {
this.addSuccess('✅ All scripts are deferred or async');
} else {
this.addWarning(`⚠️ ${scripts.length - deferredScripts} scripts not deferred/async`);
}
}
// Test User Interactions
testUserInteractions() {
console.log('\n🖱️ Testing User Interactions...');
// Test mobile menu
const mobileMenuToggle = document.querySelector('.mobile-menu-toggle');
if (mobileMenuToggle) {
this.simulateClick(mobileMenuToggle);
this.addSuccess('✅ Mobile menu toggle clickable');
}
// Test smooth scrolling
const navLinks = document.querySelectorAll('a[href^="#"]');
if (navLinks.length > 0) {
this.addSuccess(`✅ Found ${navLinks.length} smooth scroll links`);
}
// Test form validation
const contactForm = document.getElementById('contact-form');
if (contactForm) {
const submitButton = contactForm.querySelector('button[type="submit"]');
if (submitButton) {
this.addSuccess('✅ Contact form submit button found');
}
}
// Test project filters
const filterButtons = document.querySelectorAll('.filter-btn');
if (filterButtons.length > 0) {
this.addSuccess(`✅ Found ${filterButtons.length} project filter buttons`);
}
// Test lightbox
const projectImages = document.querySelectorAll('.project-image img');
if (projectImages.length > 0) {
this.addSuccess(`✅ Found ${projectImages.length} project images for lightbox`);
}
}
// Utility methods
simulateScreenSize(width, height) {
// This is a simulation - in real testing, you'd use browser dev tools
window.innerWidth = width;
window.innerHeight = height;
window.dispatchEvent(new Event('resize'));
}
simulateClick(element) {
// Simulate a click event
const clickEvent = new MouseEvent('click', {
bubbles: true,
cancelable: true,
view: window
});
element.dispatchEvent(clickEvent);
}
addSuccess(message) {
this.successes.push(message);
this.testResults[message] = 'success';
}
addWarning(message) {
this.warnings.push(message);
this.testResults[message] = 'warning';
}
addIssue(message) {
this.issues.push(message);
this.testResults[message] = 'issue';
}
// Generate comprehensive report
generateReport() {
console.log('\n📊 TESTING REPORT');
console.log('================');
const totalTests = this.successes.length + this.warnings.length + this.issues.length;
console.log(`\n✅ Successes: ${this.successes.length}`);
this.successes.forEach(success => console.log(` ${success}`));
console.log(`\n⚠️ Warnings: ${this.warnings.length}`);
this.warnings.forEach(warning => console.log(` ${warning}`));
console.log(`\n❌ Issues: ${this.issues.length}`);
this.issues.forEach(issue => console.log(` ${issue}`));
console.log(`\n📈 Summary:`);
console.log(` Total Tests: ${totalTests}`);
console.log(` Success Rate: ${((this.successes.length / totalTests) * 100).toFixed(1)}%`);
if (this.issues.length === 0) {
console.log('\n🎉 All tests passed! Your portfolio website is ready for deployment.');
} else {
console.log('\n🔧 Issues found. Please review and fix the issues above.');
}
// Store results for external access
window.portfolioTestResults = {
successes: this.successes,
warnings: this.warnings,
issues: this.issues,
summary: {
total: totalTests,
successRate: ((this.successes.length / totalTests) * 100).toFixed(1)
}
};
}
}
// Auto-run tests when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
// Wait a bit for all scripts to load
setTimeout(() => {
const tester = new PortfolioTester();
tester.init();
}, 1000);
});
// Export for manual testing
if (typeof module !== 'undefined' && module.exports) {
module.exports = PortfolioTester;
}