# ZXing Scanner Testing Guide

## 🧪 Complete Testing Protocol

This guide helps you thoroughly test the new ZXing WebAssembly barcode/QR scanner.

---

## 📋 Pre-Testing Checklist

Before starting tests, ensure:
- [ ] Server is running (WAMP/XAMPP started)
- [ ] Browser is updated (Chrome 57+, Firefox 52+, Safari 11+)
- [ ] HTTPS or localhost (required for camera access)
- [ ] Camera is working and not in use by other apps
- [ ] Test barcodes/QR codes are ready

---

## 🖥️ Desktop Testing

### Test 1: Basic Scanner Open
```
Steps:
1. Open Sales POS (index.php)
2. Click camera button 📷 next to product code
3. Browser should ask for camera permission
4. Allow camera access
5. Scanner modal should open with live video

Expected:
✓ Modal opens smoothly
✓ Camera permission requested
✓ Video feed shows in modal
✓ Scanning frame visible
✓ Status shows "Searching for barcode..."

Pass: □  Fail: □  Notes: _______________
```

### Test 2: Keyboard Shortcut
```
Steps:
1. On Sales POS page
2. Press Ctrl + K (Windows/Linux) or Cmd + K (Mac)
3. Scanner should open

Expected:
✓ Scanner opens without clicking button
✓ Same behavior as camera button

Pass: □  Fail: □  Notes: _______________
```

### Test 3: EAN-13 Barcode Detection
```
Steps:
1. Open scanner
2. Hold EAN-13 barcode (e.g., product from store)
3. Position within frame
4. Hold steady

Expected:
✓ Code detected within 1-3 seconds
✓ Green checkmark appears
✓ Success beep plays
✓ Scanner shows code number
✓ Scanner closes after 1 second
✓ Product code populated in input field

Pass: □  Fail: □  Code Scanned: _______________
```

### Test 4: QR Code Detection
```
Steps:
1. Open scanner
2. Display QR code (phone screen or printed)
3. Position within frame

Expected:
✓ QR code detected quickly
✓ Success feedback shown
✓ Data extracted correctly
✓ Scanner closes automatically

Pass: □  Fail: □  Data: _______________
```

### Test 5: Code 128 Detection
```
Steps:
1. Open scanner
2. Scan Code 128 barcode (common in warehouses)
3. Hold steady

Expected:
✓ Detection successful
✓ Alphanumeric code captured correctly

Pass: □  Fail: □  Code: _______________
```

### Test 6: Camera Switching (if multiple cameras)
```
Steps:
1. Open scanner
2. Click "Switch Camera" button
3. Camera should toggle

Expected:
✓ Switches to different camera
✓ Video continues smoothly
✓ Can toggle back and forth
✓ No errors or freezing

Pass: □  Fail: □  Notes: _______________
```

### Test 7: Scanner Close
```
Steps:
1. Open scanner
2. Click X button or Close button
3. Scanner should close

Expected:
✓ Modal closes smoothly
✓ Camera light turns off
✓ No console errors

Pass: □  Fail: □  Notes: _______________
```

### Test 8: Multiple Scans
```
Steps:
1. Scan first barcode
2. Wait for scanner to close
3. Open scanner again (Ctrl+K)
4. Scan second barcode
5. Repeat 3-5 times

Expected:
✓ Each scan works correctly
✓ No slowdown after multiple scans
✓ Camera reopens quickly each time
✓ No memory leaks (check task manager)

Pass: □  Fail: □  Scans Completed: _______________
```

---

## 📱 Mobile Testing

### Test 9: Mobile Scanner Open
```
Device: _______________
Browser: _______________

Steps:
1. Open Sales POS on mobile
2. Tap camera button
3. Grant camera permission

Expected:
✓ Rear camera opens by default
✓ Full-screen scanner modal
✓ Touch controls responsive
✓ Video fills screen properly

Pass: □  Fail: □  Notes: _______________
```

### Test 10: Mobile Barcode Scan
```
Steps:
1. Open scanner on mobile
2. Point at retail product barcode
3. Hold phone steady (6-10 inches away)

Expected:
✓ Detects within 2-3 seconds
✓ Success feedback clear on mobile
✓ Scanner closes smoothly
✓ Product added to cart

Pass: □  Fail: □  Product: _______________
```

### Test 11: Mobile QR Scan
```
Steps:
1. Open scanner
2. Scan QR code from another phone
3. Try different distances and angles

Expected:
✓ QR detection fast and accurate
✓ Works at various angles
✓ Responsive on mobile screen

Pass: □  Fail: □  Notes: _______________
```

