-
-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tests): Add unit tests for PersonResource for
- Loading branch information
1 parent
19cb6ac
commit 0398d10
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Filament\Resources; | ||
|
||
use App\Filament\Resources\PersonResource; | ||
use App\Models\Person; | ||
use Filament\Forms\Components\TextInput; | ||
use Filament\Tables\Actions\EditAction; | ||
use Filament\Tables\Actions\DeleteBulkAction; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Tests\TestCase; | ||
|
||
class PersonResourceTest extends TestCase | ||
{ | ||
use RefreshDatabase; | ||
|
||
/** @test */ | ||
public function form_schema_is_correctly_defined() | ||
{ | ||
$form = PersonResource::form(app(\Filament\Forms\Form::class)); | ||
$schema = collect($form->getSchema()); | ||
|
||
// Example assertion for a 'name' field | ||
$nameField = $schema->firstWhere('name', 'name'); | ||
$this->assertInstanceOf(TextInput::class, $nameField); | ||
$this->assertTrue($nameField->isRequired()); | ||
$this->assertEquals(255, $nameField->getMaxLength()); | ||
|
||
// Add more assertions for other fields as per the actual schema of PersonResource | ||
} | ||
|
||
/** @test */ | ||
public function table_columns_and_actions_are_correctly_defined() | ||
{ | ||
$table = PersonResource::table(app(\Filament\Tables\Table::class)); | ||
$columns = collect($table->getColumns()); | ||
|
||
// Example assertion for a 'name' column | ||
$this->assertTrue($columns->pluck('name')->contains('name')); | ||
// Add more assertions for other columns as per the actual schema of PersonResource | ||
|
||
$actions = collect($table->getActions()); | ||
$this->assertTrue($actions->pluck('name')->contains(EditAction::class)); | ||
|
||
$bulkActions = collect($table->getBulkActions()); | ||
$this->assertTrue($bulkActions->pluck('name')->contains(DeleteBulkAction::class)); | ||
} | ||
} |