feat: add TextWidget
add TextWidget CRUD api add basic tests for API
This commit is contained in:
parent
13cfd2961f
commit
c66645cbdd
18 changed files with 536 additions and 1 deletions
47
tests/Unit/TextWidgetResourceTest.php
Normal file
47
tests/Unit/TextWidgetResourceTest.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?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();
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue