# E2E Tests

This directory contains end-to-end tests for the web application using Playwright.

## Prerequisites

Before running the e2e tests, make sure you have:

1. The service running on port 3001
2. The web application running on port 3000

## Running E2E Tests

### Option 1: Manual service startup (recommended for development)

```bash
# Terminal 1: Start the service
pnpm run service

# Terminal 2: Start the web app and run e2e tests
pnpm run test:e2e:full
```

### Option 2: Run e2e tests (assuming services are already running)

```bash
pnpm run test:e2e
```

## Test Structure

- `api.spec.ts` - Tests HTTP API endpoints (GET, POST, PUT, DELETE)
- `websocket.spec.ts` - Tests WebSocket/Socket.IO functionality

## Test Coverage

### API Tests (`api.spec.ts`)

**Settings CRUD Operations:**

- ✅ GET `/config/settings` - Retrieve all settings
- ✅ POST `/config/settings` - Create/update settings
- ✅ GET `/config/settings/:key` - Get specific setting
- ✅ DELETE `/config/settings/:key` - Delete specific setting

**Tasks CRUD Operations:**

- ✅ GET `/tasks` - List all tasks
- ✅ POST `/tasks` - Create new task
- ✅ PUT `/tasks/:id` - Update existing task
- ✅ DELETE `/tasks/:id` - Delete task

**Files CRUD Operations:**

- ✅ GET `/files` - List files
- ✅ GET `/files/stats/*` - File statistics
- ✅ POST `/files/:dataset/:file` - Upload/create file
- ✅ GET `/files/:dataset/:file` - Retrieve specific file
- ✅ DELETE `/files/:dataset/:file` - Delete file

**Error Handling:**

- ✅ 404 errors for non-existent endpoints
- ✅ Timeout handling for slow/unresponsive requests

### WebSocket Tests (`websocket.spec.ts`)

- ✅ Basic WebSocket connection establishment
- ✅ Socket.IO connection and disconnection
- ✅ Room operations (join/leave rooms)
- ✅ Real-time event handling:
  - `taskUpdate` events (triggered by settings changes)
  - `fileUpdate` events (triggered by file operations)
  - `watcherUpdate` events (triggered by watcher status changes)
- ✅ Connection error handling

## Debugging

To run tests with UI mode for debugging:

```bash
pnpm run test:e2e:ui
```

This will open a browser window showing the test execution.

## Notes

- Tests assume the service is running on `http://localhost:3001`
- WebSocket tests use Socket.IO client library loaded via CDN
- Some tests may be skipped if certain endpoints don't exist in your service
