# End-to-End Test Cases

## Purpose
Define end-to-end scenarios that exercise:
- Admin entry CRUD
- Public/user display
- CalDAV CRUD
- Display/sync behavior from ICS

This suite uses fixtures in `tests/calendar_entries.md`.

## Pre-Run Setup
- Reset DB to known baseline.
- Seed users:
  - `admin_user` with calendar admin capability
  - `pending_user` with CalDAV `pending_approval`
  - `rw_user` with CalDAV `active`
- Enable plugin and ensure admin menu with `Users`, `Setup`, `Diagnostics`.

## Admin Entry CRUD

### E2E-ADM-001 Create Single Event
- Fixture: CE-001
- Steps:
  1. Admin logs in.
  2. Open `/calendar` as a write-enabled user.
  3. Create event using CE-001.
  4. Save.
- Assertions:
  - Success feedback shown.
  - Event appears in admin list.
  - Event appears in public list/day/week/month/year views.

### E2E-ADM-002 Update Single Event
- Fixture: CE-001
- Steps:
  1. Open CE-001 in editor.
  2. Change title to `Board Meeting (Updated)` and location.
  3. Save.
- Assertions:
  - Updated values shown in admin list and public views.
  - Last-modified metadata changes.

### E2E-ADM-003 Delete Single Event
- Fixture: CE-001
- Steps:
  1. Delete CE-001 from admin list and confirm.
- Assertions:
  - Event removed from admin list.
  - Event removed from public views.
  - Event removed from ICS and CalDAV query results.

### E2E-ADM-004 Create Recurrence Types
- Fixtures: CE-003, CE-004, CE-005, CE-006, CE-007
- Steps:
  1. Create each recurring event via editor.
  2. Re-open each and verify saved recurrence config.
- Assertions:
  - Persisted values match fixture.
  - Preview highlights expected near-term occurrences.
  - UI views render expected occurrences.

### E2E-ADM-005 Delete One Occurrence as Exception
- Fixture: CE-010
- Steps:
  1. Create CE-010.
  2. Delete only occurrence `2026-04-17T14:00:00+01:00`.
  3. Reload series in editor and public views.
- Assertions:
  - Only selected occurrence is removed.
  - Series remains a single sequence (not split).
  - Exception is represented in sync outputs (CalDAV/ICS rules).

### E2E-ADM-006 Table Prefix Configuration
- Steps:
  1. Open Setup page.
  2. Verify plugin table prefix defaults to `wp_cs_calendar`.
  3. Change prefix to a valid alternative (staging only) and save.
  4. Reload calendar/admin views.
- Assertions:
  - Plugin continues to operate without data loss.
  - Event/user records remain available after prefix migration.

### E2E-ADM-007 Setup Title Removal
- Steps:
  1. Open Setup page.
  2. Inspect available controls.
  3. Render a page containing `[calendar]` with a custom page heading in content.
- Assertions:
  - Setup does not show a `Calendar Title` field.
  - Calendar shortcode does not inject its own top heading.
  - Page/theme heading remains the source of title styling.

### E2E-ADM-008 User Removal Revokes Access
- Steps:
  1. Register, verify, and approve a plugin user.
  2. Confirm login/me works.
  3. Remove the same user from `Users` admin.
- Assertions:
  - Subsequent login and `/users/me` fail for removed user.
  - Removed user cannot perform event write actions.

## Public/User Display

### E2E-UI-001 Cross-View Rendering
- Fixtures: CE-002..CE-007
- Steps:
  1. Open public calendar UI.
  2. Switch list/day/week/month/year views.
- Assertions:
  - Required fields render correctly (title/time/location/category/description excerpt).
  - All-day semantics for CE-002 are correct.
  - Empty-state messaging works when date window has no matches.

### E2E-UI-002 DST and Leap-Year Display
- Fixtures: CE-008, CE-009
- Steps:
  1. Navigate to date windows covering fixture dates.
- Assertions:
  - CE-008 shows expected local times around DST boundary.
  - CE-009 recurrence behavior is correct for non-leap years.

### E2E-UI-003 Calendar Shell Control Presence
- Steps:
  1. Render `[calendar]` shortcode.
