<?php

namespace Tests\Feature;

use App\Livewire\Monitoring\SystemMonitoringIndex;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;

class SystemMonitoringTest extends TestCase
{
    use RefreshDatabase;

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

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

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

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

        Livewire::test(SystemMonitoringIndex::class)
            ->call('refreshHealthChecks')
            ->assertHasNoErrors();
    }
}
