# Frontend Testing & Validation Guide **Date:** December 18, 2025 **Purpose:** Test all frontend improvements --- ## ๐Ÿงช Quick Test Commands ### 1. Test Server Health ```bash curl http://localhost:5000/health | jq ``` ### 2. Test Responsive Layout (Using Browser DevTools) ```javascript // Open DevTools (F12) โ†’ Console โ†’ Run this: // Test Mobile View (375px width) window.resizeTo(375, 667); // Test Tablet View (768px width) window.resizeTo(768, 1024); // Test Desktop View (1920px width) window.resizeTo(1920, 1080); ``` ### 3. Test API Integration ```bash # Test admin session (should require authentication) curl -s http://localhost:5000/api/admin/session -H "Cookie: connect.sid=YOUR_SESSION_ID" | jq # Test public API curl -s http://localhost:5000/api/products | jq ``` ### 4. Test Toast Notifications ```javascript // Open browser console on any page with utils.js loaded: // Test success toast showToast('Operation successful!', 'success'); // Test error toast showToast('Something went wrong!', 'error'); // Test warning toast showToast('Please be careful!', 'warning'); // Test info toast showToast('Just so you know...', 'info'); ``` ### 5. Test Storage Utilities ```javascript // Test storage in console: // Set data storage.set('testUser', { name: 'John', age: 30 }); // Get data const user = storage.get('testUser'); console.log(user); // { name: 'John', age: 30 } // Remove data storage.remove('testUser'); // Clear all storage.clear(); ``` ### 6. Test API Request Helper ```javascript // Test API request with error handling: async function testAPI() { try { const data = await apiRequest('/api/products'); console.log('Success:', data); } catch (error) { console.error('Error:', error.message); } } testAPI(); ``` --- ## ๐Ÿ“ฑ Responsive Testing Checklist ### Mobile (320px - 768px) - [ ] Sidebar collapses and shows hamburger menu button - [ ] Menu toggle button is at least 44x44px (touch-friendly) - [ ] Sidebar slides in from left when opened - [ ] Backdrop appears behind sidebar - [ ] Clicking outside closes sidebar - [ ] Cards stack vertically (1 column) - [ ] Forms are full width - [ ] Tables scroll horizontally if needed - [ ] Toast notifications fit screen width - [ ] Images scale properly - [ ] Text is readable (not too small) - [ ] No horizontal scrolling on pages ### Tablet (769px - 1024px) - [ ] Sidebar visible at 220px width - [ ] Cards show in 2 columns - [ ] Forms have proper spacing - [ ] Navigation is accessible - [ ] Touch targets are adequate ### Desktop (โ‰ฅ1025px) - [ ] Sidebar visible at 250px width - [ ] Multi-column card layouts work - [ ] Hover states work on interactive elements - [ ] All features accessible with mouse --- ## โ™ฟ Accessibility Testing ### Keyboard Navigation Test these keyboard shortcuts: ``` Tab โ†’ Move to next focusable element Shift+Tab โ†’ Move to previous focusable element Enter/Space โ†’ Activate buttons/links Escape โ†’ Close modals/dropdowns Arrow Keys โ†’ Navigate within components ``` #### Checklist - [ ] All interactive elements are keyboard accessible - [ ] Focus indicator is visible (2px outline) - [ ] Focus order is logical - [ ] Modals trap focus properly - [ ] Can close modals with Escape key - [ ] Skip link appears on Tab key press ### Screen Reader Testing #### NVDA (Windows - Free) ```bash # Download from: https://www.nvaccess.org/download/ # Install and press Ctrl+Alt+N to start ``` #### Test Points - [ ] Skip link announces "Skip to main content" - [ ] Navigation landmarks are announced - [ ] Buttons announce their purpose - [ ] Form inputs have associated labels - [ ] Images have descriptive alt text - [ ] ARIA live regions announce updates - [ ] Toast notifications are announced - [ ] Loading states are communicated ### Color Contrast Use Chrome DevTools Lighthouse: 1. Open DevTools (F12) 2. Go to "Lighthouse" tab 3. Select "Accessibility" 4. Click "Analyze page load" 5. Check for contrast issues Target: **95+ Accessibility Score** --- ## ๐ŸŽจ Visual Testing ### Browser Compatibility #### Chrome/Edge (Chromium) ```bash # Open in Chrome google-chrome http://localhost:5000/admin/dashboard-example.html # Check Console (F12) for errors # Should show: 0 errors, 0 warnings ``` #### Firefox ```bash firefox http://localhost:5000/admin/dashboard-example.html ``` #### Safari (Mac only) ```bash open -a Safari http://localhost:5000/admin/dashboard-example.html ``` ### Mobile Browsers #### iOS Safari (Using iOS Simulator) ```bash # If you have Xcode installed: xcrun simctl boot "iPhone 14 Pro" open -a Simulator # Then open Safari and navigate to http://your-local-ip:5000 ``` #### Chrome Android (Using Chrome DevTools) 1. Connect Android device via USB 2. Enable USB debugging on Android 3. Open Chrome DevTools โ†’ Remote devices 4. Inspect your device --- ## โšก Performance Testing ### Lighthouse Performance Check ```javascript // Run in Chrome DevTools โ†’ Lighthouse // Target Scores: // - Performance: 90+ // - Accessibility: 95+ // - Best Practices: 95+ // - SEO: 90+ ``` ### Network Throttling Test ```javascript // Chrome DevTools โ†’ Network tab // Select: "Slow 3G" // Reload page and test: // - Page loads in < 10 seconds // - Loading states are visible // - Images load progressively ``` ### Check Bundle Sizes ```bash # Check JavaScript file sizes ls -lh website/assets/js/*.js ls -lh website/admin/js/*.js # Check CSS file sizes ls -lh website/assets/css/*.css ls -lh website/admin/css/*.css # Target: < 100KB per file (uncompressed) ``` --- ## ๐Ÿ› Error Testing ### Test Error Handling #### 1. Network Error ```javascript // Disconnect from internet, then: await apiRequest('/api/products'); // Should show error toast ``` #### 2. 404 Error ```javascript await apiRequest('/api/nonexistent'); // Should handle gracefully ``` #### 3. Authentication Error ```javascript // Clear cookies, then: await apiRequest('/api/admin/products'); // Should redirect to login ``` #### 4. Storage Quota Error ```javascript // Fill localStorage to test quota handling: try { for (let i = 0; i < 10000; i++) { storage.set(`test${i}`, new Array(10000).fill('x').join('')); } } catch (e) { console.log('Storage quota handled correctly'); } storage.clear(); // Clean up ``` --- ## โœ… Acceptance Criteria All tests must pass: ### Responsive Layout - โœ… Works on 320px to 2560px+ screens - โœ… No horizontal scrolling - โœ… Touch targets โ‰ฅ 44x44px - โœ… Text readable at all sizes ### Console Errors - โœ… Zero console errors on page load - โœ… Zero console warnings (except from external libraries) - โœ… No 404s for assets ### State Management - โœ… LocalStorage works across page refreshes - โœ… Data persists correctly - โœ… Errors handled gracefully ### API Integration - โœ… All endpoints return expected data - โœ… Errors display user-friendly messages - โœ… Loading states shown during requests - โœ… Network errors handled ### Accessibility - โœ… Lighthouse score โ‰ฅ 95 - โœ… All images have alt text - โœ… All buttons have accessible names - โœ… Keyboard navigation works - โœ… Screen reader friendly - โœ… Color contrast passes WCAG AA ### Performance - โœ… Lighthouse performance โ‰ฅ 90 - โœ… Page loads in < 3s on regular connection - โœ… Images lazy load - โœ… No unnecessary re-renders --- ## ๐ŸŽฏ Real-World Test Scenarios ### Scenario 1: Admin Login Flow 1. Navigate to `/admin/login.html` 2. Enter credentials 3. Verify redirect to dashboard 4. Check mobile menu works 5. Test logout functionality ### Scenario 2: Product Management 1. Go to products page 2. Click "Add Product" 3. Fill form with validation 4. Submit and verify toast notification 5. See product in list 6. Edit product 7. Delete product with confirmation ### Scenario 3: Mobile Shopping Experience 1. Open site on mobile (< 768px) 2. Browse products 3. Add items to cart 4. Open cart dropdown 5. Adjust quantities 6. Remove items 7. Add to wishlist 8. Verify storage persists ### Scenario 4: Accessibility Test 1. Use only keyboard (no mouse) 2. Tab through entire page 3. Verify focus visible 4. Use screen reader 5. Check all announcements 6. Verify image descriptions --- ## ๐Ÿ“Š Expected Results After all tests pass, you should see: ``` โœ… Responsive: All breakpoints working โœ… Console: 0 errors, 0 warnings โœ… State: Data persists correctly โœ… API: All requests successful โœ… A11y: Lighthouse score 95+ โœ… Performance: Load time < 3s โœ… Mobile: Touch-friendly, no issues โœ… Desktop: Hover states, proper layout โœ… Keyboard: Full navigation possible โœ… Screen Reader: All content accessible ``` --- ## ๐Ÿ†˜ Troubleshooting ### Issue: Mobile menu doesn't appear **Solution:** Include utils.js and utilities.css, ensure auth.js is loaded ### Issue: Toast notifications not showing **Solution:** Include utilities.css for toast styles ### Issue: Storage errors in console **Solution:** Use storage utility instead of direct localStorage calls ### Issue: API requests fail **Solution:** Check server is running on port 5000, verify CORS settings ### Issue: Focus styles not visible **Solution:** Ensure utilities.css is included and loads after other styles --- **๐ŸŽ‰ Happy Testing! ๐ŸŽ‰**