Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeWithDennis committed Mar 28, 2024
1 parent e023680 commit 12e4c9e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/Commands/FilamentResourceTestsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,17 +135,25 @@ protected function getStubVariables(Resource $resource): array
$userModel = User::class;
$modelImport = $resourceModel === $userModel ? "use {$resourceModel};" : "use {$resourceModel};\nuse {$userModel};";

$individualSearchableColumns = $columns->filter(fn ($column) => $column->isIndividuallySearchable())->keys();

$modelSingularName = str($resourceModel)->afterLast('\\');

return [
'resource' => str($resource::class)->afterLast('\\'),
'modelImport' => $modelImport,
'modelSingularName' => str($resourceModel)->afterLast('\\'),
'modelSingularName' => $modelSingularName,
'modelPluralName' => str($resourceModel)->afterLast('\\')->plural(),
'resourceTableColumns' => $this->convertDoubleQuotedArrayString($columns->keys()),
'resourceTableColumnsWithoutHidden' => $this->convertDoubleQuotedArrayString($columns->filter(fn ($column) => ! $column->isToggledHiddenByDefault())->keys()),
'resourceTableToggleableColumns' => $this->convertDoubleQuotedArrayString($columns->filter(fn ($column) => $column->isToggleable())->keys()),
'resourceTableSortableColumns' => $this->convertDoubleQuotedArrayString($columns->filter(fn ($column) => $column->isSortable())->keys()),
'resourceTableSearchableColumns' => $this->convertDoubleQuotedArrayString($columns->filter(fn ($column) => $column->isSearchable())->keys()),
'resourceTableIndividuallySearchableColumns' => $this->convertDoubleQuotedArrayString($columns->filter(fn ($column) => $column->isIndividuallySearchable())->keys()),
'resourceTableIndividuallySearchableColumns' => ! $individualSearchableColumns->isEmpty() ?
$this->convertDoubleQuotedArrayString($columns->filter(fn ($column) => $column->isIndividuallySearchable())->keys()) :
'\''.$modelSingularName.' does not have individually searchable columns\'',
'resourceTableIndividuallySearchableColumnsMethod' => $individualSearchableColumns->isEmpty() ? 'skip' : 'with',
'resourceTableIndividuallySearchableColumnsVariable' => ! $individualSearchableColumns->isEmpty() ? 'string $column' : '',
];
}

Expand Down
5 changes: 2 additions & 3 deletions stubs/Resource.stub
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ it('can search column', function (string $column) {
->assertCanNotSeeTableRecords($records->where($column, '!=', $search));
})->with($resourceTableSearchableColumns$);

it('can individually search by column', function (string $column) {
it('can individually search by column', function ($resourceTableIndividuallySearchableColumnsVariable$) {
$records = $modelSingularName$::factory()->count(3)->create();

$search = $records->first()->{$column};
Expand All @@ -62,8 +62,7 @@ it('can individually search by column', function (string $column) {
->searchTableColumns([$column => $search])
->assertCanSeeTableRecords($records->where($column, $search))
->assertCanNotSeeTableRecords($records->where($column, '!=', $search));
})->with($resourceTableIndividuallySearchableColumns$);

})->$resourceTableIndividuallySearchableColumnsMethod$($resourceTableIndividuallySearchableColumns$);

it('cannot display trashed records by default', function () {
$records = $modelSingularName$::factory()->count(3)->create();
Expand Down

0 comments on commit 12e4c9e

Please sign in to comment.