Frontend E2E Tests
Status: ✅ ALL 22 TESTS PASSING Framework: Playwright v1.57.0 Last Updated: 2025-12-13
Overview
Automated E2E tests that mirror backend HTTP test files (auths.http, employers.http, users.http) through the browser UI against the real API.
Test Summary
| File | Tests | Status | Backend Reference |
|---|---|---|---|
auth.spec.ts | 9 | ✅ Pass | auths.http |
employer.spec.ts | 5 | ✅ Pass | employers.http |
users.spec.ts | 8 | ✅ Pass | users.http |
| Total | 22 | ✅ Pass |
Running Tests
Prerequisites
# Terminal 1: Start backend
cd backend && dotnet watch run --project SafetyApp.Api
# Terminal 2: Start frontend
cd frontend && ng serve
Commands
cd frontend
# Run all tests
pnpm e2e
# Run with UI (debug mode)
pnpm e2e:ui
# View HTML report
pnpm e2e:report
Zed Tasks
- E2E: Run All Tests - Run all Playwright tests
- E2E: Run Tests (UI Mode) - Open Playwright UI for debugging
- E2E: Show Report - View HTML test report
Test Cases
Auth Tests (9) - mirrors auths.http
| TC | Description | Backend TC |
|---|---|---|
| TC-1.1 | Valid login redirects to dashboard | 1.1 |
| TC-1.2 | Invalid email format prevents submission | 1.2 |
| TC-1.3 | Wrong password shows Thai error message | 1.3 |
| TC-1.4 | Non-existent email shows Thai error message | 1.4 |
| TC-1.5 | Empty email prevents submission | 1.5 |
| TC-1.6 | Empty password prevents submission | 1.6 |
| TC-2.1 | Logout redirects to login page | 2.1 |
| TC-8.1 | Admin login redirects to employer settings | 8.1 |
| TC-8.3 | Contractor login redirects to my-tasks | 8.3 |
Employer Tests (5) - mirrors employers.http
| TC | Description | Backend TC |
|---|---|---|
| TC-EMP-1.1 | Admin can view employer settings | 1.1 |
| TC-EMP-1.4 | Contractor cannot access employer settings | 1.4 |
| TC-EMP-2.1 | Admin can save employer settings | 2.1 |
| - | All employer settings tabs accessible | (bonus) |
| - | Refresh button reloads employer data | (bonus) |
Users Tests (8) - mirrors users.http
| TC | Description | Backend TC |
|---|---|---|
| TC-USR-1 | Admin can view user management page | 1.1 |
| TC-USR-2 | Admin can create new user (WorkspaceOwner) | 2.1 |
| TC-USR-3 | Admin can edit existing user | 4.1 |
| TC-USR-4 | Admin can send invitation email | 7.1 |
| TC-USR-5 | Admin can delete user (handles FK constraint) | 5.1, 5.2 |
| TC-USR-6 | Purchasing can only see contractor users | 9.1 |
| TC-USR-7 | Contractor cannot access user management | 2.4 |
| TC-USR-8 | Purchasing can create contractor user | 9.2 |
Backend → UI Test Mapping
Why not all 80 backend tests?
The backend HTTP test files contain 80 tests total (56 auth + 24 employer), but only ~14 are UI-testable:
| Category | Reason NOT UI-testable |
|---|---|
| TC 1.7-1.15 | API edge cases (SQL injection, null values, long strings) |
| TC 2.2-2.3 | Logout edge cases (cookie manipulation) |
| TC 3.x | Refresh token (handled internally by HTTP interceptor) |
| TC 4.x | Create account (feature disabled in UI) |
| TC 6.x | Search role types (internal API, no direct UI) |
| TC 7.x | Multi-tenancy (X-Domain header set automatically) |
File Structure
frontend/
├── playwright.config.ts # Playwright configuration
├── package.json # Scripts: e2e, e2e:ui, e2e:report
├── e2e/
│ ├── auth.spec.ts # Auth E2E tests (9)
│ ├── employer.spec.ts # Employer E2E tests (5)
│ ├── users.spec.ts # Users E2E tests (8)
│ └── fixtures/
│ └── test-data.ts # Test credentials & data
Test Data
Test credentials are defined in e2e/fixtures/test-data.ts:
| Role | Redirect | |
|---|---|---|
| Admin | tn@thaiscada.com | /tools/settings/employer |
| Purchasing | safety-purchasing@outlook.com | /tasks/my-tasks |
| Contractor | safety-contractor1-0@outlook.com | /tasks/my-tasks |
Completed Phases
| Phase | Feature | Tests | Status |
|---|---|---|---|
| 1 | Authentication | 9 | ✅ Completed |
| 2 | Employer Settings | 5 | ✅ Completed |
| 3 | User Management | 8 | ✅ Completed (2025-12-13) |
Notes
- Admin creates WorkspaceOwner users (Purchasing role creates contractors)
- Delete test handles FK constraint gracefully for invited users
- TC-USR-8 tests Purchasing role creating contractor with company info