141 lines
4.2 KiB
PHP
141 lines
4.2 KiB
PHP
<?php
|
|
|
|
use App\Models\BlockedTime;
|
|
use App\Models\Consultation;
|
|
use App\Models\WorkingHour;
|
|
use Carbon\Carbon;
|
|
use Livewire\Volt\Volt;
|
|
|
|
beforeEach(function () {
|
|
// Setup working hours for weekdays (Sunday-Thursday)
|
|
foreach ([0, 1, 2, 3, 4] as $day) {
|
|
WorkingHour::factory()->create([
|
|
'day_of_week' => $day,
|
|
'start_time' => '09:00',
|
|
'end_time' => '17:00',
|
|
'is_active' => true,
|
|
]);
|
|
}
|
|
});
|
|
|
|
it('displays current month by default', function () {
|
|
$currentMonth = now()->translatedFormat('F Y');
|
|
|
|
Volt::test('availability-calendar')
|
|
->assertSee($currentMonth);
|
|
});
|
|
|
|
it('navigates to next month', function () {
|
|
$nextMonth = now()->addMonth()->translatedFormat('F Y');
|
|
|
|
Volt::test('availability-calendar')
|
|
->call('nextMonth')
|
|
->assertSee($nextMonth);
|
|
});
|
|
|
|
it('prevents navigating to past months', function () {
|
|
Volt::test('availability-calendar')
|
|
->assertSet('year', now()->year)
|
|
->assertSet('month', now()->month)
|
|
->call('previousMonth')
|
|
->assertSet('year', now()->year)
|
|
->assertSet('month', now()->month);
|
|
});
|
|
|
|
it('handles year rollover when navigating months', function () {
|
|
Carbon::setTestNow(Carbon::create(2024, 12, 15));
|
|
|
|
Volt::test('availability-calendar')
|
|
->assertSet('year', 2024)
|
|
->assertSet('month', 12)
|
|
->call('nextMonth')
|
|
->assertSet('year', 2025)
|
|
->assertSet('month', 1);
|
|
|
|
Carbon::setTestNow();
|
|
});
|
|
|
|
it('loads available slots when date is selected', function () {
|
|
$sunday = Carbon::now()->next(Carbon::SUNDAY)->format('Y-m-d');
|
|
|
|
Volt::test('availability-calendar')
|
|
->call('selectDate', $sunday)
|
|
->assertSet('selectedDate', $sunday)
|
|
->assertNotSet('availableSlots', []);
|
|
});
|
|
|
|
it('does not select unavailable dates', function () {
|
|
// Friday is a non-working day in our setup
|
|
$friday = Carbon::now()->next(Carbon::FRIDAY)->format('Y-m-d');
|
|
|
|
Volt::test('availability-calendar')
|
|
->call('selectDate', $friday)
|
|
->assertSet('selectedDate', null)
|
|
->assertSet('availableSlots', []);
|
|
});
|
|
|
|
it('clears selection when navigating months', function () {
|
|
$sunday = Carbon::now()->next(Carbon::SUNDAY)->format('Y-m-d');
|
|
|
|
Volt::test('availability-calendar')
|
|
->call('selectDate', $sunday)
|
|
->assertSet('selectedDate', $sunday)
|
|
->call('nextMonth')
|
|
->assertSet('selectedDate', null)
|
|
->assertSet('availableSlots', []);
|
|
});
|
|
|
|
it('displays RTL layout for Arabic locale', function () {
|
|
app()->setLocale('ar');
|
|
|
|
Volt::test('availability-calendar')
|
|
->assertSeeHtml('dir="rtl"');
|
|
});
|
|
|
|
it('does not select blocked dates', function () {
|
|
$sunday = Carbon::now()->next(Carbon::SUNDAY);
|
|
BlockedTime::factory()->allDay()->create([
|
|
'block_date' => $sunday->toDateString(),
|
|
]);
|
|
|
|
Volt::test('availability-calendar')
|
|
->call('selectDate', $sunday->toDateString())
|
|
->assertSet('selectedDate', null);
|
|
});
|
|
|
|
it('does not select fully booked dates', function () {
|
|
$sunday = Carbon::now()->next(Carbon::SUNDAY);
|
|
$slots = ['09:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00'];
|
|
|
|
foreach ($slots as $slot) {
|
|
Consultation::factory()->approved()->create([
|
|
'booking_date' => $sunday->toDateString(),
|
|
'booking_time' => $slot,
|
|
]);
|
|
}
|
|
|
|
Volt::test('availability-calendar')
|
|
->call('selectDate', $sunday->toDateString())
|
|
->assertSet('selectedDate', null);
|
|
});
|
|
|
|
it('shows available legend items', function () {
|
|
Volt::test('availability-calendar')
|
|
->assertSee(__('booking.available'))
|
|
->assertSee(__('booking.partial'))
|
|
->assertSee(__('booking.unavailable'));
|
|
});
|
|
|
|
it('allows selecting partially booked dates', function () {
|
|
$sunday = Carbon::now()->next(Carbon::SUNDAY);
|
|
Consultation::factory()->approved()->create([
|
|
'booking_date' => $sunday->toDateString(),
|
|
'booking_time' => '10:00',
|
|
]);
|
|
|
|
Volt::test('availability-calendar')
|
|
->call('selectDate', $sunday->toDateString())
|
|
->assertSet('selectedDate', $sunday->toDateString())
|
|
->assertNotSet('availableSlots', []);
|
|
});
|