# HVAC Community Events - E2E Tests

## Trainer Journey Testing

This directory contains end-to-end tests for the complete Trainer User Journey as defined in the project requirements.

### Quick Start

1. Verify your setup:
   ```bash
   cd tests/e2e
   ./verify-setup.sh
   ```

2. Run the trainer journey tests:
   ```bash
   cd ../..  # Go to wordpress-dev directory
   ./bin/run-tests.sh --trainer-journey
   ```

3. Run certificate tests (manual guided testing):
   ```bash
   cd ../..  # Go to wordpress-dev directory
   ./bin/run-certificate-tests.sh generation  # Test certificate generation
   ./bin/run-certificate-tests.sh reports     # Test certificate reports
   ```

### Test Coverage

The test suite covers the following trainer journey steps:

- ✅ **Login & Authentication** (Steps 1-2)
- ✅ **Dashboard Access** (Step 3)
- ✅ **Event Management** (Step 4)
  - Create events (Step 4a)
  - View event list (Step 4b)
  - Modify events (Step 4c)
  - Delete events (Step 4d)
- ✅ **Event Details View** (Step 5)
- ⏳ **Event Statistics** (Step 6 - In Progress)
- ⏳ **Order & Attendee Details** (Steps 7-8 - Pending)
- ⏳ **Email Communication** (Step 9 - Phase 2)
- ⏳ **Attendee Check-in** (Step 10)
- ✅ **Certificate Generation** (Step 11 - Now Implemented!)
  - Generate certificates for attendees
  - View and manage certificates
  - Email and revoke certificates

### Project Structure

```
tests/e2e/
├── pages/              # Page Object Model classes
│   ├── BasePage.ts
│   ├── LoginPage.ts
│   ├── DashboardPage.ts
│   ├── CreateEventPage.ts
│   ├── EventSummaryPage.ts
│   ├── ModifyEventPage.ts
│   └── CertificatePage.ts     # NEW!
├── utils/               # Utility classes
│   ├── Config.ts         # NEW! Centralized configuration
│   └── CertificateTestData.ts # NEW! Certificate test data
├── data/               # Test data
│   ├── test-users.ts
│   └── test-events.ts
├── docs/               # Documentation
│   └── trainer-journey-testing.md
├── test-plan/          # Test planning documents
│   └── trainer-journey-verification.md
├── trainer-journey.test.ts  # Main test suite
├── certificate-generation-manual.test.ts  # NEW! Manual certificate tests
├── certificate-management-manual.test.ts  # NEW! Manual certificate tests
├── CERTIFICATE_TESTING_GUIDE.md  # NEW! Certificate testing documentation
├── verify-setup.sh     # Setup verification script
└── README.md          # This file
```

### Running Specific Tests

```bash
# Run all E2E tests
./bin/run-tests.sh --e2e

# Run only trainer journey tests
./bin/run-tests.sh --trainer-journey

# Run specific test scenarios
./bin/run-tests.sh --e2e --grep @login
./bin/run-tests.sh --e2e --grep @dashboard
./bin/run-tests.sh --e2e --grep @create-event

# Run certificate tests
./bin/run-certificate-tests.sh generation
./bin/run-certificate-tests.sh reports
```

### Test Results

- Console output shows real-time test progress
- Screenshots saved in `test-results/screenshots/`
- Test reports generated in `test-results/`

### Latest Test Summary (2025-05-20)

The trainer journey tests are now **✅ PASSING** with the following coverage:

1. **Login and Dashboard Access**: Successfully tests trainer login and dashboard navigation
2. **Event Management**: Complete coverage of event CRUD operations:
   - Create new events with all required fields
   - View events in My Events page (both upcoming and past)
   - Modify existing events
   - Delete events with confirmation
3. **Event Details**: Views individual event pages
4. **Certificate Generation**: Now implemented!
   - Generate certificates for event attendees
   - Manage certificates (view, email, revoke)
   - Filter and paginate certificate lists

Key findings:
- Events created during testing appear in My Events but not in main dashboard (application issue)
- TinyMCE editor requires special handling in tests
- Multiple fallback strategies implemented for form fields
- Certificate generation properly handles checked-in vs. non-checked-in attendees

For complete details on certificate testing, see the [Certificate Testing Guide](CERTIFICATE_TESTING_GUIDE.md).

### Prerequisites

1. **Environment Setup**
   - `.env` file with staging server credentials
   - Node.js and npm installed
   - Playwright dependencies installed

2. **Staging Server Requirements**
   - Test user `test_trainer` exists
   - Required plugins activated
   - HVAC Community Events plugin deployed

### Troubleshooting

If tests fail, check:

1. **Network Issues**
   - Staging server is accessible
   - No proxy/firewall blocking

2. **Authentication Issues**
   - Test user credentials are correct
   - User has proper role assigned

3. **Element Not Found**
   - Page structure may have changed
   - Update selectors in page objects

4. **Certificate Generation Issues**
   - Verify events have attendees
   - Check if attendees have proper check-in status
   - Review certificate storage permissions

### Contributing

When adding new tests:

1. Use the Page Object Model pattern
2. Add test data to centralized files
3. Update documentation
4. Follow existing naming conventions
5. Use the Config utility for environment variables

### Support

For issues or questions:
- Check the troubleshooting guide above
- Review test output and screenshots
- Check staging server logs
- Contact the development team