<?php

namespace Tests\Feature;

use App\Models\Page;

trait ContentElementsTestTrait
{
    abstract protected function getClassname();

    public function test_a_content_element_can_be_created_and_viewed_on_a_page()
    {
        $page = Page::factory()->create();
        $content_element = $this->createContentElement($this->getFactory(), $page);

        $page = $content_element->pages->first();
        $page->publish();
        $page->refresh();

        $this->assertInstanceOf(Page::class, $page);

        $this->withoutExceptionHandling();
        $this->get($page->full_slug)
            ->assertSuccessful();
    }

    public function test_content_elements_have_an_achor_attribute()
    {
        $page = Page::factory()->create();
        $content_element = $this->createContentElement($this->getFactory(), $page);
        $page = $content_element->pages->first();
        $page->publish();
        $page->refresh();

        $this->assertNotNull($content_element->anchor);
    }
}
