complete story 7.6 with qa tests

This commit is contained in:
Naser Mansour
2025-12-29 00:36:33 +02:00
parent 45e2be8468
commit 3bcbb13c61
8 changed files with 657 additions and 28 deletions
@@ -138,3 +138,83 @@ it('allows selecting partially booked dates', function () {
->assertSet('selectedDate', $sunday->toDateString())
->assertNotSet('availableSlots', []);
});
// User Booked Dates Tests
it('accepts bookedDates prop on mount', function () {
// Use a date in the current month to avoid navigating
$bookedDate = Carbon::now()->startOfMonth()->addDays(10)->format('Y-m-d');
Volt::test('availability-calendar', ['bookedDates' => [$bookedDate]])
->assertSet('bookedDates', [$bookedDate]);
});
it('prevents selecting user booked dates', function () {
$sunday = Carbon::now()->next(Carbon::SUNDAY);
$component = Volt::test('availability-calendar', ['bookedDates' => [$sunday->format('Y-m-d')]]);
// Navigate to the month containing the Sunday if necessary
if ($sunday->month !== now()->month || $sunday->year !== now()->year) {
$component->call('nextMonth');
}
$component->call('selectDate', $sunday->format('Y-m-d'))
->assertSet('selectedDate', null);
});
it('marks user booked dates with user_booked status in calendar', function () {
$sunday = Carbon::now()->next(Carbon::SUNDAY);
$component = Volt::test('availability-calendar', ['bookedDates' => [$sunday->format('Y-m-d')]]);
// Navigate to the month containing the Sunday if necessary
if ($sunday->month !== now()->month || $sunday->year !== now()->year) {
$component->call('nextMonth');
}
$calendarDays = $component->viewData('calendarDays');
$bookedDay = collect($calendarDays)->firstWhere('date', $sunday->format('Y-m-d'));
expect($bookedDay)->not->toBeNull();
expect($bookedDay['status'])->toBe('user_booked');
});
it('shows user booked legend when bookedDates is not empty', function () {
$bookedDate = Carbon::now()->startOfMonth()->addDays(10)->format('Y-m-d');
Volt::test('availability-calendar', ['bookedDates' => [$bookedDate]])
->assertSee(__('booking.user_booked'));
});
it('does not show user booked legend when bookedDates is empty', function () {
Volt::test('availability-calendar', ['bookedDates' => []])
->assertDontSee(__('booking.user_booked'));
});
it('user booked status takes precedence over available status', function () {
$sunday = Carbon::now()->next(Carbon::SUNDAY);
$component = Volt::test('availability-calendar', ['bookedDates' => [$sunday->format('Y-m-d')]]);
// Navigate to the month containing the Sunday if necessary
if ($sunday->month !== now()->month || $sunday->year !== now()->year) {
$component->call('nextMonth');
}
$calendarDays = $component->viewData('calendarDays');
$bookedDay = collect($calendarDays)->firstWhere('date', $sunday->format('Y-m-d'));
expect($bookedDay)->not->toBeNull();
expect($bookedDay['status'])->toBe('user_booked');
});
it('allows selecting dates not in bookedDates array', function () {
$sunday = Carbon::now()->next(Carbon::SUNDAY);
$monday = Carbon::now()->next(Carbon::MONDAY);
$component = Volt::test('availability-calendar', ['bookedDates' => [$sunday->format('Y-m-d')]]);
// Navigate to the month containing the Monday if necessary
if ($monday->month !== now()->month || $monday->year !== now()->year) {
$component->call('nextMonth');
}
$component->call('selectDate', $monday->format('Y-m-d'))
->assertSet('selectedDate', $monday->format('Y-m-d'));
});