<?php

namespace Tests\Feature;

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

class AdminPagesTest extends TestCase
{
    use RefreshDatabase;

    private User $admin;

    protected function setUp(): void
    {
        parent::setUp();

        $this->seed();

        $this->admin = User::query()->firstOrCreate(
            ['email' => 'admin@laralog.test'],
            ['name' => '管理员', 'password' => bcrypt('password')]
        );
    }

    public function test_dashboard_loads(): void
    {
        $this->actingAs($this->admin)->get('/admin')->assertOk();
    }

    public function test_post_resource_loads(): void
    {
        $this->actingAs($this->admin)->get('/admin/posts')->assertOk();
        $this->actingAs($this->admin)->get('/admin/posts/create')->assertOk();
    }

    public function test_settings_page_loads(): void
    {
        $this->actingAs($this->admin)->get('/admin/blog-settings')->assertOk();
    }

    public function test_comment_resource_loads(): void
    {
        $this->actingAs($this->admin)->get('/admin/comments')->assertOk();
    }

    public function test_media_resource_loads(): void
    {
        $this->actingAs($this->admin)->get('/admin/media')->assertOk();
    }

    public function test_guest_is_redirected_to_login(): void
    {
        $this->get('/admin')->assertRedirect('/admin/login');
    }
}
