# E2E Test Suite Review — Overview and Decisions

> This document captures the full context, findings, and decisions from a deep review of
> the E2E test suite introduced in PR #348. It is the source of truth for anyone picking
> up this work later.

---

## Why This Review Was Done

PR #348 introduces 325 Playwright E2E tests across 17 spec files and 1 smoke file.
The tests were generated by an AI agent (`pantheon-ai[bot]`) against an *assumed* UI
contract rather than the running application. A production-focused fork (the "origin"
repo) has diverged from upstream by 58 commits representing real-world bug fixes,
feature additions, and UX improvements discovered through actual use.

This review was conducted to:

1. Assess every E2E test against the **actual application behavior** (Router.tsx,
   component structure, feature availability)
2. Fix objectively incorrect test assumptions (route patterns) that violate the
   Salesforce Lightning URL specification the app follows
3. Document the gap between what the tests cover and what production users have
   encountered (origin commit analysis)
4. Create actionable tracking documents so frontend developers can systematically
   bring the tests to a passing state

---

## The Two Repos

| Repo | Role | URL |
|------|------|-----|
| **Upstream** (`pingcap-inc/MetaDrivenPlatform4AI`) | Barebones platform, developed by developers | Core features, unit tests, typed errors, code quality |
| **Origin** (`ywang-official/MetaDrivenPlatform4AI`) | Production fork, developed by end users | Real-world layouts, campaign fixes, flow triggers, validation rules, formula engine, pagination, and more |

Both repos share the same `Router.tsx` and frontend architecture. The divergence is
in features, bug fixes, and configuration — not in routing or component structure.

**Merge base**: `0b3d168` (58 commits on origin not in upstream)

---

## Critical Issues Discovered

### Issue 1: 200+ Missing `data-testid` Attributes

The tests reference over 200 `data-testid` selector values (`login-form`,
`email-input`, `accounts-table`, `new-button`, `nav-dashboard`, etc.). The actual
frontend — in **both** upstream and origin — has only **6 production `data-testid`
values**:

| File | `data-testid` value |
|------|---------------------|
| `components/layout/TopBar.tsx` | `mobile-menu-toggle` |
| `components/formula/FormulaEditor.tsx` | `formula-editor` |
| `features/flows/components/FieldMappingBuilder.tsx` | `field-mapping-builder` (4 usages) |

Every other selector the tests depend on does not exist. This means **100% of tests
will fail** on selector resolution before they even test behavior.

**Decision**: Leave selectors as-is. The tests serve as a specification of what
`data-testid` attributes the frontend *should* have. A separate `SELECTOR_AUDIT.md`
catalogs every needed selector so frontend developers can add them systematically.
As selectors are added, tests will progressively start passing.

**Rationale**: Rewriting 200+ selectors to use ARIA roles or text matchers would be
a massive effort that produces more brittle tests. The `data-testid` approach is
the industry standard for E2E stability. It is better to invest that effort in
adding the attributes to the frontend once.

### Issue 2: Route Pattern Mismatch (FIXED)

The tests assume conventional SPA routes:

| Test assumed | Actual app route | Salesforce Lightning equivalent |
|---|---|---|
| `/accounts` | `/object/Account` | `/lightning/o/Account/list` |
| `/contacts` | `/object/Contact` | `/lightning/o/Contact/list` |
| `/opportunities` | `/object/Opportunity` | `/lightning/o/Opportunity/list` |
| `/dashboard` | `/dashboards` | N/A (app-specific) |
| `/settings/objects` | `/setup/objects` | N/A (setup routing) |
| `/custom-objects` | `/object/{apiName}` | `/lightning/o/{apiName}/list` |
| `/reports` | `/analytics/report-builder` | N/A |
| `/dashboards/1` | `/dashboard/{id}` | N/A |

NexusCRM follows the Salesforce Lightning URL convention (`/lightning/o/{Object}/list`
for object homes, `/lightning/r/{Object}/{Id}/view` for record detail). The app also
has a shorter alias pattern (`/object/{Object}` and `/object/{Object}/{Id}`). Both
are defined in `Router.tsx`.

The tests used generic SPA routes (`/accounts`, `/contacts`) that don't exist in
either repo. This was fixed across all 18 spec files.

**Decision**: Fix all routes to match the app's actual routing.
See `01-ROUTE-FIXES.md` for the complete per-file changelog.

### Issue 3: Login Form Structure Mismatch

Tests expect `data-testid="email-input"`, `data-testid="password-input"`, and
`data-testid="login-button"`. The actual `LoginScreen.tsx` uses controlled React
inputs with **no `id`, `name`, or `data-testid` attributes**.

