Claim types: EXPENSES, MEAL, MILEAGE, OT. Export excludes local MongoDB data and claim file upload blobs. Co-authored-by: Cursor <cursoragent@cursor.com>
4.3 KiB
4.3 KiB
E2E Testing Setup Complete ✅
Playwright end-to-end tests have been added to the project.
What Was Added
Configuration
playwright.config.ts- Main config with auto-start dev serverpackage.json- Added test scripts (test:e2e,test:e2e:ui,test:e2e:debug).gitignore- Excluded test results and reports
Test Files (5 test suites)
e2e/smoke.spec.ts- Homepage and navigation smoke testse2e/claim-form-mileage.spec.ts- Mileage claim end-to-end tests- Full form submission
- Date validation (period bounds)
- Total calculation verification
e2e/claim-form-expenses.spec.ts- Expenses claim tests- Multiple line items
- Numeric month input (5 → MAY)
e2e/claim-form-ot.spec.ts- Overtime claim tests- DD/MM/YYYY date format
- Validation for month-only rejection
e2e/claim-form-meal.spec.ts- Meal & Accommodation tests- Time input formatting
- Date range support
Component Updates
AdminClaimForm.jsx- Updateddata-testidfromitem-row-Ntoline-item-Nfor consistency
Quick Start
1. Install Playwright Browsers
cd frontend
npx playwright install
2. Run Tests
# Headless (CI mode)
yarn test:e2e
# Interactive UI mode (recommended for development)
yarn test:e2e:ui
# Debug mode (step through tests)
yarn test:e2e:debug
3. Run Specific Test Suite
npx playwright test claim-form-mileage.spec.ts
Test Coverage
✅ Implemented
- Claim form creation (all 4 types: Expenses, Mileage, OT, Meal)
- Date input validation
- Period bounds checking (e.g., can't enter Dec date in May claim)
- Format validation (DD/MM/YYYY for mileage/OT, month-only for expenses)
- Total calculations (mileage KM × rate + toll + parking)
- Preview iframe updates
- Save functionality
⏳ TODO (Future Enhancements)
- Authentication flows (login/logout)
- Excel export download
- PDF preview verification
- Import existing claims
- Edit claim workflow
- Attachment upload/download
- Claims list filtering/sorting
CI Integration
Add this to .github/workflows/e2e.yml:
name: E2E Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: cd frontend && yarn install
- name: Install Playwright browsers
run: cd frontend && npx playwright install --with-deps
- name: Start backend
run: |
cd backend
python -m venv venv
source venv/bin/activate
pip install -r requirements.txt
python server.py &
- name: Run E2E tests
run: cd frontend && yarn test:e2e
- name: Upload test report
if: failure()
uses: actions/upload-artifact@v3
with:
name: playwright-report
path: frontend/playwright-report/
Best Practices
- Use
data-testidfor stable selectors (already added to form) - Use
await expect()with built-in retry instead ofwaitForTimeout() - Test user flows, not implementation details
- Keep tests independent - each test should work standalone
- Use page objects for complex, reused interactions
Example: Running Your First Test
cd frontend
# Install browsers (one-time setup)
npx playwright install
# Run mileage claim tests in UI mode
yarn test:e2e:ui e2e/claim-form-mileage.spec.ts
The UI mode lets you:
- See tests run in real browser
- Time-travel through test steps
- Inspect DOM at each step
- Debug failing tests visually
Debugging Failed Tests
When a test fails:
- Check screenshots:
frontend/test-results/<test-name>/test-failed-1.png - View trace:
npx playwright show-trace test-results/<folder>/trace.zip - Run in headed mode:
npx playwright test --headed --debug - Check terminal output for assertion errors
Next Steps
- Run
yarn test:e2e:uito see tests in action - Add authentication tests when auth is implemented
- Extend tests to cover Excel export and PDF verification
- Add to CI pipeline for automated regression testing
See frontend/e2e/README.md for detailed documentation.