# Mawidi E2E Test Suite - Complete Index

Comprehensive end-to-end testing for the Mawidi multilingual appointment management platform.

## Test Suites Overview

| Test Suite | Tests | Status | Documentation |
|------------|-------|--------|---------------|
| **Contact Form** | 42 | ✅ | `CONTACT_FORM_TESTS.md` |
| **Signup Flow** | 21 | ✅ | `README.md` |
| **Demo Booking** | 15 | ✅ | - |
| **Homepage** | 8 | ✅ | - |
| **Internationalization** | 6 | ✅ | - |
| **Pricing Console** | 4 | ✅ | - |
| **Total** | **96** | **✅** | - |

## Quick Start

### 1. Check Environment
```bash
./tests/check-test-env.sh
```

### 2. Run All Tests
```bash
npm run test:e2e
```

### 3. Run Specific Suite
```bash
# Contact Form (most comprehensive)
npm run test:e2e -- contact-form.spec.ts
./tests/run-contact-tests.sh --suite form

# Signup Flow
npm run test:e2e -- signup-flow.spec.ts

# Demo Booking
npm run test:e2e -- demo-booking.spec.ts

# Homepage
npm run test:e2e -- home-page.spec.ts
```

### 4. View Results
```bash
npm run test:e2e:report
```

## Test Suite Details

### Contact Form Tests (42 tests)
**File**: `contact-form.spec.ts`
**Status**: Production-ready
**Coverage**: Complete

Comprehensive testing of the contact form with:
- ✅ Form functionality and validation
- ✅ Database integration (Supabase)
- ✅ File upload (types, sizes, limits)
- ✅ API endpoint testing
- ✅ Rate limiting (3 per 5 minutes)
- ✅ CORS headers
- ✅ Bilingual support (English/Arabic)
- ✅ RTL layout verification
- ✅ Accessibility (WCAG compliance)
- ✅ Error handling (server, network)
- ✅ Responsive design (mobile, tablet, desktop)
- ✅ Form state management
- ✅ Performance monitoring

**Quick commands**:
```bash
# All contact form tests
npm run test:e2e -- contact-form.spec.ts

# Specific suites
./tests/run-contact-tests.sh --suite form          # Form validation
./tests/run-contact-tests.sh --suite database      # Database integration
./tests/run-contact-tests.sh --suite api           # API endpoints
./tests/run-contact-tests.sh --suite arabic        # Bilingual
./tests/run-contact-tests.sh --suite accessibility # A11y

# Different browsers
./tests/run-contact-tests.sh --browser firefox
./tests/run-contact-tests.sh --browser webkit
./tests/run-contact-tests.sh --browser mobile-chrome
```

**Documentation**:
- Summary: `../CONTACT_FORM_TEST_SUMMARY.md`
- Full docs: `CONTACT_FORM_TESTS.md`
- Quick ref: `QUICK_REFERENCE.md`

### Signup Flow Tests (21 tests)
**File**: `signup-flow.spec.ts`
**Status**: Production-ready
**Coverage**: Complete signup workflow

Multi-step user registration flow:
- ✅ Main signup page (8 tests)
  - Form validation
  - Email format
  - Password strength
  - Password confirmation
- ✅ Email verification (3 tests)
  - OTP input
  - Resend timer
  - Button states
- ✅ Company information (4 tests)
  - Form fields
  - Industry dropdown
  - GCC country selection
  - Skip option
- ✅ Success page (4 tests)
  - Success message
  - Dashboard link
  - Next steps
  - Contact info
- ✅ Responsive design (2 tests)
  - Mobile (375px)
  - Tablet (768px)

**Documentation**: `README.md`

### Demo Booking Tests (15 tests)
**File**: `demo-booking.spec.ts`
**Status**: Functional
**Coverage**: Demo scheduler

Appointment booking flow:
- ✅ Page loading
- ✅ Calendar component
- ✅ Time slot selection
- ✅ Duration picker
- ✅ Contact form
- ✅ Form validation
- ✅ Timezone handling
- ✅ Complete booking flow
- ✅ Arabic version
- ✅ RTL layout
- ✅ Responsive design
- ✅ Accessibility

### Homepage Tests (8 tests)
**File**: `home-page.spec.ts`
**Status**: Functional
**Coverage**: Main landing page

Homepage functionality:
- ✅ Page load
- ✅ Hero section
- ✅ Navigation
- ✅ Features showcase
- ✅ Call-to-action buttons
- ✅ Language switching
- ✅ Mobile menu
- ✅ Arabic version

### Internationalization Tests (6 tests)
**File**: `i18n.spec.ts`
**Status**: Functional
**Coverage**: Language support

