diff --git a/docs/features/availability-management.md b/docs/features/availability-management.md index 85392a6..0839711 100644 --- a/docs/features/availability-management.md +++ b/docs/features/availability-management.md @@ -42,7 +42,7 @@ Instructors access **My Availability** in wp-admin (`?page=us-availability`). - Add a weekly series: tick weekly repeat and choose the number of weeks - Delete a slot: only allowed if `is_booked = 0` - Bulk delete: the list view has a checkbox per unbooked slot (with a select-all header checkbox) and a **Delete selected** button (`usc_action=bulk_delete`, `slot_ids[]`); each id is ownership-checked, and booked slots are refused at the repository level -- Current slots can be shown as a **list** or a **weekly calendar** (`usc_view=week`, navigated with `usc_week=Y-m-d`); the grid honours the site's `start_of_week` option via `Availability\WeekCalendar` +- Current slots can be shown as a **weekly calendar** (the default, navigated with `usc_week=Y-m-d`) or a **list** (`usc_view=list`); the grid honours the site's `start_of_week` option via `Availability\WeekCalendar` ## Public Calendar The front-end booking shortcode renders open slots from `GET /availability` diff --git a/src/Availability/AvailabilityController.php b/src/Availability/AvailabilityController.php index 089f7cb..b6036de 100644 --- a/src/Availability/AvailabilityController.php +++ b/src/Availability/AvailabilityController.php @@ -32,7 +32,7 @@ class AvailabilityController { // View-state query params only (which view, which week) — nothing is // mutated from them, so no nonce applies. // phpcs:disable WordPress.Security.NonceVerification.Recommended - $view = 'week' === sanitize_key( Val::string( wp_unslash( $_GET['usc_view'] ?? '' ) ) ) ? 'week' : 'list'; + $view = 'list' === sanitize_key( Val::string( wp_unslash( $_GET['usc_view'] ?? '' ) ) ) ? 'list' : 'week'; $requestedWeek = sanitize_text_field( Val::string( wp_unslash( $_GET['usc_week'] ?? '' ) ) ); // phpcs:enable WordPress.Security.NonceVerification.Recommended diff --git a/templates/admin/availability.php b/templates/admin/availability.php index 11f6350..7f65adc 100644 --- a/templates/admin/availability.php +++ b/templates/admin/availability.php @@ -84,24 +84,24 @@ $deleteForm = static function (\Unsupervised\Schedular\Availability\Availability

- + - +

diff --git a/tests/Unit/Availability/AvailabilityControllerTest.php b/tests/Unit/Availability/AvailabilityControllerTest.php index 8c7b94d..87f3f2a 100644 --- a/tests/Unit/Availability/AvailabilityControllerTest.php +++ b/tests/Unit/Availability/AvailabilityControllerTest.php @@ -99,8 +99,24 @@ class AvailabilityControllerTest extends TestCase $this->render(); } + public function testDefaultsToWeekView(): void + { + $slot = new AvailabilitySlot(instructorId: 3, startDt: '2026-07-08 09:00:00', endDt: '2026-07-08 10:00:00', id: 5); + + $this->repository->shouldReceive('findByInstructor')->once()->with(3)->andReturn([$slot]); + + $html = $this->render(); + + // Week of Monday 2026-07-06 (start_of_week = 1, today = 2026-07-06). + self::assertStringContainsString('Week of', $html); + // The list table (with its bulk-delete form) is not rendered by default. + self::assertStringNotContainsString('id="usc-bulk-delete-form"', $html); + } + public function testListViewRendersBulkCheckboxesOnlyForUnbookedSlots(): void { + $_GET['usc_view'] = 'list'; + $unbooked = new AvailabilitySlot(instructorId: 3, startDt: '2026-07-08 09:00:00', endDt: '2026-07-08 10:00:00', id: 5); $booked = new AvailabilitySlot(instructorId: 3, startDt: '2026-07-08 10:00:00', endDt: '2026-07-08 11:00:00', isBooked: true, id: 6);