- Assertions:
  - Login/register/verify/reset controls are present.
  - Future-only filter and theme selector controls are present.
  - Recurrence occurrence-delete controls are present in editor shell markup.

## CalDAV CRUD

### E2E-CDV-001 Auth Gate (Pending User)
- User: `pending_user`
- Fixtures: CE-002, CE-003
- Steps:
  1. Connect CalDAV client as `pending_user`.
- Assertions:
  - Authentication is denied until admin approval.

### E2E-CDV-002 Create/Update/Delete (Write User)
- User: `rw_user`
- Fixture: CE-001 as CalDAV-created item
- Steps:
  1. Create event via CalDAV `PUT`.
  2. Modify via CalDAV `PUT` with valid ETag precondition.
  3. Delete via CalDAV `DELETE`.
- Assertions:
  - Admin UI reflects CalDAV-created and updated data.
  - Public UI reflects changes.
  - Deletion propagates to admin/public views.

### E2E-CDV-003 Recurrence Exception Round-Trip
- User: `rw_user`
- Fixture: CE-010
- Steps:
  1. Create CE-010 via admin or CalDAV.
  2. Delete a single occurrence from CalDAV client.
  3. Sync and inspect in admin editor.
- Assertions:
  - Exception is present for deleted occurrence.
  - Series stays unified (single UID sequence).
  - No split-series artifact created.

### E2E-CDV-004 CalDAV Single-Occurrence Delete Sync Persistence
- User: `rw_user`
- Fixture: CE-010
- Steps:
  1. Create recurring event via UI or CalDAV.
  2. In CalDAV client, delete one occurrence only (client emits `EXDATE` and/or cancelled `RECURRENCE-ID` component).
  3. Force sync/refresh in client and fixture UI.
  4. Restart fixture and refresh again.
- Assertions:
  - Deleted occurrence remains deleted after sync cycles and restart.
  - Persisted exception exists in fixture data store (`recurrence_exceptions`).
  - No duplicate recurrence series is created.

### E2E-CDV-005 Monthly Ordinal Round-Trip
- User: `rw_user`
- Steps:
  1. Create a monthly ordinal recurring event (`weekday_of_month`, `last`, chosen weekday).
  2. Sync via CalDAV and read back object.
  3. Validate resulting occurrence dates in UI/API.
- Assertions:
  - Monthly ordinal rule round-trips without changing meaning.
  - Expected target dates (for example last Sunday of month) are preserved.
  - No split or duplicate series created.

## ICS Display and Sync

### E2E-ICS-001 ICS Link Health and Parsing
- Fixtures: CE-002..CE-007
- Steps:
  1. Fetch public ICS URL.
  2. Parse payload with validator/parser.
- Assertions:
  - HTTP content type is `text/calendar`.
  - VCALENDAR envelope is valid.
  - VEVENT fields map correctly from fixtures.

### E2E-ICS-002 Recurrence and Exception Export
- Fixture: CE-010 with deleted occurrence exception
- Steps:
  1. Fetch ICS after exception delete.
- Assertions:
  - Recurrence is represented with RRULE.
  - Deleted occurrence is represented as exception (EXDATE and/or RECURRENCE-ID pattern).
  - No split into independent series.

### E2E-ICS-003 Consumer Sync
- Fixtures: CE-002, CE-003, CE-010
- Steps:
  1. Subscribe external test calendar to ICS feed.
  2. Update source entries in admin.
  3. Refresh subscriber.
- Assertions:
  - Create/update/delete changes propagate.
  - Exception delete for CE-010 propagates as missing occurrence in subscriber.

### E2E-ICS-004 Slug Path Link Consistency
- Steps:
  1. Set `url_slug` in Setup.
  2. Render `[calendar]`.
- Assertions:
  - Rendered ICS and CalDAV links use slugged path.
  - Links remain navigable and consistent with configured endpoint prefix.

## Traceability
- Admin CRUD/lifecycle: E2E-ADM-001..008
- User display/UI shell: E2E-UI-001..003
- CalDAV CRUD/sync: E2E-CDV-001..005
- ICS display/sync/pathing: E2E-ICS-001..004
