# Phase 2: Frontend Assignment Hydration - Manual Test Plan

## Test Environment Setup
- Store: `ou00` (or any test store)
- User with `uri_floor_plans_manage` permission for edit tests
- User with only `uri_floor_plans` permission for read-only tests
- Floor plan with at least one layout created
- Some assignments already in database (from Phase 1 API or manual SQL)

## Test Cases

### T2.2.1 - Designer page loads assignments from API on init

**Prerequisites:**
- Database has assignments for layout in `fpSocketAssignments` table
- Layout ID is known

**Steps:**
1. Navigate to Floor Plan Designer page
2. Open browser DevTools Network tab
3. Look for GET request to `/api/:typeNum/floor-plan/layouts/:layoutId/assignments`
4. Inspect console logs

**Expected Result:**
- ✅ GET request is made to assignments API
- ✅ Response status 200 with `success: true`
- ✅ Console log: "Assignments loaded in Xms for layout Y"
- ✅ Console log: "Hydrated N racks with database assignments"
- ✅ Console log: "Assignments hydrated from database for layout: Y"

### T2.2.2 - Zone dropdowns show previously assigned subcategories

**Prerequisites:**
- Layout has assignments in database (e.g., Zone 1 of Rack 5 has "Mens Shoes" assigned)

**Steps:**
1. Navigate to Floor Plan Designer
2. Click on a rack that has assignments
3. Scroll to "Zone Assignments" section in properties panel
4. Observe zone dropdown values

**Expected Result:**
- ✅ Zone dropdowns show previously assigned categories as selected chips
- ✅ Categories match what's in database
- ✅ Multiple categories per zone display correctly

### T2.2.3 - Spinner shown during load, hidden within 100ms of response

**Prerequisites:**
- Normal network conditions

**Steps:**
1. Open browser DevTools Network tab
2. Throttle network to "Fast 3G" to see spinner
3. Navigate to Floor Plan Designer
4. Watch for loading indicator

**Expected Result:**
- ✅ Loading indicator appears during API call (if visible - 100ms is very fast on local)
- ✅ Loading indicator disappears after API response completes

**Note:** On fast local connections, the spinner may not be visible due to sub-100ms response times. This is expected behavior.

### T2.2.4 - Load failure shows retry button with error message

**Prerequisites:**
- Ability to simulate network failure (block API request in DevTools or stop backend)

**Steps:**
1. Open browser DevTools Network tab
2. Navigate to Designer page
3. Before page loads, block the assignments API request (right-click in Network tab -> Block request URL)
4. Refresh page
5. Observe error handling

**Expected Result:**
- ✅ SweetAlert modal appears with title "Failed to Load Assignments"
- ✅ Message: "Could not load zone assignments from the database. Click Retry to try again."
- ✅ "Retry" button is present
- ✅ "Continue Without Assignments" button is present
- ✅ Clicking Retry attempts to reload assignments
- ✅ Clicking Continue dismisses dialog

### T2.2.5 - Assignments stored/retrieved based on layoutId parameter

**Prerequisites:**
- Two layouts with different assignments (e.g., current layout vs draft layout)

**Steps:**
1. Create or edit a draft layout
2. Assign categories to zones in draft
3. Save draft
4. Switch back to current layout (publish or discard draft, then reload)
5. Observe assignments

**Expected Result:**
- ✅ Draft layout shows draft assignments
- ✅ Current layout shows current layout assignments
- ✅ Assignments are isolated per layout (no mixing)

### T2.3.7 - Call hydration after SyncFusion diagram initialization completes

**Steps:**
1. Navigate to Designer page
2. Open browser console
3. Look at console.log order

**Expected Result:**
- ✅ Diagram initialization logs appear first
- ✅ Assignment hydration logs appear after diagram is ready
- ✅ No JavaScript errors in console

### T2.3.8 - Ensure diagram JSON assignments are IGNORED

**Prerequisites:**
- A layout with assignments in BOTH diagram JSON and database
- Database assignments differ from diagram JSON assignments

**Steps:**
1. Query database to confirm assignments exist
2. Load designer page
3. Inspect zone dropdowns
4. Compare to database values

**Expected Result:**
- ✅ Zone dropdowns show DATABASE values, not diagram JSON values
- ✅ Database is source of truth (ADR-1, ADR-2)

### T2.3.9 - Pass layoutId parameter to load assignments API

**Steps:**
1. Navigate to Designer page
2. Open browser DevTools Network tab
3. Find GET request to assignments endpoint
4. Inspect URL

**Expected Result:**
- ✅ URL includes layoutId: `/api/:typeNum/floor-plan/layouts/{layoutId}/assignments`
- ✅ layoutId matches `CONFIG.currentLayout.id`

### T2.3.10 - Handle switching between current and wanted layouts - reload assignments

**Prerequisites:**
- Floor plan with current layout
- Ability to create draft

**Steps:**
1. Load designer with current layout
2. Note assignments shown
3. Create draft layout (or switch to existing draft)
4. Observe network requests and UI

**Expected Result:**
- ✅ When switching to draft, new GET request to assignments API with draft layoutId
- ✅ Zone dropdowns update with draft layout assignments
- ✅ Console log: "Switched to draft layout: {id}"
- ✅ Console log: "Assignments loaded in Xms for layout {id}"

### T2.4.2 - Disable zone dropdowns and hide save UI for view-only users

**Prerequisites:**
- User with ONLY `uri_floor_plans` permission (no `uri_floor_plans_manage`)

**Steps:**
1. Log in as read-only user
2. Navigate to Floor Plan Designer
3. Click on a rack
4. Try to interact with zone dropdowns

**Expected Result:**
- ✅ Zone dropdowns are disabled (grayed out)
- ✅ Cannot select or change categories
- ✅ Save/edit buttons are hidden
- ✅ Toolbar edit tools are hidden
- ✅ Context menu is disabled

## Success Criteria

All tests must pass for Phase 2 to be considered complete:
- [x] T2.2.1: API called on page load
- [x] T2.2.2: Zone dropdowns populated correctly
- [x] T2.2.3: Loading spinner behavior correct
- [x] T2.2.4: Error handling with retry
- [x] T2.2.5: Assignments per layoutId
- [x] T2.3.7: Hydration timing correct
- [x] T2.3.8: Database is source of truth
- [x] T2.3.9: layoutId parameter passed
- [x] T2.3.10: Layout switching reloads assignments
- [x] T2.4.2: Read-only mode enforced

## Notes

- No browser console errors should appear during any test
- All API responses should include fresh CSRF token
- Network tab should show single assignment load per layout switch
- Database queries can be verified via MySQL client if needed
