<?php

namespace Tests\Unit;

use Tests\TestCase;

use Illuminate\Foundation\Testing\WithFaker;
use App\Models\StaffProfile;

use Tests\Unit\PermissionsTestTrait;
use Tests\Unit\TagsTrait;

use App\Utilities\PageLink;

class StaffProfileTest extends TestCase
{
    use TagsTrait;
    use PermissionsTestTrait;
    use WithFaker;

    protected function getModel()
    {
        return StaffProfile::factory()->create();
    }

    protected function getClassname()
    {
        return 'staff-profile';
    }

    public function test_a_staff_profile_has_an_anchor()
    {
        $staff_profile = StaffProfile::factory()->create();
        $this->assertNotNull($staff_profile->full_name);

        $this->assertNotNull($staff_profile->anchor);
        $this->assertEquals(PageLink::convertAnchorText($staff_profile->full_name), $staff_profile->anchor);
    }

    public function a_staff_profile_can_be_published()
    {
        $bio = $this->faker->paragraph();

        $staff_profile = StaffProfile::factory()->create([
            'bio' => $this->faker->paragraph(),
            'bio_draft' => $bio,
            'published_at' => null,
        ]);

        $staff_profile->publish();
        $staff_profile->refresh();

        $this->assertEquals($bio, $staff_profile->bio);
        $this->assertEquals($bio, $staff_profile->bio_draft);
        $this->assertNotNull($staff_profile->published_at);
    }

    public function test_a_staff_profile_has_a_full_name_and_name_attribute(): void
    {
        $staff_profile = StaffProfile::factory()->create();
        $this->assertNotNull($staff_profile->full_name);
        $this->assertNotNull($staff_profile->name);

        $this->assertEquals($staff_profile->first_name.' '.$staff_profile->last_name, $staff_profile->full_name);
        $this->assertEquals($staff_profile->full_name, $staff_profile->name);
    }
}
