File size: 14,222 Bytes
25f22bf |
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 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 |
/**
* Responsive Design Test Suite
* This file contains tests to validate responsive design implementation
*/
// Test configuration
const testConfig = {
breakpoints: {
xs: 0,
sm: 640,
md: 768,
lg: 1024,
xl: 1280,
'2xl': 1536,
'3xl': 1920
},
testScenarios: [
'mobile-navigation',
'responsive-layouts',
'touch-interactions',
'accessibility',
'performance',
'typography-scaling',
'grid-systems',
'spacing-scaling'
]
};
// Test results storage
const testResults = {
passed: 0,
failed: 0,
total: 0,
details: []
};
/**
* Test Mobile Navigation
*/
function testMobileNavigation() {
console.log('Testing Mobile Navigation...');
const tests = [
{
name: 'Hamburger Menu Button',
check: () => {
const button = document.querySelector('.mobile-menu-button');
return button && button.getAttribute('aria-label');
}
},
{
name: 'Mobile Menu Overlay',
check: () => {
const overlay = document.querySelector('.mobile-menu-overlay');
return overlay && overlay.getAttribute('aria-label');
}
},
{
name: 'Skip Link',
check: () => {
const skipLink = document.querySelector('.skip-link');
return skipLink && skipLink.getAttribute('href') === '#main-content';
}
},
{
name: 'Touch Target Size',
check: () => {
const buttons = document.querySelectorAll('.mobile-menu-button');
return Array.from(buttons).every(btn =>
btn.offsetWidth >= 44 && btn.offsetHeight >= 44
);
}
}
];
return runTests(tests, 'Mobile Navigation');
}
/**
* Test Responsive Layouts
*/
function testResponsiveLayouts() {
console.log('Testing Responsive Layouts...');
const tests = [
{
name: 'Container Max Width',
check: () => {
const containers = document.querySelectorAll('.container');
return Array.from(containers).every(container => {
const style = window.getComputedStyle(container);
return style.maxWidth && style.maxWidth !== 'none';
});
}
},
{
name: 'Grid System',
check: () => {
const grids = document.querySelectorAll('.grid');
return Array.from(grids).every(grid => {
const style = window.getComputedStyle(grid);
return style.display === 'grid' || style.display === 'flex';
});
}
},
{
name: 'Responsive Spacing',
check: () => {
const elements = document.querySelectorAll('[class*="p-"], [class*="m-"]');
return elements.length > 0;
}
},
{
name: 'Flexbox Layout',
check: () => {
const flexElements = document.querySelectorAll('.flex');
return Array.from(flexElements).every(el => {
const style = window.getComputedStyle(el);
return style.display === 'flex';
});
}
}
];
return runTests(tests, 'Responsive Layouts');
}
/**
* Test Touch Interactions
*/
function testTouchInteractions() {
console.log('Testing Touch Interactions...');
const tests = [
{
name: 'Touch Optimization',
check: () => {
const touchElements = document.querySelectorAll('.touch-optimized');
return touchElements.length > 0;
}
},
{
name: 'Tap Highlight',
check: () => {
const buttons = document.querySelectorAll('button');
return Array.from(buttons).every(btn => {
const style = window.getComputedStyle(btn);
return style.getPropertyValue('-webkit-tap-highlight-color') === 'transparent';
});
}
},
{
name: 'Touch Action',
check: () => {
const interactiveElements = document.querySelectorAll('button, a, [role="button"]');
return Array.from(interactiveElements).every(el => {
const style = window.getComputedStyle(el);
return style.getPropertyValue('touch-action') === 'manipulation';
});
}
},
{
name: 'Mobile Acceleration',
check: () => {
const accelerated = document.querySelectorAll('.mobile-accelerated');
return accelerated.length > 0;
}
}
];
return runTests(tests, 'Touch Interactions');
}
/**
* Test Accessibility
*/
function testAccessibility() {
console.log('Testing Accessibility...');
const tests = [
{
name: 'ARIA Labels',
check: () => {
const elementsWithAria = document.querySelectorAll('[aria-label], [aria-labelledby], [aria-describedby]');
return elementsWithAria.length > 0;
}
},
{
name: 'Focus Management',
check: () => {
const focusableElements = document.querySelectorAll('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');
return focusableElements.length > 0;
}
},
{
name: 'Skip Link',
check: () => {
const skipLink = document.querySelector('.skip-link');
return skipLink && skipLink.getAttribute('href') === '#main-content';
}
},
{
name: 'High Contrast Support',
check: () => {
const highContrastElements = document.querySelectorAll('[style*="contrast"]');
return highContrastElements.length > 0;
}
},
{
name: 'Reduced Motion',
check: () => {
const reducedMotionElements = document.querySelectorAll('.mobile-reduced-motion');
return reducedMotionElements.length > 0;
}
}
];
return runTests(tests, 'Accessibility');
}
/**
* Test Performance
*/
function testPerformance() {
console.log('Testing Performance...');
const tests = [
{
name: 'Lazy Loading',
check: () => {
const lazyElements = document.querySelectorAll('[loading="lazy"], .lazy-load');
return lazyElements.length > 0;
}
},
{
name: 'Hardware Acceleration',
check: () => {
const accelerated = document.querySelectorAll('.mobile-accelerated');
return accelerated.length > 0;
}
},
{
name: 'Render Optimization',
check: () => {
const optimized = document.querySelectorAll('.mobile-render-optimized');
return optimized.length > 0;
}
},
{
name: 'Animation Optimization',
check: () => {
const optimized = document.querySelectorAll('.mobile-optimized-animation');
return optimized.length > 0;
}
}
];
return runTests(tests, 'Performance');
}
/**
* Test Typography Scaling
*/
function testTypographyScaling() {
console.log('Testing Typography Scaling...');
const tests = [
{
name: 'Fluid Typography',
check: () => {
const fluidElements = document.querySelectorAll('.text-fluid, .text-fluid-lg, .text-fluid-xl');
return fluidElements.length > 0;
}
},
{
name: 'Responsive Font Sizes',
check: () => {
const responsiveElements = document.querySelectorAll('[class*="text-responsive"]');
return responsiveElements.length > 0;
}
},
{
name: 'Line Height Scaling',
check: () => {
const elementsWithLineHeight = document.querySelectorAll('[class*="leading-responsive"]');
return elementsWithLineHeight.length > 0;
}
},
{
name: 'Mobile Readability',
check: () => {
const readableElements = document.querySelectorAll('.mobile-readable, .mobile-readable-large');
return readableElements.length > 0;
}
}
];
return runTests(tests, 'Typography Scaling');
}
/**
* Test Grid Systems
*/
function testGridSystems() {
console.log('Testing Grid Systems...');
const tests = [
{
name: 'Responsive Grid',
check: () => {
const gridElements = document.querySelectorAll('.grid');
return Array.from(gridElements).every(grid => {
const style = window.getComputedStyle(grid);
return style.display === 'grid' || style.display === 'flex';
});
}
},
{
name: 'Grid Breakpoints',
check: () => {
const gridElements = document.querySelectorAll('[class*="grid-cols-"]');
return gridElements.length > 0;
}
},
{
name: 'Grid Gap',
check: () => {
const gridElements = document.querySelectorAll('[class*="gap-"]');
return gridElements.length > 0;
}
},
{
name: 'Grid Alignment',
check: () => {
const gridElements = document.querySelectorAll('[class*="justify-"], [class*="items-"]');
return gridElements.length > 0;
}
}
];
return runTests(tests, 'Grid Systems');
}
/**
* Test Spacing Scaling
*/
function testSpacingScaling() {
console.log('Testing Spacing Scaling...');
const tests = [
{
name: 'Responsive Padding',
check: () => {
const paddingElements = document.querySelectorAll('[class*="p-"]');
return paddingElements.length > 0;
}
},
{
name: 'Responsive Margin',
check: () => {
const marginElements = document.querySelectorAll('[class*="m-"]');
return marginElements.length > 0;
}
},
{
name: 'Spacing Breakpoints',
check: () => {
const responsiveElements = document.querySelectorAll('[class*="sm:"], [class*="md:"], [class*="lg:"]');
return responsiveElements.length > 0;
}
},
{
name: 'Container Padding',
check: () => {
const containers = document.querySelectorAll('.container');
return Array.from(containers).every(container => {
const style = window.getComputedStyle(container);
return style.paddingLeft && style.paddingRight;
});
}
}
];
return runTests(tests, 'Spacing Scaling');
}
/**
* Run individual tests
*/
function runTests(tests, category) {
const categoryResults = {
category,
passed: 0,
failed: 0,
details: []
};
tests.forEach(test => {
testResults.total++;
categoryResults.total = testResults.total;
try {
const result = test.check();
if (result) {
testResults.passed++;
categoryResults.passed++;
categoryResults.details.push({ name: test.name, status: 'PASSED' });
} else {
testResults.failed++;
categoryResults.failed++;
categoryResults.details.push({ name: test.name, status: 'FAILED' });
}
} catch (error) {
testResults.failed++;
categoryResults.failed++;
categoryResults.details.push({ name: test.name, status: 'ERROR', error: error.message });
}
});
return categoryResults;
}
/**
* Run all tests
*/
function runAllTests() {
console.log('π Starting Responsive Design Tests...\n');
const results = [
testMobileNavigation(),
testResponsiveLayouts(),
testTouchInteractions(),
testAccessibility(),
testPerformance(),
testTypographyScaling(),
testGridSystems(),
testSpacingScaling()
];
// Generate report
generateReport(results);
}
/**
* Generate test report
*/
function generateReport(results) {
console.log('\nπ Responsive Design Test Report');
console.log('='.repeat(50));
results.forEach(result => {
console.log(`\n${result.category.toUpperCase()}`);
console.log('-'.repeat(30));
console.log(`Passed: ${result.passed}`);
console.log(`Failed: ${result.failed}`);
console.log(`Total: ${result.passed + result.failed}`);
if (result.details.length > 0) {
console.log('\nDetails:');
result.details.forEach(detail => {
const status = detail.status === 'PASSED' ? 'β
' : detail.status === 'FAILED' ? 'β' : 'β οΈ';
console.log(` ${status} ${detail.name}`);
if (detail.error) {
console.log(` Error: ${detail.error}`);
}
});
}
});
console.log('\nπ― Overall Results');
console.log('='.repeat(50));
console.log(`Total Tests: ${testResults.total}`);
console.log(`Passed: ${testResults.passed}`);
console.log(`Failed: ${testResults.failed}`);
console.log(`Success Rate: ${((testResults.passed / testResults.total) * 100).toFixed(2)}%`);
if (testResults.failed === 0) {
console.log('\nπ All tests passed! Responsive design implementation is complete.');
} else {
console.log('\nβ οΈ Some tests failed. Please review the details above.');
}
}
/**
* Test specific breakpoint
*/
function testBreakpoint(breakpoint) {
const width = testConfig.breakpoints[breakpoint];
if (!width) {
console.error(`Unknown breakpoint: ${breakpoint}`);
return;
}
// Set viewport width
window.innerWidth = width;
window.dispatchEvent(new Event('resize'));
console.log(`\nπ± Testing ${breakpoint.toUpperCase()} breakpoint (${width}px)`);
// Run tests for this breakpoint
const results = [
testResponsiveLayouts(),
testTypographyScaling(),
testSpacingScaling()
];
return results;
}
/**
* Initialize responsive design testing
*/
function initResponsiveTesting() {
console.log('π§ Responsive Design Test Suite Initialized');
console.log('Available functions:');
console.log(' - runAllTests()');
console.log(' - testBreakpoint(breakpoint)');
console.log(' - testMobileNavigation()');
console.log(' - testResponsiveLayouts()');
console.log(' - testTouchInteractions()');
console.log(' - testAccessibility()');
console.log(' - testPerformance()');
console.log(' - testTypographyScaling()');
console.log(' - testGridSystems()');
console.log(' - testSpacingScaling()');
}
// Initialize testing
initResponsiveTesting();
// Export functions for external use
window.responsiveTests = {
runAllTests,
testBreakpoint,
testMobileNavigation,
testResponsiveLayouts,
testTouchInteractions,
testAccessibility,
testPerformance,
testTypographyScaling,
testGridSystems,
testSpacingScaling
};
export default {
runAllTests,
testBreakpoint,
testMobileNavigation,
testResponsiveLayouts,
testTouchInteractions,
testAccessibility,
testPerformance,
testTypographyScaling,
testGridSystems,
testSpacingScaling
}; |