# Phase 1 Progress Tracking - Testing Steps

## Overview
Phase 1 implements client-side multi-job progress tracking UI. Jobs are tracked per button, with support for single and multiple jobs per button.

## Token Format
- **select_prompt**: Button token: `{objectId}_select_prompt_{timestamp}_{random}`, Job token: `{objectId}_{promptId}_{timestamp}_{random}`
- **ai:prompt (autofill)**: Token: `{objectId}_{fieldId}_{timestamp}_{random}`
- **proposeThought**: Token: `{objectId}_proposeThought_{timestamp}_{random}`

## Test 1: ai:prompt Button (Single Job) - Task Description Field

### Setup
1. Open a task object in JOE
2. Navigate to the "description" field (should have an "AI" button)

### Test Steps
1. **Verify button rendering**:
   - Button should have class `joe-ai-button` and `joe-ai-autofill-button`
   - Button should have `data-progress-token` attribute (format: `{objectId}_description_{timestamp}_{random}`)
   - Button should have `data-field-name="description"` attribute
   - Progress div should exist below button with `data-for-token` matching button token
   - Jobs list container should exist below progress div

2. **Click AI button**:
   - Button should disable and show loading state
   - Button text should change to "Running..." or show percentage if available
   - Progress text field should show "Starting..." or progress message
   - Jobs list should show one job: "AI Autofill - Running..."

3. **During execution** (if progress updates are sent):
   - Button text should update with percentage: "Running... X%"
   - Progress text should show detailed message
   - Job in list should show percentage

4. **On completion**:
   - Button text should show "Complete" briefly, then restore to "AI"
   - Button should re-enable
   - Progress text should clear after 2 seconds
   - Job should be removed from list

5. **On error**:
   - Button should re-enable
   - Job should be cleared
   - Error alert should appear

### Expected Results
- Single job tracked correctly
- Button shows percentage when single job is active
- UI updates properly
- Job cleared on completion/error

---

## Test 2: select_prompt Field (Multiple Jobs)

### Setup
1. Open a protocol object (or any object with `select_prompt` field)
2. Navigate to the "Run AI Prompt" field

### Test Steps
1. **Verify button rendering**:
   - Button token format: `{objectId}_select_prompt_{timestamp}_{random}`
   - Progress and jobs containers exist

2. **Run first prompt**:
   - Select a prompt from dropdown
   - Click "Run AI Prompt"
   - Button should disable
   - Job token should be generated: `{objectId}_{promptId}_{timestamp}_{random}`
   - Jobs list should show: "{Prompt Name} - Running..."
   - Button text should show percentage (single job)

3. **Run second prompt** (while first is running):
   - Select a different prompt
   - Click "Run AI Prompt" again
   - Second job should be added to jobs list
   - Button text should change to "2 jobs running"
   - Progress text field should clear (multiple jobs shown in list)

4. **Verify multiple jobs display**:
   - Jobs list should show both jobs with their names and statuses
   - Each job should show percentage or "Running..."

5. **Complete jobs**:
   - As jobs complete, they should be removed from list
   - Button text should update: "2 jobs running" → "1 job running" → percentage → "Complete" → original text
   - When all jobs complete, button should re-enable

### Expected Results
- Multiple jobs tracked correctly
- Button shows "X jobs running" when multiple active
- Jobs list displays all active jobs
- Button shows percentage when only one job remains
- All jobs cleared when complete

---

## Test 3: proposeThought Field (Single Job)

### Setup
1. Open a task object
2. Navigate to "Propose Thought" field

### Test Steps
1. **Verify button rendering**:
   - Button token format: `{objectId}_proposeThought_{timestamp}_{random}`
   - Progress and jobs containers exist

2. **Run thought agent**:
   - Click "Run Thought Agent"
   - Button should disable
   - Job should be tracked (token: `{objectId}_proposeThought_{timestamp}_{random}`)
   - Button text should show "Running..." or percentage
   - Progress text should show status

3. **On completion**:
   - Button should re-enable
   - Job should be cleared
   - UI should restore

### Expected Results
- Single job tracked correctly
- UI updates properly
- Job cleared on completion

---

## Test 4: Navigation (Field Rerender)

### Setup
1. Start a job on any field
2. Navigate away (list view or different object)
3. Navigate back to the same object

### Test Steps
1. **Before navigation**:
   - Note the button token
   - Start a job
   - Verify job is tracked

2. **After navigation**:
   - Field rerenders with new button token
   - Old job tracking is lost (expected for Phase 1)
   - New button has no active jobs

### Expected Results
- Field rerender creates new button with new token
- Old jobs are not visible (Phase 2 will add server-side reconnection)
- New button works normally

---

## Test 5: Error Handling

### Test Steps
1. **Network error**:
   - Start a job
   - Simulate network failure (disable network or invalid endpoint)
   - Verify error alert appears
   - Verify job is cleared
   - Verify button re-enables

2. **Server error**:
   - Start a job with invalid parameters
   - Verify error message appears
   - Verify job is cleared
   - Verify button re-enables

### Expected Results
- Errors are handled gracefully
- Jobs are cleared on error
- UI is restored

---

## Test 6: Multiple Windows

### Setup
1. Open same object in two browser windows/tabs

### Test Steps
1. **Window 1**:
   - Start a job
   - Verify job is tracked

2. **Window 2**:
   - Should have independent button token
   - Can start separate job
   - Jobs are tracked independently

### Expected Results
- Each window has independent job tracking
- No conflicts between windows

---

## Debugging

### Console Checks
- `Ai.activeJobs` Map should contain button tokens as keys
- Each value should be an array of job objects
- Job objects should have: `token`, `promptId`, `promptName`, `progress`, `total`, `message`

### Common Issues
1. **Button not found**: Check `data-progress-token` attribute exists
2. **Jobs not showing**: Check `Ai.activeJobs` Map has entries
3. **UI not updating**: Check `renderJobsList` is being called
4. **Token format wrong**: Verify token matches expected format for field type

---

## Notes
- Phase 1 is client-side only. Server-side progress tracking comes in Phase 2.
- Jobs are lost on page refresh or field rerender (Phase 2 will add persistence).
- Progress updates require server-side implementation (Phase 2/3).