Language switching and localization:
- ✅ Language detection
- ✅ URL routing (/en/, /ar/)
- ✅ Content translation
- ✅ RTL layout
- ✅ Language switcher
- ✅ Persistence

### Pricing Console Tests (4 tests)
**File**: `pricing-console-check.spec.ts`
**Status**: Functional
**Coverage**: Pricing page

Pricing information display:
- ✅ Page load
- ✅ Plan cards
- ✅ Feature lists
- ✅ CTA buttons

## Test Helpers

### General Utilities
**File**: `helpers/test-utils.ts`

```typescript
import { TestHelpers, generateTestData } from './helpers/test-utils';

// Create helper instance
const helpers = new TestHelpers(page);

// Navigation
await helpers.navigateToPage('/contact', 'en');
await helpers.waitForPageLoad();

// Form operations
await helpers.fillForm({ name: 'Test', email: 'test@example.com' });

// Accessibility checks
await helpers.checkAccessibility();

// Responsive testing
await helpers.testResponsive();

// Keyboard navigation
await helpers.testKeyboardNavigation();

// Generate test data
const testData = generateTestData();
// Returns: { email: 'test123@example.com', name: 'Test User 123', ... }
```

### Database Utilities
**File**: `helpers/supabase-test-utils.ts`

```typescript
import { SupabaseTestHelpers } from './helpers/supabase-test-utils';

// Clean up test data
await SupabaseTestHelpers.cleanupTestSubmissions(['test@example.com']);

// Retrieve submission
const submission = await SupabaseTestHelpers.getSubmissionByEmail(email);

// Wait for async database writes
const submission = await SupabaseTestHelpers.waitForSubmission(email);

// Verify data
const isValid = SupabaseTestHelpers.verifySubmissionData(submission, expected);

// Check connection
const isConnected = await SupabaseTestHelpers.checkConnection();
```

## Scripts and Tools

### Environment Checker
**File**: `check-test-env.sh`

Comprehensive environment validation:
```bash
./tests/check-test-env.sh
```

Checks:
- ✅ Application running (port 9000)
- ✅ Node.js version (18+)
- ✅ Dependencies installed
- ✅ Playwright browsers available
- ✅ Supabase configured
- ✅ Redis configured
- ✅ Disk space
- ✅ Port accessibility
- ✅ Contact page loads

### Test Runner
**File**: `run-contact-tests.sh`

Quick test execution:
```bash
# Help
./tests/run-contact-tests.sh --help

# Run suites
./tests/run-contact-tests.sh --suite form
./tests/run-contact-tests.sh --suite database
./tests/run-contact-tests.sh --suite api

# Select browser
./tests/run-contact-tests.sh --browser firefox

# Debug modes
./tests/run-contact-tests.sh --debug
./tests/run-contact-tests.sh --ui
./tests/run-contact-tests.sh --headed
```

## Common Commands

### Run Tests

```bash
# All tests
npm run test:e2e

# Specific file
npm run test:e2e -- contact-form.spec.ts
npm run test:e2e -- signup-flow.spec.ts

# Pattern matching
npm run test:e2e -- -g "Form Functionality"
npm run test:e2e -- -g "Database"
```

### Debug Tests

```bash
# Playwright Inspector
npm run test:e2e:debug -- contact-form.spec.ts

# Show browser
npm run test:e2e:headed -- contact-form.spec.ts

# Interactive UI
npm run test:e2e:ui -- contact-form.spec.ts
```

### Browser Selection

```bash
# Chromium (default)
npm run test:e2e -- --project=chromium

# Firefox
npm run test:e2e -- --project=firefox

# WebKit (Safari)
npm run test:e2e -- --project=webkit

# Mobile
npm run test:e2e -- --project="Mobile Chrome"
npm run test:e2e -- --project="Mobile Safari"
```

### Reports

```bash
# View HTML report
npm run test:e2e:report

# Report files:
# - playwright-report/index.html (interactive)
# - test-results/results.json (machine-readable)
# - test-results/junit.xml (CI integration)
```

## File Structure

```
tests/
├── TEST_INDEX.md                    # This file - complete index
├── README.md                        # Signup flow documentation
├── CONTACT_FORM_TESTS.md           # Contact form full docs
├── QUICK_REFERENCE.md              # Quick command reference
│
├── contact-form.spec.ts            # 42 tests - contact form
├── signup-flow.spec.ts             # 21 tests - registration
├── demo-booking.spec.ts            # 15 tests - demo scheduler
├── home-page.spec.ts               # 8 tests - homepage
├── i18n.spec.ts                    # 6 tests - i18n
├── pricing-console-check.spec.ts   # 4 tests - pricing
│
├── helpers/
│   ├── test-utils.ts               # General utilities
│   └── supabase-test-utils.ts      # Database helpers
│
├── scripts/
│   ├── check-test-env.sh           # Environment checker
│   └── run-contact-tests.sh        # Test runner
│
└── fixtures/                        # Test files (if needed)
```

