# Login Flow Tests

Authentication tests for the Open Core Business Suite login functionality.

## Test Environment
- Base URL: http://127.0.0.1:8000
- Login Page: /auth/login
- Dashboard: /dashboard

## Demo Credentials
| Role | Email | Password |
|------|-------|----------|
| Admin | admin@demo.com | password123 |
| HR | hr@demo.com | password123 |
| Employee | employee@demo.com | password123 |

---

## Login with valid admin credentials

**Prerequisite:** None (fresh browser session)

### Steps:
1. Navigate to `/auth/login`
2. Verify the login form is displayed
3. Enter "admin@demo.com" in the email field
4. Enter "password123" in the password field
5. Click the "Sign in" button

### Expected Results:
- User is redirected to `/dashboard`
- Dashboard page loads successfully
- User name "Admin" is visible in the header
- Sidebar navigation menu is visible

---

## Login with invalid password

**Prerequisite:** None (fresh browser session)

### Steps:
1. Navigate to `/auth/login`
2. Enter "admin@demo.com" in the email field
3. Enter "wrongpassword" in the password field
4. Click the "Sign in" button

### Expected Results:
- User remains on the login page
- Error message is displayed (e.g., "Invalid credentials" or similar)
- Password field is cleared or highlighted

---

## Login with non-existent user

**Prerequisite:** None (fresh browser session)

### Steps:
1. Navigate to `/auth/login`
2. Enter "nonexistent@example.com" in the email field
3. Enter "password123" in the password field
4. Click the "Sign in" button

### Expected Results:
- User remains on the login page
- Error message is displayed
- Form fields are preserved or cleared appropriately

---

## Logout

**Prerequisite:** User is logged in as admin

### Steps:
1. Login as admin (use seed test as prerequisite)
2. Locate the user dropdown menu in the header
3. Click on the user profile/avatar
4. Click "Logout" option

### Expected Results:
- User is redirected to `/auth/login`
- Session is terminated
- Attempting to access `/dashboard` redirects back to login

---

## Remember me functionality

**Prerequisite:** None (fresh browser session)

### Steps:
1. Navigate to `/auth/login`
2. Enter valid admin credentials
3. Check the "Remember me" checkbox
4. Click the "Sign in" button
5. Close the browser
6. Reopen and navigate to the application

### Expected Results:
- User session persists across browser restarts
- User is automatically logged in on return

---

## Demo mode login buttons

**Prerequisite:** Application is in demo mode (APP_DEMO=true)

### Steps:
1. Navigate to `/auth/login`
2. Verify demo credential buttons are visible
3. Click the "Admin" demo login button

### Expected Results:
- Credentials are auto-filled
- User is logged in as admin
- Redirected to dashboard
