<?php

namespace Tests\Feature;

use App\Livewire\Shifts\ShiftIndex;
use App\Models\Shift;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;

class ShiftTest extends TestCase
{
    use RefreshDatabase;

    protected function setUp(): void
    {
        parent::setUp();
        $this->seed();
    }

    public function test_authenticated_admin_can_access_shifts_page(): void
    {
        $admin = User::where('email', 'admin@smkn1gunungagung.sch.id')->first();
        $admin->update(['force_password_change' => false]);
        $this->actingAs($admin);

        $response = $this->get('/shifts');
        $response->assertStatus(200);
    }

    public function test_can_add_shift_via_livewire(): void
    {
        $admin = User::where('email', 'admin@smkn1gunungagung.sch.id')->first();
        $admin->update(['force_password_change' => false]);
        $this->actingAs($admin);

        Livewire::test(ShiftIndex::class)
            ->set('name', 'Shift Ujian')
            ->set('start_time', '07:30')
            ->set('end_time', '12:00')
            ->call('save')
            ->assertHasNoErrors();

        $this->assertDatabaseHas('shifts', [
            'name' => 'Shift Ujian',
        ]);
    }
}
