Skip to content

Commit

Permalink
Merge pull request #64 from dissto/add-back-trashed-test
Browse files Browse the repository at this point in the history
Add trashed test
  • Loading branch information
CodeWithDennis authored Mar 29, 2024
2 parents 084d703 + fd7ed3a commit 0ab921c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/Commands/FilamentResourceTestsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ protected function getInitiallyVisibleColumns(Resource $resource): Collection
->filter(fn ($column) => ! $column->isToggledHiddenByDefault());
}

protected function hasSoftDeletes(Resource $resource): bool
{
return method_exists($resource->getModel(), 'bootSoftDeletes');
}

protected function getStubs(Resource $resource): array
{
// Base stubs that are always included
Expand Down Expand Up @@ -156,6 +161,11 @@ protected function getStubs(Resource $resource): array
$stubs[] = 'IndividuallySearchColumn';
}

// Check that trashed columns are not displayed by default
if ($this->hasSoftDeletes($resource) && $this->getTableColumns($resource)->isNotEmpty()) {
$stubs[] = 'Trashed';
}

// Return the stubs
return $stubs;
}
Expand Down
2 changes: 0 additions & 2 deletions stubs/Base.stub
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@ use function Pest\Livewire\livewire;
uses()->group('filament-resource-tests');

beforeEach(function () {
$this->modelUsesSoftDeletes = method_exists(new $MODEL_SINGULAR_NAME$(), 'bootSoftDeletes');

actingAs(User::factory()->create());
});
10 changes: 10 additions & 0 deletions stubs/Trashed.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
it('cannot display trashed records by default', function () {
$records = $MODEL_SINGULAR_NAME$::factory()->count(3)->create();

$trashedRecords = $MODEL_SINGULAR_NAME$::factory()->trashed()->count(6)->create();

livewire(List$MODEL_PLURAL_NAME$::class)
->assertCanSeeTableRecords($records)
->assertCanNotSeeTableRecords($trashedRecords)
->assertCountTableRecords(3);
});

0 comments on commit 0ab921c

Please sign in to comment.