XYLEX Group

Running Tests

Running Tests

Unit Tests

First run this to install jsdom and any other dependencies:

pnpm install
```typescript

To run **all unit tests** in the dashboard (excludes E2E tests):

```bash
pnpm --filter dashboard test
```typescript

This runs all tests in `apps/dashboard/__tests__/**` but excludes E2E tests in `__tests__/e2e/**`.

### Run Specific Test Folders

To run tests in a specific folder (data, invoices, sf-formations, utils):

```bash
pnpm --filter dashboard test __tests__/folder_name
```typescript

### Run Individual Test Files

To run a specific test file:

```bash
pnpm --filter dashboard test __tests__/folder_name/test-file.test.ts
```typescript

## E2E Tests (Playwright)

E2E tests are located in `apps/dashboard/__tests__/e2e/` and use Playwright to test the full user journey.

### Prerequisites

1. Install Playwright browsers:

```bash
pnpm exec playwright install --with-deps
```typescript

2. Set up environment variables in `.env.local` or `.env`:
   - `PLAYWRIGHT_TEST_EMAIL` - Test user email for authentication tests
   - `PLAYWRIGHT_TEST_PASSWORD` - Test user password for authentication tests
   - `NEXT_PUBLIC_SUPABASE_URL` - Supabase project URL
   - `NEXT_PUBLIC_SUPABASE_ANON_KEY` - Supabase anonymous key

### Running E2E Tests

**Run all E2E tests:**

```bash
pnpm playwright test
```typescript

Or

```bash
npx playwright test --project=chromium
```typescript

The dev server will automatically start on port 3000 (or 3025 in CI) before running tests.

### To run a particular Playwright test (replace test_file.spec.ts with test file such as invoices.spec.ts)

```bash
npx playwright test __tests__/e2e/test_file.spec.ts --project=chromium
```typescript

### Authentication Rate Limiting

The E2E tests include a rate limiter that caps authentication attempts at **3 attempts per 15-minute window**. This prevents hitting backend rate limits during test runs.

- Tests that require login will automatically skip if the limit is reached
- The counter resets automatically after 15 minutes
- The counter is shared across all tests in the suite
- Both successful and failed login attempts count toward the limit

### Test Structure

- Tests are located in: `apps/dashboard/__tests__/e2e/`
- Configuration: `playwright.config.ts`
- The webServer automatically starts the dev server before tests run
- Tests run in parallel across Chromium, Firefox, and WebKit browsers