share-lt/tests/Unit/TextWidgetResourceTest.php

48 lines
1.4 KiB
PHP
Raw Permalink Normal View History

<?php
use App\Filament\Resources\Entries\EntryResource;
use App\Filament\Resources\TextWidgets\TextWidgetResource;
use App\Models\TextWidget;
use ReflectionClass;
it('references the correct model and record title attribute', function () {
$defaults = (new ReflectionClass(TextWidgetResource::class))->getDefaultProperties();
expect($defaults['model'] ?? null)->toBe(TextWidget::class);
expect($defaults['recordTitleAttribute'] ?? null)->toBe('title');
});
it('defines the expected pages', function () {
$pages = EntryResource::getPages();
expect(array_keys($pages))->toEqual(['index', 'create', 'view', 'edit']);
});
it('accepts new record when entered via the form schema', function () {
$data = [
'title' => 'Test Entry',
'description' => 'This is a test entry.',
'content' => '<p>This is the content of the test entry.</p>',
];
$entry = new TextWidget;
$entry->fill($data);
expect($entry->title)->toBe('Test Entry');
});
it('deletes a record correctly', function () {
$entry = TextWidget::create([
'title' => 'Test Entry to Delete',
'description' => 'This is a test entry.',
'content' => '<p>This is the content of the test entry.</p>',
]);
$entryId = $entry->id;
$entry->delete();
$deletedEntry = TextWidget::find($entryId);
expect($deletedEntry)->toBeNull();
});