The tests also assume features that don't exist: "remember me" checkbox, "forgot
password" link, "help/support" link, and "password visibility toggle". The login
page has three modes (Backend, Salesforce OAuth, Advanced Token) — tests only
cover the backend mode.

**Decision**: Leave as-is. These are selector issues (covered by Issue 1) and
feature wishlist items (covered by Issue 4).

### Issue 4: Tests for Non-Existent Features (~65 tests)

The following features are tested but not implemented in either repo:

| Spec file | Feature assumed | Status |
|---|---|---|
| `auth.spec.ts` | Remember me, forgot password, help link, password toggle | Not implemented |
| `auth.spec.ts` | `readonly@nexuscrm.test` user | No readonly user in bootstrap |
| `setup-landing.spec.ts` | Setup wizard, onboarding tips, welcome message | Not implemented |
| `contacts-crud.spec.ts` | Activities timeline, add activity | Not implemented |
| `opportunities-crud.spec.ts` | Pipeline metrics (weighted, stage breakdown) | Not implemented |
| `search.spec.ts` | Advanced search with save/load, recent searches | Not implemented |
| `dashboard-view.spec.ts` | Funnel, gauge, list, report widget types | Only chart/table/metric exist |
| `dashboard-creation.spec.ts` | Dashboard templates | Not implemented |
| `reports.spec.ts` | Scheduling, subscriptions, PDF/Excel export, folders | Not implemented |
| `navigation.spec.ts` | App-wide breadcrumbs | Only in Setup pages |

**Decision**: Leave as-is. These tests serve as a feature specification and wishlist.
When features are implemented, the tests are already written.

### Issue 5: Code Bugs in Tests

1. **`setup-landing.spec.ts`**: "should display setup wizard" references
   `authenticatedPage` but the test fixture provides `guestPage`
2. **`reports.spec.ts`**: Typo `authuncatedPage` instead of `authenticatedPage`
3. **`smoke.spec.ts`**: Uses `input[name="username"]` but login form has no
   `name` attributes

**Decision**: Leave as-is. These will surface naturally when tests are run and are
trivial to fix at that point.

---

## Per-Spec Assessment Summary

| # | Spec file | Tests | Salvageable | Non-existent features | Route fix? |
|---|---|---|---|---|---|
| 1 | `auth.spec.ts` | 24 | 8 | 6 | Yes |
| 2 | `navigation.spec.ts` | 18 | 6 | 4 | Yes |
| 3 | `accounts-crud.spec.ts` | 28 | 15 | 5 | Yes |
| 4 | `contacts-crud.spec.ts` | 24 | ~20 | 2 | Yes |
| 5 | `opportunities-crud.spec.ts` | 26 | ~18 | 5 | Yes |
| 6 | `search.spec.ts` | 16 | 4 | 7 | Yes |
| 7 | `setup-landing.spec.ts` | 14 | 2 | 10 | Yes |
| 8 | `object-manager.spec.ts` | 20 | 10 | 3 | Yes |
| 9 | `object-creation.spec.ts` | 16 | 8 | 0 | Yes |
| 10 | `object-fields.spec.ts` | 18 | 12 | 2 | Yes |
| 11 | `dashboard-list.spec.ts` | 14 | ~8 | ~5 | No |
| 12 | `dashboard-view.spec.ts` | 16 | ~8 | ~5 | Yes |
| 13 | `dashboard-creation.spec.ts` | 18 | ~10 | ~5 | No |
| 14 | `reports.spec.ts` | 22 | 8 | 8 | Yes |
| 15 | `flows.spec.ts` | 20 | 15 | 0 | No |
| 16 | `approvals.spec.ts` | 22 | ~14 | ~4 | No |
| 17 | `approval-queue.spec.ts` | 22 | ~14 | ~4 | No |
| 18 | `smoke.spec.ts` | 7 | 7 | 0 | Yes |
| | **TOTAL** | **325** | **~177** | **~75** | |

"Salvageable" means the test concept is valid and will work once selectors are added.
"Non-existent features" means the test exercises functionality not yet implemented.

---

## Files in This Directory

| File | Purpose |
|------|---------|
| `00-OVERVIEW.md` | This file. Master context, decisions, and rationale. |
| `01-ROUTE-FIXES.md` | Per-file changelog of every route pattern fix. |
| `02-SELECTOR-AUDIT.md` | Methodology and detailed findings of the selector audit. |
| `03-ORIGIN-COVERAGE-GAPS.md` | Full commit-by-commit analysis of origin divergence and test gaps. |

Related top-level documents:

| File | Purpose |
|------|---------|
| `tests/e2e/SELECTOR_AUDIT.md` | Actionable backlog: every `data-testid` needed, grouped by component. |
| `tests/e2e/ORIGIN_COVERAGE_GAPS.md` | Actionable list of test gaps from production use. |
