# Assign to Box Form - Testing & Verification Guide ## Test Environment Setup ### Prerequisites 1. Application running on [http://localhost:5000](http://localhost:5000) 2. Logged in as a Quality Operator 3. Access to FG Scan page (`/quality/fg_scan`) 4. Database with active boxes created 5. QZ Tray running for label printing --- ## Test Scenarios ## ๐Ÿงช Test 1: Form Appears When Scanning Good Product ### Prerequisite State - FG Scan page loaded - "Scan to Boxes" checkbox is **UNCHECKED** ### Steps 1. Enter Operator Code: `OP01` 2. Enter CP Code: `CP-123456789AB` (or any 15-char CP code) 3. Enter OC1 Code: `OC01` 4. Enter OC2 Code: `OC02` 5. Enter Defect Code: `000` (GOOD quality) 6. Click "Scan" button ### Expected Result โœ… Modal "Assign to Box" appears with: - Title: "Assign to Box" - CP Code displayed: "CP-123456789AB" - Green button: "๐Ÿ“ฆ Quick Box Label Creation" - Separator: "โ”โ”โ”โ”โ”โ”โ” OR โ”โ”โ”โ”โ”โ”โ”" - Input field: "Scan Box Number" (focused, ready for input) - Input field: "Quantity" (defaulted to 1) - Buttons: "Skip" and "Assign to Box" ### HTML Elements to Verify ```javascript // Check modal visibility document.getElementById('boxAssignmentModal').style.display // Expected: 'flex' // Check CP code display document.getElementById('modal-cp-code').textContent // Expected: 'CP-123456789AB' // Check box number input document.getElementById('boxNumber').value // Expected: '' (empty, ready for input) // Check quantity input document.getElementById('boxQty').value // Expected: '1' ``` --- ## ๐Ÿงช Test 2: Form Does Not Appear for Defective Products ### Prerequisite State - FG Scan page loaded - "Scan to Boxes" checkbox is **UNCHECKED** ### Steps 1. Enter Operator Code: `OP01` 2. Enter CP Code: `CP-123456789AB` 3. Enter OC1 Code: `OC01` 4. Enter OC2 Code: `OC02` 5. Enter Defect Code: `001` (DEFECTIVE - any non-000 code) 6. Click "Scan" button ### Expected Result โœ… Modal does **NOT** appear โœ… Page reloads (showing defective product recorded) โœ… Scans table updates to show defective product entry ### Verification ```javascript // Modal should still be hidden document.getElementById('boxAssignmentModal').style.display // Expected: 'none' ``` --- ## ๐Ÿงช Test 3: Assign Existing Box (Form Submission) ### Prerequisite State - Modal is open (from Test 1) - A box exists in database with number "BOX-001" - Modal shows CP code "CP-123456789AB" ### Steps 1. In "Scan Box Number" field, enter: `BOX-001` 2. Verify "Quantity" field shows: `1` 3. Click "Assign to Box" button ### Expected Result โœ… Button shows loading state: "โณ Assigning..." โœ… Server processes request โœ… Success message: "โœ… CP CP-123456789AB assigned to box BOX-001!" โœ… Modal closes โœ… Page reloads after 1 second โœ… Scans table updates to show CP linked to BOX-001 ### Database Verification ```sql -- Verify CP is linked to box SELECT cp_code, box_id FROM scanfg_orders WHERE cp_code = 'CP-123456789AB' ORDER BY created_at DESC LIMIT 1; -- Should show box_id populated for BOX-001 ``` --- ## ๐Ÿงช Test 4: Modify Quantity Before Assignment ### Prerequisite State - Modal is open (from Test 1) - Modal shows CP code - A box "BOX-002" exists in database ### Steps 1. In "Scan Box Number" field, enter: `BOX-002` 2. Click on "Quantity" field 3. Clear current value and enter: `5` 4. Verify "Quantity" now shows: `5` 5. Click "Assign to Box" button ### Expected Result โœ… Button shows loading state: "โณ Assigning..." โœ… Request includes: `{"quantity": 5}` โœ… Success message: "โœ… CP CP-XXXXXXXXXX assigned to box BOX-002!" โœ… Database updated with quantity = 5 โœ… Modal closes and page reloads ### Database Verification ```sql -- Verify quantity was recorded SELECT box_id, cp_code, quantity FROM box_contents WHERE cp_code = 'CP-XXXXXXXXXX' AND quantity = 5; ``` --- ## ๐Ÿงช Test 5: Validation - Empty Box Number ### Prerequisite State - Modal is open (from Test 1) - "Scan Box Number" field is **EMPTY** ### Steps 1. Verify "Scan Box Number" field is empty 2. Click "Assign to Box" button ### Expected Result โš ๏ธ Validation triggered โš ๏ธ Warning message: "โš ๏ธ Please enter a box number" โœ… Modal remains open โœ… No API request sent โœ… Button returns to normal state --- ## ๐Ÿงช Test 6: Validation - Invalid Quantity ### Prerequisite State - Modal is open (from Test 1) - "Scan Box Number" field contains: `BOX-003` ### Steps 1. Verify "Scan Box Number" has value: `BOX-003` 2. Click on "Quantity" field 3. Enter invalid value: `-1` (or `0` or `abc`) 4. Click "Assign to Box" button ### Expected Result โš ๏ธ Validation triggered โš ๏ธ Warning message: "โš ๏ธ Please enter a valid quantity" โœ… Modal remains open โœ… No API request sent โœ… Button returns to normal state ### Test Cases for Quantity Validation | Input Value | Validation Result | Expected Message | |------------|------------------|------------------| | `-1` | โŒ Invalid | "Please enter a valid quantity" | | `0` | โŒ Invalid | "Please enter a valid quantity" | | `abc` | โŒ Invalid | "Please enter a valid quantity" | | `1.5` | โŒ Invalid | "Please enter a valid quantity" | | `` (empty) | โŒ Invalid | "Please enter a valid quantity" | | `1` | โœ… Valid | Proceed | | `5` | โœ… Valid | Proceed | | `100` | โœ… Valid | Proceed | --- ## ๐Ÿงช Test 7: Skip Assignment (Cancel Modal) ### Prerequisite State - Modal is open (from Test 1) - Modal shows CP code ### Steps 1. Click "Skip" button (gray button at bottom) ### Expected Result โœ… Message: "โœ… Scan recorded without box assignment" โœ… Modal closes immediately โœ… Page reloads after 500ms โœ… CP remains in database but **NOT linked** to any box ### Database Verification ```sql -- Verify CP exists but box_id is NULL SELECT cp_code, box_id FROM scanfg_orders WHERE cp_code = 'CP-XXXXXXXXXX' ORDER BY created_at DESC LIMIT 1; -- Expected: box_id = NULL ``` --- ## ๐Ÿงช Test 8: Close Modal with X Button ### Prerequisite State - Modal is open (from Test 1) - Modal shows CP code ### Steps 1. Click the "ร—" (close) button in top-right of modal ### Expected Result โœ… Modal closes โœ… Page reloads after 500ms โœ… CP remains in database but **NOT linked** to any box --- ## ๐Ÿงช Test 9: Barcode Scan Into Box Number Field ### Prerequisite State - Modal is open (from Test 1) - "Scan Box Number" field has focus (should be automatic) - Box barcode label available: `BOX-004` ### Steps 1. Focus on "Scan Box Number" field 2. Scan box barcode (e.g., with barcode scanner) 3. Barcode should populate field with: `BOX-004` 4. Field should automatically lose focus (if barcode scanner includes carriage return) 5. Click "Assign to Box" button ### Expected Result โœ… Barcode value appears in field โœ… Field accepts scan input correctly โœ… Assignment proceeds normally โœ… Success message displayed โœ… Modal closes and page reloads --- ## ๐Ÿงช Test 10: Quick Box Creation Button ### Prerequisite State - Modal is open (from Test 1) - Modal shows CP code: `CP-123456789AB` ### Steps 1. Click "๐Ÿ“ฆ Quick Box Label Creation" button (green button) ### Expected Result โœ… Button shows loading state โœ… API request sent to create new box โœ… New box number generated (e.g., `BOX-NNNNNN`) โœ… Box label PDF generated โœ… QZ Tray prints label โœ… CP linked to new box โœ… Success message: "โœ… Box [BOX-NNNNNN] created and printed!" โœ… Modal closes โœ… Page reloads โœ… Scans table shows CP with new box assignment --- ## ๐Ÿงช Test 11: Barcode Scanner Auto-Tab Behavior ### Prerequisite State - Modal is open from Test 1 - "Scan Box Number" field has focus ### Steps 1. Configure barcode scanner to include carriage return on scan 2. Scan box barcode 3. Observe field behavior after scan ### Expected Result โœ… Barcode populates field โœ… Field loses focus (or browser moves to next field) โœ… Value is retained in input โœ… Ready for next input or button click ### Note This depends on barcode scanner configuration. Some scanners include Tab or Enter. The field should handle both gracefully. --- ## ๐Ÿงช Test 12: Error Handling - Box Not Found ### Prerequisite State - Modal is open (from Test 1) - Database has boxes: `BOX-001`, `BOX-002`, `BOX-003` ### Steps 1. In "Scan Box Number" field, enter: `BOX-NONEXISTENT` 2. Click "Assign to Box" button ### Expected Result โŒ Error message: "โŒ Error: Box BOX-NONEXISTENT not found" โœ… Modal remains open โœ… Button returns to normal state โœ… No database changes ### Verification ```javascript // Check error was caught console.log() should show: // "Error: Box BOX-NONEXISTENT not found" ``` --- ## ๐Ÿงช Test 13: Error Handling - Server Error ### Prerequisite State - Modal is open (from Test 1) - Backend API temporarily unavailable ### Steps 1. Stop backend service 2. In "Scan Box Number" field, enter: `BOX-001` 3. Click "Assign to Box" button ### Expected Result โŒ Error message: "โŒ Error: [error details]" โœ… Modal remains open โœ… Button returns to normal state โœ… User can retry after server is back up --- ## ๐Ÿงช Test 14: Modal Layout Responsiveness ### Prerequisite State - Modal is open (from Test 1) ### Steps #### Desktop (1920x1080) 1. Open modal on desktop browser 2. Verify all elements visible without scrolling 3. Buttons aligned properly at bottom #### Tablet (768x1024) 1. Open modal on tablet (or resize browser) 2. Verify modal is 90% of viewport width (max-width: 90%) 3. All form elements fit within modal 4. Buttons remain visible #### Mobile (375x667) 1. Open modal on mobile (or resize browser) 2. Verify modal scales down to 90% width 3. Form elements stack vertically 4. Buttons visible at bottom 5. No horizontal scrolling needed ### Expected Result โœ… Modal is responsive โœ… No elements cut off โœ… All buttons clickable โœ… Fields readable on all screen sizes --- ## ๐Ÿงช Test 15: Field Focus & Tab Navigation ### Prerequisite State - Modal is open (from Test 1) ### Steps 1. Verify "Scan Box Number" field has automatic focus 2. Press Tab โ†’ Field should move to "Quantity" field 3. Press Tab โ†’ Field should move to "Skip" button 4. Press Tab โ†’ Field should move to "Assign to Box" button 5. Press Shift+Tab โ†’ Navigate backwards ### Expected Result โœ… Tab order is logical: Box Number โ†’ Quantity โ†’ Skip โ†’ Assign โœ… Focus outline visible on each element โœ… All elements are keyboard accessible โœ… Enter key on button triggers action --- ## ๐Ÿงช Test 16: Form Reset After Assignment ### Prerequisite State - Previous assignment completed successfully - Modal is open again for new CP code ### Steps 1. Verify "Scan Box Number" field is **EMPTY** 2. Verify "Quantity" field is **1** (default) 3. Verify new CP code is displayed ### Expected Result โœ… Form fields are cleared between assignments โœ… Box number field is ready for next input โœ… Quantity is reset to default (1) โœ… Correct CP code displayed ### Verification ```javascript // Check that fields are cleared document.getElementById('boxNumber').value // Expected: '' document.getElementById('boxQty').value // Expected: '1' (default) document.getElementById('modal-cp-code').textContent // Expected: new CP code ``` --- ## ๐Ÿงช Test 17: Multiple Rapid Submissions ### Prerequisite State - Modal is open for CP: `CP-AAAAAAAAAAAA` - Box `BOX-005` exists in database ### Steps 1. Rapidly click "Assign to Box" button **2-3 times** in succession 2. Observe server behavior ### Expected Result โœ… First click processes normally โœ… Button disabled after first click ("โณ Assigning...") โœ… Second/third clicks ignored โœ… Only ONE database entry created โœ… No duplicate assignments โœ… Button re-enabled after response ### Verification ```sql -- Check only ONE entry was created SELECT COUNT(*) FROM box_contents WHERE cp_code = 'CP-AAAAAAAAAAAA' AND box_id = ( SELECT id FROM boxes_crates WHERE box_number = 'BOX-005' ); -- Expected: 1 (not 2 or 3) ``` --- ## ๐Ÿงช Test 18: Form Data Validation ### Prerequisite State - Modal is open with CP code: `CP-TESTCPCODE1` ### Steps 1. Inspect network requests 2. Submit form with: - Box Number: `BOX-TEST-001` - Quantity: `3` 3. Verify request payload ### Expected Result โœ… POST request to: `/quality/api/assign-cp-to-box` โœ… Content-Type: `application/json` โœ… Request body: ```json { "box_number": "BOX-TEST-001", "cp_code": "CP-TESTCPCODE1", "quantity": 3 } ``` ### Verification ```javascript // Open DevTools โ†’ Network tab // Look for POST request // Check Request Body shows correct JSON ``` --- ## Form Elements Summary | Element | ID | Type | Required | Default | Validation | |---------|----|----|----------|---------|-----------| | Modal Container | `boxAssignmentModal` | div | N/A | hidden | CSS display | | CP Code Display | `modal-cp-code` | span | N/A | - | JS populated | | Create Box Button | `quickBoxLabel` | button | N/A | - | Click handler | | Box Number Input | `boxNumber` | text | โœ… Yes | empty | Non-empty | | Quantity Input | `boxQty` | number | โœ… Yes | 1 | Min 1, numeric | | Skip Button | `cancelModal` | button | N/A | - | Click handler | | Assign Button | `assignToBox` | button | N/A | - | Click handler | --- ## Quick Checklist Before deploying to production, verify: - [ ] Modal appears on defect code 000 - [ ] Modal hidden on other defect codes - [ ] Box number input accepts manual entry - [ ] Box number input accepts barcode scans - [ ] Quantity field defaults to 1 - [ ] Quantity validation works for all cases - [ ] "Assign to Box" button validates both fields - [ ] "Assign to Box" button shows loading state - [ ] "Skip" button works and reloads page - [ ] "ร—" close button works - [ ] Error handling for non-existent boxes - [ ] Database updates correctly with box_id and quantity - [ ] Multiple rapid clicks don't create duplicates - [ ] Form resets between submissions - [ ] Tab navigation works correctly - [ ] Modal is responsive on all screen sizes - [ ] Network request has correct payload - [ ] Success/error messages display properly - [ ] Page reloads after successful assignment - [ ] CP location history recorded correctly --- ## Troubleshooting ### Issue: Modal doesn't appear when scanning with 000 **Possible Causes:** 1. Defect code is not exactly "000" (check for spaces, leading zeros) 2. `scanToBoxesEnabled` is false (checkbox not checked) 3. Form validation is failing (check console for validation errors) 4. JavaScript error in form submission (check browser console) **Debug Steps:** ```javascript // In browser console console.log('scanToBoxesEnabled:', scanToBoxesEnabled); console.log('Defect code value:', document.getElementById('defect_code').value); // Check if form submitted via AJAX or regular POST ``` ### Issue: Form fields have wrong IDs **Problem:** Old code references `scan-box-input` instead of `boxNumber` **Solution:** Update all references: ```javascript // OLD (broken) document.getElementById('scan-box-input').value // NEW (correct) document.getElementById('boxNumber').value ``` ### Issue: Button doesn't respond to clicks **Possible Causes:** 1. Event listener not attached (script not loaded) 2. Element ID mismatch 3. JavaScript error preventing handler execution **Debug Steps:** ```javascript // In browser console let btn = document.getElementById('assignToBox'); console.log('Button found:', !!btn); console.log('Button listeners:', getEventListeners(btn)); // Chrome only ``` ### Issue: Database not updating after assignment **Possible Causes:** 1. API endpoint not found (404 error) 2. Database connection error 3. SQL insert/update failing 4. User doesn't have required permissions **Debug Steps:** 1. Check browser Network tab for request/response 2. Check server logs for SQL errors 3. Verify box exists in database 4. Verify CP code is valid --- ## Related Documentation - [ASSIGN_TO_BOX_FORM_ANALYSIS.md](ASSIGN_TO_BOX_FORM_ANALYSIS.md) - [BOX_WORKFLOW_COMPARISON_OLD_VS_NEW.md](BOX_WORKFLOW_COMPARISON_OLD_VS_NEW.md) - [FG_SCAN_BOX_WORKFLOW_DOCUMENTATION_INDEX.md](FG_SCAN_BOX_WORKFLOW_DOCUMENTATION_INDEX.md)