# Testing and Operations

## 1. Test Types

### 1.1 Smoke Tests

- Page loads without console exceptions.
- API key prompt/display behavior is correct.
- Dashboard refresh updates timestamp and status.

### 1.2 Functional Tests

- API test reads typed symbol and returns corresponding data.
- Watchlist selectors persist selected values after reload.
- `None` selection suppresses card fetch.
- Add/remove ticker operations update UI and persistence.

### 1.3 Defensive Tests

- Missing DOM element paths do not crash app.
- Undefined/global init order does not break logging.
- Empty watchlist produces clear UI message.

## 2. Built-in Test Utilities

Use debug controls:

- `runSelfTests()`
- `testApiCalls()`
- `testWatchlistIntegrity()`

## 3. Recommended Tooling

- ESLint (`no-undef`, `no-unused-vars`, `eqeqeq`)
- Prettier for formatting consistency
- Browser DevTools (Network + Console + Application tabs)

## 4. Operational Runbook

### Startup

1. Load page.
2. Verify API key available.
3. Run refresh.
4. Confirm panel updates and no fatal errors.

### Incident Triage

1. Enable debug mode.
2. Reproduce issue.
3. Capture console and debug panel logs.
4. Identify failing component from message context.
5. Validate storage values for `mp_prefs2` and `mp_wl2`.

### Recovery

- Reset key via UI if authentication issue.
- Recreate watchlists if storage corruption detected.
- Reload with cleared cache/storage for clean baseline.

## 5. Regression Checklist

- [ ] API test symbol is not hardcoded.
- [ ] No `undefined` watchlist names in logs.
- [ ] Watchlist cards render expected symbols.
- [ ] Preferences reload exactly what was saved.
- [ ] Partial failures report the exact failed operation.