### Test 12: Mobile Camera Switch
```
Steps:
1. Open scanner
2. Tap "Switch Camera" button
3. Should toggle front/rear

Expected:
✓ Smooth transition
✓ Both cameras work
✓ Can switch multiple times

Pass: □  Fail: □  Notes: _______________
```

### Test 13: Mobile Portrait/Landscape
```
Steps:
1. Open scanner in portrait
2. Scan a code
3. Rotate to landscape
4. Open scanner again and scan

Expected:
✓ Works in both orientations
✓ UI adapts properly
✓ No layout issues

Pass: □  Fail: □  Notes: _______________
```

---

## 🎯 Format-Specific Tests

### Test 14: Various 1D Formats
```
Test each format:

□ EAN-13 (13 digits): _______________
□ EAN-8 (8 digits): _______________
□ UPC-A (12 digits): _______________
□ UPC-E (6 digits): _______________
□ Code 39: _______________
□ Code 93: _______________
□ Code 128: _______________
□ ITF: _______________
□ Codabar: _______________

Notes: _______________
```

### Test 15: Various 2D Formats
```
Test each format:

□ QR Code: _______________
□ Data Matrix: _______________
□ Aztec: _______________
□ PDF417: _______________

Notes: _______________
```

---

## 🌐 Browser Compatibility Tests

### Test 16: Chrome/Edge
```
Version: _______________

□ Scanner opens
□ Detects barcodes
□ Detects QR codes
□ Camera switch works
□ No console errors

Pass: □  Fail: □  Issues: _______________
```

### Test 17: Firefox
```
Version: _______________

□ Scanner opens
□ Detects barcodes
□ Detects QR codes
□ Camera switch works
□ No console errors

Pass: □  Fail: □  Issues: _______________
```

### Test 18: Safari (Mac/iPhone)
```
Version: _______________

□ Scanner opens
□ Detects barcodes
□ Detects QR codes
□ Camera switch works
□ No console errors

Pass: □  Fail: □  Issues: _______________
```

---

## 🔥 Edge Case Testing

### Test 19: Damaged Barcode
```
Steps:
1. Use partially damaged/worn barcode
2. Try scanning

Expected:
⚠️  May take longer but should detect
⚠️  Or gracefully fail after timeout

Result: _______________
```

### Test 20: Multiple Codes in View
```
Steps:
1. Place multiple barcodes in view
2. Try scanning

Expected:
✓ Detects one code (usually closest)
✓ Consistent detection

Result: _______________
```

### Test 21: Low Light Conditions
```
Steps:
1. Dim lighting
2. Try scanning

Expected:
⚠️  May be slower
⚠️  Should still work with adequate light
⚠️  Graceful degradation

Result: _______________
```

### Test 22: Very Bright Light/Glare
```
Steps:
1. Bright light or reflection on barcode
2. Try scanning

Expected:
⚠️  May struggle with glare
⚠️  User can adjust angle

Result: _______________
```

### Test 23: Small Barcode (far away)
```
Steps:
1. Hold barcode far from camera
2. Try scanning

Expected:
⚠️  May need to be closer
⚠️  Clear error/guidance

Result: _______________
```

### Test 24: Large QR Code (very close)
```
Steps:
1. Hold QR code very close
2. Try scanning

Expected:
✓ Should still detect
✓ Even when filling entire frame

Result: _______________
```

### Test 25: Angled Barcode
```
Steps:
1. Hold barcode at 45° angle
2. Try scanning

Expected:
⚠️  Should detect with moderate angle
⚠️  Very extreme angles may fail

Result: _______________
```

---

## 🚨 Error Handling Tests

### Test 26: No Camera Permission
```
Steps:
1. Deny camera permission
2. Try to open scanner

Expected:
✓ Clear error message
✓ Instructions to enable permission
✓ No crashes

Pass: □  Fail: □  Error Message: _______________
```

### Test 27: Camera In Use
```
Steps:
1. Open camera in another app/tab
2. Try to open scanner

Expected:
✓ Error about camera in use
✓ Clear guidance
✓ Graceful handling

Pass: □  Fail: □  Notes: _______________
```

### Test 28: Browser Too Old
```
Steps:
1. Test on old browser (if available)
2. Try to open scanner

Expected:
✓ Error about unsupported browser
✓ Recommendation to update

Pass: □  Fail: □  Notes: _______________
```

