<?php

namespace Tests\Feature;

use App\Models\Post;
use Database\Seeders\MoneyWiseMinuteSeeder;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class BlogArticleTest extends TestCase
{
    use RefreshDatabase;

    public function test_all_minute_articles_are_seeded(): void
    {
        $this->seed(MoneyWiseMinuteSeeder::class);
        $this->assertSame(13, Post::count());
        $this->assertNotNull(Post::whereNull('published_at')->count() === 0 ? true : null);
    }

    public function test_article_renders_with_rich_formatting(): void
    {
        $this->seed(MoneyWiseMinuteSeeder::class);

        $res = $this->get('/blog/who-is-your-anchor');

        $res->assertOk()
            ->assertSee('Who Is Your Anchor?')
            ->assertSee('Storms reveal what calm seasons hide')
            ->assertSee('3 Truths')
            ->assertSee('blockquote', false)      // pull-quote rendered
            ->assertSee('built an anchor');        // the Rina quote content
    }

    public function test_article_appears_on_blog_index(): void
    {
        $this->seed(MoneyWiseMinuteSeeder::class);
        $this->get('/blog')->assertOk()->assertSee('The Day Aisha Opened the Red File');
    }

    public function test_seeder_is_idempotent(): void
    {
        $this->seed(MoneyWiseMinuteSeeder::class);
        $this->seed(MoneyWiseMinuteSeeder::class);
        $this->assertSame(13, Post::count());
    }
}
