# Phase 1 Testing Plan

> **Purpose**: Comprehensive testing checklist for Phase 1 functionality  
> **Created**: 2025-01-12  
> **Status**: Ready for Testing

## Prerequisites

Before testing, ensure you have:
- [ ] Chrome or Edge browser (latest version)
- [ ] Access to a Filevine account
- [ ] Filevine extension loaded in browser
- [ ] Chrome DevTools knowledge (for debugging)

## Setup Instructions

### 1. Load Extension in Chrome

1. Open Chrome and navigate to `chrome://extensions`
2. Enable **"Developer mode"** (toggle in top-right)
3. Click **"Load unpacked"**
4. Navigate to and select the `filevine-plugin` directory
5. Verify extension appears in list with name "Filevine Document Viewer"
6. Note the extension ID (you'll need it for debugging)

### 2. Verify Extension Loads

- [ ] Extension icon appears in browser toolbar
- [ ] No errors in `chrome://extensions` page
- [ ] Service worker shows as "active" or "inactive" (both OK)

---

## Test Suite 1: Extension Installation & Initialization

### Test 1.1: Extension Loads Successfully
**Steps:**
1. Load extension (see Setup above)
2. Check background service worker logs

**Expected Results:**
- [ ] Service worker initializes without errors
- [ ] Console shows: `[Filevine Plugin] Extension installed/updated`
- [ ] Console shows: `[Filevine Plugin] Initializing...`
- [ ] Console shows: `[Filevine Plugin] Initialization complete`
- [ ] No red errors in console

**How to Check:**
- `chrome://extensions` → Find extension → Click "service worker" link
- Check console for initialization messages

**If Failed:**
- Check `manifest.json` syntax
- Verify all import paths are correct
- Check browser console for module loading errors

---

### Test 1.2: IndexedDB Initializes
**Steps:**
1. After extension loads, check IndexedDB

**Expected Results:**
- [ ] Database `filevine_docs` created
- [ ] Object stores: `files` and `metadata` exist
- [ ] No errors in service worker console

**How to Check:**
- DevTools → Application → IndexedDB → `filevine_docs`
- Or check service worker console for errors

**If Failed:**
- Check `src/background/downloads.js` → `initializeDb()`
- Verify IndexedDB permissions

---

## Test Suite 2: Content Script Injection

### Test 2.1: Content Script Loads on Filevine Page
**Steps:**
1. Navigate to any Filevine page (e.g., `https://app.filevineapp.com`)
2. Open DevTools → Console tab
3. Look for content script messages

**Expected Results:**
- [ ] Console shows: `[Filevine Plugin] Content script loaded`
- [ ] Console shows: `[Filevine Plugin] Initializing session detection...`
- [ ] No errors related to content script

**How to Check:**
- DevTools Console on Filevine page
- Filter by `[Filevine Plugin]` to see only extension messages

**If Failed:**
- Check `manifest.json` → `content_scripts` → `matches`
- Verify URL pattern matches Filevine domain
- Check if content script file exists at `src/content/index.js`

---

### Test 2.2: Token Extraction Setup
**Steps:**
1. On Filevine page, check console
2. Verify interception is set up

**Expected Results:**
- [ ] Console shows: `[Filevine Plugin] Network interception active`
- [ ] Token extractor initialized
- [ ] Token detector initialized

**How to Check:**
- Look for interception setup messages
- Check for any extraction attempts

**If Failed:**
- Check `src/content/extractor.js` → `setupInterception()`
- Verify script injection works (check for errors)

---

## Test Suite 3: Authentication Flow

### Test 3.1: Popup Shows Disconnected State
**Steps:**
1. Click extension icon in toolbar
2. Observe popup UI

**Expected Results:**
- [ ] Popup opens
- [ ] Shows "Disconnected" status
- [ ] Shows message: "Open Filevine to connect"
- [ ] Connection panel visible (not main panel)

**How to Check:**
- Visual inspection of popup
- Check `#connection-status` element
- Verify status text says "Disconnected"

**If Failed:**
- Check `src/popup/popup.js` → `checkAuthState()`
- Verify CSS classes (`hidden` class)
- Check popup.html structure

---

### Test 3.2: Token Detection on Filevine Login
**Steps:**
1. Ensure you're logged out of Filevine
2. Navigate to Filevine login page
3. Log in to Filevine
4. After login completes, check console

**Expected Results:**
- [ ] Content script detects page change
- [ ] Token extraction attempts occur
- [ ] Tokens found (if extraction works)
- [ ] Message sent to background: `AUTH_DETECTED`

**How to Check:**
- DevTools Console on Filevine page
- Look for: `[Filevine Plugin] New tokens received`
- Check background service worker logs

**If Failed:**
- Token extraction may not work (see Troubleshooting)
- Check `src/content/extractor.js` → `extractTokens()`
- Verify network interception is working

---

### Test 3.3: Background Processes Tokens
**Steps:**
1. After tokens detected, check background service worker
2. Verify auth state stored

**Expected Results:**
- [ ] Background receives `AUTH_DETECTED` message
- [ ] Console shows: `[Filevine Plugin] Auth tokens received from content script`
- [ ] API call to `GetUserOrgsWithToken` succeeds
- [ ] Auth state stored in `chrome.storage.session`
- [ ] API client initialized with credentials

**How to Check:**
- Background service worker console
- Check for API call to `/utils/GetUserOrgsWithToken`
- Verify response contains numeric user ID

**If Failed:**
- Check `src/background/auth.js` → `processTokens()`
- Verify API endpoint URL is correct
- Check network tab for API call
- Verify headers are correct

---

### Test 3.4: Popup Shows Connected State
**Steps:**
1. After authentication succeeds, click extension icon
2. Observe popup UI

**Expected Results:**
- [ ] Popup shows "Connected" status
- [ ] Main panel visible (connection panel hidden)
- [ ] Status indicator shows green/connected
- [ ] Projects should start loading (or show loading state)

**How to Check:**
- Visual inspection
- Check `#connection-status` class
- Verify `#main-panel` is visible

**If Failed:**
- Check `src/popup/popup.js` → `updateConnectionUI()`
- Verify message listener receives `AUTH_STATE_CHANGED`
- Check CSS for `.hidden` class

---

## Test Suite 4: API Communication

### Test 4.1: Get Projects List
**Steps:**
1. With extension connected, open popup
2. Projects should load automatically
3. Check network requests

**Expected Results:**
- [ ] API call to `/Projects` endpoint
- [ ] Request includes all required headers:
  - `Authorization: Bearer {token}`
  - `x-fv-userid: {numeric_id}`
  - `x-fv-orgid: {org_id}`
  - `x-fv-sessionid: {session_id}`
- [ ] Response contains projects array
- [ ] Projects displayed in popup

**How to Check:**
- DevTools → Network tab → Filter by `api.filevineapp.com`
- Check request headers
- Check response payload
- Visual inspection of popup

**If Failed:**
- Check `src/background/api.js` → `getProjects()`
- Verify headers are correct (see ADR-004, ADR-005)
- Check for 401/404 errors
- Verify endpoint uses PascalCase: `/Projects`

---

### Test 4.2: Project Search
**Steps:**
1. In popup, type in project search box
2. Observe API calls

**Expected Results:**
- [ ] Search is debounced (not too many requests)
- [ ] API call includes `q` parameter
- [ ] Results filtered appropriately
- [ ] UI updates with filtered results

**How to Check:**
- Network tab for API calls
- Visual inspection of search results
- Check debounce timing (should be ~300ms)

**If Failed:**
- Check `src/popup/popup.js` → `searchProjects()`
- Verify debounce implementation
- Check API parameter format

---

### Test 4.3: Get Project Documents
**Steps:**
1. Click on a project in the list
2. Observe API call and UI update

**Expected Results:**
- [ ] API call to `/Projects/{id}/Docs`
- [ ] Request includes all required headers
- [ ] Response contains documents array
- [ ] File browser shows documents
- [ ] Back button works to return to projects

**How to Check:**
- Network tab for API call
- Visual inspection of file browser
- Check document list rendering

**If Failed:**
- Check `src/background/api.js` → `getProjectDocuments()`
- Verify endpoint format: `/Projects/{id}/Docs`
- Check `src/popup/popup.js` → `loadDocuments()`

---

## Test Suite 5: Download Functionality

### Test 5.1: Queue Download
**Steps:**
1. Click "Download" button on a document
2. Check download queue state

**Expected Results:**
- [ ] Download added to queue
- [ ] API call to get presigned URL: `/Docs/{id}/Download`
- [ ] Download starts fetching from S3
- [ ] Progress updates (if available)
- [ ] File stored in IndexedDB

**How to Check:**
- Background service worker console
- Network tab for S3 fetch
- IndexedDB → `filevine_docs` → `files` store
- Download state via message: `get_download_state`

**If Failed:**
- Check `src/background/downloads.js` → `queueDownload()`
- Verify presigned URL format
- Check S3 fetch errors
- Verify IndexedDB storage

---

### Test 5.2: Download Progress
**Steps:**
1. Download a large file
2. Check progress updates

**Expected Results:**
- [ ] Progress percentage updates during download
- [ ] Download state broadcasts to popup
- [ ] UI shows progress (if downloads panel open)

**How to Check:**
- Background console for progress logs
- Download state messages
- Visual inspection of downloads panel

**If Failed:**
- Check `src/background/downloads.js` → `executeDownload()`
- Verify progress calculation
- Check broadcast mechanism

---

### Test 5.3: File Storage
**Steps:**
1. After download completes, check IndexedDB
2. Verify file can be retrieved

**Expected Results:**
- [ ] File blob stored in `files` object store
- [ ] Metadata stored in `metadata` object store
- [ ] File can be retrieved by docId
- [ ] Blob URL can be created

**How to Check:**
- DevTools → Application → IndexedDB
- Check both object stores
- Test retrieval: `downloadManager.getFile(docId)`

**If Failed:**
- Check `src/background/downloads.js` → `storeFile()`
- Verify IndexedDB transaction
- Check blob creation

---

## Test Suite 6: Error Handling

### Test 6.1: API Errors
**Steps:**
1. Disconnect from internet
2. Try to load projects
3. Reconnect and try again

**Expected Results:**
- [ ] Error message shown to user
- [ ] Error doesn't crash extension
- [ ] Can retry after reconnecting
- [ ] Error logged in console

**How to Check:**
- Visual inspection of error messages
- Console for error logs
- Verify error handling in popup

**If Failed:**
- Check error handling in `src/popup/popup.js`
- Verify try/catch blocks
- Check error message display

---

### Test 6.2: Authentication Errors
**Steps:**
1. Let session expire (or manually expire token)
2. Try to make API call
3. Check error handling

**Expected Results:**
- [ ] Extension detects expired token
- [ ] Shows "Disconnected" or "Expired" state
- [ ] Prompts user to refresh Filevine page
- [ ] Doesn't crash on expired token

**How to Check:**
- Check auth state after expiry
- Verify `isExpired()` logic
- Check UI updates

**If Failed:**
- Check `src/background/auth.js` → `isExpired()`
- Verify expiry detection
- Check error handling

---

### Test 6.3: Invalid Message Types
**Steps:**
1. Send invalid message type to background
2. Check error handling

**Expected Results:**
- [ ] Error returned (not crash)
- [ ] Error message indicates unknown type
- [ ] Extension continues working

**How to Check:**
- Background console for warning
- Verify error response format

**If Failed:**
- Check `src/background/index.js` → `handleMessage()`
- Verify default case in switch statement

---

## Test Suite 7: Edge Cases

### Test 7.1: Multiple Tabs
**Steps:**
1. Open multiple Filevine tabs
2. Check token extraction on each
3. Verify no conflicts

**Expected Results:**
- [ ] Each tab's content script works independently
- [ ] Background handles multiple token updates
- [ ] No race conditions

**How to Check:**
- Multiple DevTools consoles
- Background service worker logs
- Verify auth state consistency

---

### Test 7.2: Service Worker Restart
**Steps:**
1. Let service worker go inactive
2. Send message to reactivate
3. Verify state restored

**Expected Results:**
- [ ] Service worker reactivates
- [ ] Auth state restored from storage
- [ ] Extension continues working

**How to Check:**
- Service worker console
- Verify initialization on restart
- Check auth state restoration

---

### Test 7.3: Large File Downloads
**Steps:**
1. Download a large file (>50MB)
2. Check memory usage
3. Verify download completes

**Expected Results:**
- [ ] Download doesn't crash browser
- [ ] Progress updates correctly
- [ ] File stored successfully

**How to Check:**
- Task Manager for memory
- Download progress
- IndexedDB storage

---

## Debugging Tools

### Console Commands

**Check Auth State:**
```javascript
// In background service worker console or popup console
chrome.runtime.sendMessage({ type: 'get_auth_state' }, console.log);
```

**Check Download State:**
```javascript
chrome.runtime.sendMessage({ type: 'get_download_state' }, console.log);
```

**Manual Token Check:**
```javascript
// On Filevine page console
localStorage.getItem('fv_access_token');
// or
Object.keys(localStorage).filter(k => k.includes('token'));
```

**Test API Call:**
```javascript
// In popup console (after connected)
chrome.runtime.sendMessage({ 
  type: 'get_projects', 
  limit: 10 
}, console.log);
```

### Common Issues & Solutions

See `.ai/TROUBLESHOOTING.md` for detailed solutions to common problems.

---

## Test Results Template

```
Date: ___________
Tester: ___________
Browser: Chrome/Edge Version: ___________

Test Suite 1: Installation
- [ ] Test 1.1: Extension Loads
- [ ] Test 1.2: IndexedDB Initializes

Test Suite 2: Content Script
- [ ] Test 2.1: Content Script Loads
- [ ] Test 2.2: Token Extraction Setup

Test Suite 3: Authentication
- [ ] Test 3.1: Disconnected State
- [ ] Test 3.2: Token Detection
- [ ] Test 3.3: Background Processes Tokens
- [ ] Test 3.4: Connected State

Test Suite 4: API Communication
- [ ] Test 4.1: Get Projects
- [ ] Test 4.2: Project Search
- [ ] Test 4.3: Get Documents

Test Suite 5: Downloads
- [ ] Test 5.1: Queue Download
- [ ] Test 5.2: Download Progress
- [ ] Test 5.3: File Storage

Test Suite 6: Error Handling
- [ ] Test 6.1: API Errors
- [ ] Test 6.2: Auth Errors
- [ ] Test 6.3: Invalid Messages

Test Suite 7: Edge Cases
- [ ] Test 7.1: Multiple Tabs
- [ ] Test 7.2: Service Worker Restart
- [ ] Test 7.3: Large Files

Issues Found:
1. 
2. 
3. 

Notes:
```

---

## Next Steps After Testing

1. **Document Issues**: Add any bugs found to `.ai/TROUBLESHOOTING.md`
2. **Fix Critical Bugs**: Address any blocking issues
3. **Update Documentation**: Update docs if behavior differs from expectations
4. **Plan Phase 2**: Based on test results, prioritize Phase 2 features
