-
-
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 ChanResourceTest for verifying fo
- Loading branch information
1 parent
cc7d0d5
commit b3f67ce
Showing
1 changed file
with
58 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,58 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Filament\Resources; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use App\Filament\Resources\ChanResource; | ||
use Filament\Forms\Components\TextInput; | ||
use Filament\Tables\Columns\TextColumn; | ||
use Filament\Tables\Actions\EditAction; | ||
use Filament\Tables\Actions\DeleteBulkAction; | ||
|
||
class ChanResourceTest extends TestCase | ||
{ | ||
public function test_form_schema_contains_expected_fields(): void | ||
{ | ||
$form = ChanResource::form(null); | ||
$schema = $form->getSchema(); | ||
|
||
$expectedFields = [ | ||
'group' => TextInput::class, | ||
'gid' => TextInput::class, | ||
'date' => TextInput::class, | ||
'time' => TextInput::class, | ||
]; | ||
|
||
foreach ($expectedFields as $fieldName => $fieldClass) { | ||
$field = collect($schema)->firstWhere('name', $fieldName); | ||
$this->assertNotNull($field, "Field {$fieldName} does not exist."); | ||
$this->assertInstanceOf($fieldClass, $field, "Field {$fieldName} is not of type {$fieldClass}."); | ||
if ($fieldName !== 'gid') { | ||
$this->assertEquals(255, $field->getMaxLength(), "Field {$fieldName} does not have the correct maxLength."); | ||
} | ||
} | ||
} | ||
|
||
public function test_table_configuration_includes_correct_columns_and_actions(): void | ||
{ | ||
$table = ChanResource::table(null); | ||
$columns = $table->getColumns(); | ||
$actions = $table->getActions(); | ||
$bulkActions = $table->getBulkActions(); | ||
|
||
$expectedColumns = ['group', 'gid', 'date', 'time', 'created_at', 'updated_at']; | ||
foreach ($expectedColumns as $columnName) { | ||
$column = collect($columns)->firstWhere('name', $columnName); | ||
$this->assertNotNull($column, "Column {$columnName} does not exist."); | ||
$this->assertInstanceOf(TextColumn::class, $column, "Column {$columnName} is not of type TextColumn."); | ||
} | ||
|
||
$editAction = collect($actions)->firstWhere('name', 'edit'); | ||
$this->assertNotNull($editAction, "Edit action does not exist."); | ||
$this->assertInstanceOf(EditAction::class, $editAction, "Edit action is not of type EditAction."); | ||
|
||
$deleteBulkAction = collect($bulkActions)->firstWhere('name', 'delete'); | ||
$this->assertNotNull($deleteBulkAction, "Delete bulk action does not exist."); | ||
$this->assertInstanceOf(DeleteBulkAction::class, $deleteBulkAction, "Delete bulk action is not of type DeleteBulkAction."); | ||
} | ||
} |