---
model: sonnet
---

# /tas-e2e-mobile $ARGUMENTS

Role: SE / QA
Generate Detox E2E test scripts from an E2E Scenario markdown file.

## IMPORTANT — Layer 3: Mobile E2E Scripts
- Create Detox test scripts from E2E-Scenario (markdown)
- Scripts located in `apps/mobile/e2e/flows/`
- REUSE helpers from Layer 2 functional tests (`features/`)
- Chain functional test steps into end-to-end flows

## Actions

### Step 1: Identify Scenario
1. `$ARGUMENTS` is path to `E2E-Scenario-*.md`
2. If not provided: scan `docs/e2e-scenarios/E2E-Scenario-*.md`
3. List scenarios and ask user to pick

### Step 2: Check Prerequisites
1. Check `apps/mobile/` exists. If not → report:
   > "Mobile app doesn't exist. If project only has web, use `/tas-e2e-web`."
   > STOP, DO NOT create file.
2. Read scenario file to get:
   - Scenario steps and flow
   - FT ID references ("Builds on FT IDs" column)
   - FT Reuse Map (section at end)
   - Test data per environment
   - Scenario type (single-stack / cross-stack)

### Step 3: Find Functional Test Helpers
From FT Reuse Map:
1. Find each source file in `apps/mobile/e2e/features/`
2. Verify helper functions exist
3. If helper missing → create stub with `// TODO: implement helper`
4. Build import map: FT ID → file path → function name

### Step 4: Generate E2E Script

**File output**: `apps/mobile/e2e/flows/{scenario-slug}.e2e.ts`

**Structure**:
```typescript
/**
 * E2E Flow: {Scenario Name}
 * Scenario: {Scenario_ID}
 * Features: {Feature_IDs comma-separated}
 * Type: {single-stack | cross-stack}
 *
 * Generated by /tas-e2e-mobile
 * Spec: {path to E2E-Scenario-*.md}
 */

import { device, element, expect, by, waitFor } from 'detox';
import { TEST_IDS } from '../test-ids';
import { loadTestData, getCredentials } from '../helpers/data-loader';
import { login, logout, navigateToTab } from '../helpers/test-utils';

// Layer 2 helpers (reuse from functional tests)
import { fillLoginForm, verifyLoginSuccess } from '../features/{feature-slug}/helpers';
import { viewList } from '../features/{feature-slug-2}/helpers';

const testData = loadTestData();

describe('E2E Flow: {Scenario Name}', () => {
  beforeAll(async () => {
    await device.launchApp({ newInstance: true });
  });

  // Main Flow
  describe('{PROJECT}_E2E_001_H: {Flow Title}', () => {
    it('Step 1: {Action}', async () => {
      // Reuses: AL_F002_AC1_FT_001_H
      const creds = getCredentials();
      await fillLoginForm(creds.email, creds.password);
      await verifyLoginSuccess();
    });

    it('Step 2: {Action}', async () => {
      // Reuses: AL_F003_AC1_FT_001_H
      await viewList();
    });

    it('Step 3: {New logic - no FT reference}', async () => {
      await element(by.id(TEST_IDS.SCAN.SCREEN.CAMERA)).tap();
    });
  });

  // Alternate Flow
  describe('{PROJECT}_E2E_002_N: {Alternate Flow}', () => {
    it('should handle {error condition}', async () => {});
  });
});
```

### Step 5: Update package.json Script
```json
"e2e:flow:{scenario-slug}": "detox test --configuration ios.sim.debug --testPathPattern='e2e/flows/{scenario-slug}'"
```

### Step 6: Generate Execution Report (Optional)
After running, generate from `.tas/templates/E2E-Execution-Report.md`:
- Summary metrics
- Results by test ID
- Failed test details
- Performance metrics
- AC coverage analysis

## File Structure Output
```
apps/mobile/e2e/flows/
├── {scenario-1-slug}.e2e.ts
├── {scenario-2-slug}.e2e.ts
└── ...
```

## Reuse Strategy
```
Layer 2 (features/)          Layer 3 (flows/)
┌───────────────────┐       ┌──────────────────────┐
│ helpers.ts        │──────>│ {scenario}.e2e.ts    │
│  - fillLoginForm()│       │  import { fillLogin }│
│  - verifyLogin()  │       │  import { viewList } │
└───────────────────┘       │                      │
┌───────────────────┐       │  Step 1: fillLogin() │
│ helpers.ts        │──────>│  Step 2: viewList()  │
│  - viewList()     │       │  Step 3: new logic   │
└───────────────────┘       └──────────────────────┘
```

## Run Tests
```bash
yarn e2e:flow:{scenario-slug}
npx detox test --configuration ios.sim.debug --testPathPattern='e2e/flows/'
npx detox test --configuration android.emu.debug --testPathPattern='e2e/flows/{scenario}'
```

## Principles
- MUST reuse helpers from Layer 2 when possible
- Each step in E2E flow should correspond to 1 functional test helper
- Steps without FT reference → write new logic in flow file
- Scripts MUST be runnable from CLI
- If `apps/mobile/` doesn't exist → STOP, DO NOT create file
- describe block uses full E2E ID for grep-ability
- Import paths: relative from `flows/` up to `features/`
