# Careers Feature Test Plan

Use this plan to validate the new Supabase-backed careers experience, including job listings and application submissions with CV uploads. Tests are grouped by automation level and assume bilingual content (Arabic/English).

## Prerequisites

- Supabase local stack running (`supabase start`) with latest migrations applied (`supabase migration up` or `supabase db reset`).
- `NEXT_PUBLIC_SUPABASE_URL`, `NEXT_PUBLIC_SUPABASE_ANON_KEY`, and `SUPABASE_SERVICE_ROLE_KEY` configured in `.env.local`.
- `JOB_CV_BUCKET` (`job-cvs`) available with 10 MB file limit per migration.
- Seed at least one open job in Supabase (`status = 'open'`, `opening_at` ≤ now, `closing_at` null or future) with populated translation fields.
- Sample CV PDF files for tests: `fixtures/cv-valid.pdf` (<10 MB), `fixtures/cv-too-large.pdf` (>10 MB), `fixtures/cv-invalid.docx`.

## Automated Tests (Playwright MCP)

> Create `tests/careers.spec.ts` and use the Playwright MCP to enumerate scenarios below. Leverage Supabase test helpers if available.

- **Render Open Jobs**
  - Seed an open engineering role with translations and arrays populated.
  - Navigate to `/en/careers`; assert hero loads, job card shows department, contract type, level, salary, and responsibilities/benefits sections.
  - Repeat for `/ar/careers` and verify RTL layout and Arabic copy.

- **Hide Closed Jobs**
  - Seed two jobs: one with `closing_at` in the past, one in the future.
  - Assert only the future job displays in listings.

- **Empty State Messaging**
  - Temporarily mark all jobs `status = 'closed'` (or adjust dates).
  - Verify the empty-state card renders with `openPositionsNone` messaging.

- **Happy Path Application Submission**
  - Mock Supabase admin client or intercept `/api/apply-job` call.
  - Fill form with valid data, upload `cv-valid.pdf`, submit.
  - Assert request payload includes all fields, the modal shows success message, and `jobs` API called once.

- **Validation Errors**
  1. Missing required fields → expect inline browser validation preventing submit.
  2. Invalid email format → expect server 400 with error toast/state.
  3. Non-PDF upload (`cv-invalid.docx`) → expect client alert (copy text).
  4. Oversized PDF (`cv-too-large.pdf`) → expect client alert and no submission.
  5. Reuse slugged job but set `status = 'closed'` → expect server 409 error message.

- **Arabic Form Submission**
  - Switch to `/ar/careers`, submit valid application, assert success message appears in Arabic and API receives `lang=ar`.

- **Resume Upload Cleanup** _(optional, integration)_
  - After submission, query Supabase storage using service role to confirm object created under `{job-slug}/timestamp-...pdf`.
  - Optionally, after test, clean up file via Supabase Admin helpers.

## Manual QA Checklist

- **Database Integrity**
  - Confirm new `careers`, `jobs`, `job_applications` tables exist with expected columns and RLS enabled (`\d+` in psql).
  - Insert job via Supabase Studio and ensure JSON translations persist correctly.

- **Storage Policies**
  - Upload CV manually via API; verify object stored in `job-cvs` bucket, not publicly accessible without signed URL/service role.
  - Attempt unauthenticated GET on stored object; expect access denied.

- **Application Record**
  - After submitting form in browser, verify `job_applications` row contains applicant data, metadata (IP/User-Agent when available), and CV path.

- **Error Handling**
  - Temporarily break Supabase credentials and confirm API returns `503` configuration error.
  - Simulate storage failure (set bucket read-only) to ensure API returns meaningful `500` and no DB insert occurs.

- **Bilingual UI Review**
  - Inspect `/ar/careers` for RTL alignment, typography, and translation accuracy (hero, job sections, modal).
  - Confirm numeric formatting uses locale (dates, punctuation).

- **Accessibility & UX**
  - Tab through job cards and modal; ensure focus states visible.
  - Verify file input announces accepted types/limits to screen readers.
  - Check responsive layout on mobile viewport (<640px) for hero, job cards, and modal.

- **Regression Smoke**
  - Ensure contact form, sitemap, and footer careers link still operate after changes.
  - Confirm `/sitemap.xml` includes `/en/careers` and `/ar/careers` URLs (unchanged).

## Post-Test Actions

- Remove any seeded dummy data or uploaded CVs created during testing.
- Reset Supabase migrations if destructive tests modified schema (`supabase db reset`).
- Capture screenshots of successful test runs or notable failures for documentation.