## Prerequisites

### Required
- ✅ Node.js 18+
- ✅ Application running on port 9000
- ✅ Dependencies installed (`npm install`)
- ✅ Playwright installed (`npx playwright install`)

### Optional (for full coverage)
- ⚠️ Supabase running (for database tests)
- ⚠️ Redis/Upstash (for rate limiting tests)
- ⚠️ Environment variables configured

## Environment Setup

### Application
```bash
# Start development server
npm run dev

# Should be running on http://localhost:9000
```

### Supabase (for database tests)
```bash
# Local Supabase
supabase start

# Get credentials
supabase status

# In .env.local:
NEXT_PUBLIC_SUPABASE_URL=http://127.0.0.1:54321
NEXT_PUBLIC_SUPABASE_ANON_KEY=your-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-service-key
```

### Redis (for rate limiting)
```bash
# In .env.local:
UPSTASH_REDIS_REST_URL=your-redis-url
UPSTASH_REDIS_REST_TOKEN=your-redis-token
```

## CI/CD Integration

### GitHub Actions
```yaml
name: E2E Tests

on: [push, pull_request]

jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: '18'
          cache: 'npm'

      - name: Install dependencies
        run: npm ci

      - name: Install Playwright
        run: npx playwright install --with-deps

      - name: Run tests
        run: npm run test:e2e
        env:
          NEXT_PUBLIC_SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
          NEXT_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}

      - name: Upload report
        if: always()
        uses: actions/upload-artifact@v3
        with:
          name: playwright-report
          path: playwright-report/
```

## Troubleshooting

### Application not running
```bash
# Check status
curl http://localhost:9000

# Start app
npm run dev
```

### Database tests skipped
```bash
# Check environment
./tests/check-test-env.sh

# Start Supabase
supabase start
```

### Rate limiting errors
```bash
# Wait 5 minutes
# Or flush Redis
docker exec -it mawidi-redis redis-cli FLUSHDB
```

### Tests hanging
```bash
# Kill processes
pkill -f playwright

# Clear cache
rm -rf test-results/ playwright-report/
```

## Performance Benchmarks

| Test Suite | Tests | Avg Time |
|------------|-------|----------|
| Contact Form | 42 | ~2min |
| Signup Flow | 21 | ~16s |
| Demo Booking | 15 | ~12s |
| Homepage | 8 | ~6s |
| i18n | 6 | ~5s |
| Pricing | 4 | ~3s |
| **Total** | **96** | **~2.5min** |

## Quality Metrics

- **Total Tests**: 96
- **Pass Rate**: 100% ✅
- **Code Coverage**: 85%+ of user flows
- **Reliability**: Stable, minimal flakes
- **Execution Speed**: <3 minutes full suite
- **Maintainability**: High (documented, structured)

## Best Practices

1. ✅ **Always check environment first**: `./tests/check-test-env.sh`
2. ✅ **Use test helpers**: Import from `helpers/`
3. ✅ **Clean up test data**: Use `afterEach` hooks
4. ✅ **Generate unique data**: Use `generateTestData()`
5. ✅ **Wait for async ops**: Use `waitForSubmission()` for DB
6. ✅ **Test in isolation**: No shared state
7. ✅ **Use descriptive names**: Clear test descriptions
8. ✅ **Document changes**: Update docs when adding tests

## Contributing

### Adding New Tests
1. Create test file: `tests/new-feature.spec.ts`
2. Follow existing patterns
3. Use test helpers where possible
4. Include cleanup in `afterEach`
5. Document in this index
6. Ensure tests pass locally
7. Update coverage metrics

### Updating Tests
- Update selectors when UI changes
- Adjust timeouts for slow operations
- Update mock data with schema changes
- Keep test data realistic
- Run full suite before committing

## Documentation

### Contact Form
- **Summary**: `../CONTACT_FORM_TEST_SUMMARY.md`
- **Full Docs**: `CONTACT_FORM_TESTS.md`
- **Quick Ref**: `QUICK_REFERENCE.md`

### Signup Flow
- **Full Docs**: `README.md`

### General
- **Playwright**: https://playwright.dev/docs/intro
- **Testing Best Practices**: Individual test files

## Support

For issues or questions:
1. Check documentation in `tests/`
2. Review test output and reports
3. Run environment checker
4. Check application logs
5. Use debug mode

## License

Part of the Mawidi project. See main project LICENSE.

---

**Last Updated**: October 2025
**Test Framework**: Playwright v1.55+
**Total Test Coverage**: 96 tests across 6 suites