### Test 29: No Camera Available
```
Steps:
1. Test on device without camera (if possible)
2. Try to open scanner

Expected:
✓ Clear error message
✓ Feature gracefully disabled

Pass: □  Fail: □  Notes: _______________
```

---

## ⚡ Performance Tests

### Test 30: Scan Speed
```
Steps:
1. Time how long to detect code
2. Test 10 different codes
3. Calculate average

Results:
Code 1: _____s
Code 2: _____s
Code 3: _____s
Code 4: _____s
Code 5: _____s
Code 6: _____s
Code 7: _____s
Code 8: _____s
Code 9: _____s
Code 10: _____s

Average: _____s
Target: < 2 seconds

Pass: □  Fail: □
```

### Test 31: CPU Usage
```
Steps:
1. Open Task Manager/Activity Monitor
2. Open scanner
3. Monitor CPU usage while scanning

CPU Usage (scanner active): _____%
CPU Usage (scanner idle): _____%

Target: < 20% increase
Pass: □  Fail: □
```

### Test 32: Memory Usage
```
Steps:
1. Check browser memory before
2. Open scanner
3. Scan 20 codes
4. Close scanner
5. Check memory after

Memory Before: _____MB
Memory After: _____MB
Memory Increase: _____MB

Target: < 50MB increase
Pass: □  Fail: □
```

### Test 33: Battery Impact (Mobile)
```
Steps:
1. Note battery % before
2. Use scanner for 5 minutes
3. Note battery % after

Battery Before: _____%
Battery After: _____%
Battery Drain: _____%

Target: < 5% for 5 minutes
Pass: □  Fail: □
```

---

## 🔗 Integration Tests

### Test 34: Product Search After Scan
```
Steps:
1. Scan known product code
2. Wait for search
3. Verify product loaded

Expected:
✓ Product search triggered automatically
✓ Correct product loaded
✓ Details displayed properly

Pass: □  Fail: □  Product: _______________
```

### Test 35: Add to Cart After Scan
```
Steps:
1. Scan product
2. Verify added to cart
3. Check quantity and price

Expected:
✓ Product added with correct details
✓ Price matches database
✓ Quantity set to 1

Pass: □  Fail: □  Notes: _______________
```

### Test 36: Multiple Products Scan
```
Steps:
1. Scan product 1
2. Scan product 2
3. Scan product 3
4. Check cart

Expected:
✓ All 3 products in cart
✓ No duplicates (or quantity increased)
✓ Total calculated correctly

Pass: □  Fail: □  Cart Total: _______________
```

### Test 37: Unknown Product Scan
```
Steps:
1. Scan barcode not in database
2. Observe response

Expected:
✓ Clear "Product not found" message
✓ Option to continue/retry
✓ No errors

Pass: □  Fail: □  Message: _______________
```

---

## 📊 Test Summary

```
Total Tests: 37
Passed: ___
Failed: ___
Skipped: ___

Pass Rate: ____%

Critical Issues: _______________
__________________________________
__________________________________

Minor Issues: _______________
__________________________________
__________________________________

Notes: _______________
__________________________________
__________________________________
```

---

## ✅ Sign-Off

```
Tested By: _______________
Date: _______________
Browser(s): _______________
Device(s): _______________

Overall Status: □ Pass  □ Fail  □ Pass with Issues

Recommendation:
□ Ready for production
□ Needs minor fixes
□ Needs major fixes

Signature: _______________
```

---

## 🔧 Common Issues & Solutions

### Issue: Scanner won't open
**Check:**
- Camera permission granted?
- HTTPS or localhost?
- ZXing library loaded? (check console)

### Issue: Slow detection
**Check:**
- Lighting adequate?
- Barcode clear and flat?
- Camera focused?
- Device performance adequate?

### Issue: Wrong product loaded
**Check:**
- Barcode matches product?
- Database up to date?
- No duplicate codes in database?

---

## 📞 Report Issues

If you find bugs or issues:

1. **Note the details:**
   - Browser/device
   - Steps to reproduce
   - Expected vs actual behavior
   - Console errors

2. **Check documentation:**
   - ZXING_SCANNER_README.md
   - TROUBLESHOOTING section

3. **Report with:**
   - Clear description
   - Screenshots/video if possible
   - Test results from this guide

---

**Happy Testing!** 🎉

**Remember:** The goal is a smooth, reliable scanning experience for users. Report any issues that affect usability!
