Skip to content

Commit

Permalink
Merge pull request #139 from dissto/add-test-table-heading-and-descri…
Browse files Browse the repository at this point in the history
…ption

Add tests to confirm the `heading` and `description` for the table can be seen
  • Loading branch information
CodeWithDennis authored Apr 10, 2024
2 parents b134f53 + 870a7bb commit e193278
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ won't be generated.
- [x] It can reset table filters
- [x] It has table actions
- [x] It has table bulk actions
- [x] It has the correct table heading
- [x] It has the correct table description
- [ ] It can filter table records
- [ ] It can remove table filters
Expand Down
30 changes: 30 additions & 0 deletions src/Commands/FilamentTestsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,26 @@ protected function tableHasPagination(Resource $resource): bool
return $this->getResourceTable($resource)->isPaginated();
}

protected function tableHasHeading(Resource $resource): bool
{
return $this->getResourceTable($resource)->getHeading() !== null;
}

protected function getTableHeading(Resource $resource): ?string
{
return $this->getResourceTable($resource)->getHeading();
}

protected function tableHasDescription(Resource $resource): bool
{
return $this->getResourceTable($resource)->getDescription() !== null;
}

protected function getTableDescription(Resource $resource): ?string
{
return $this->getResourceTable($resource)->getDescription();
}

protected function getTableDefaultPaginationPageOption(Resource $resource): int|string|null
{
return $this->getResourceTable($resource)->getDefaultPaginationPageOption();
Expand Down Expand Up @@ -312,6 +332,14 @@ protected function getStubs(Resource $resource): array
if ($this->tableHasPagination($resource)) {
$stubs[] = $this->getStubPath('ListRecordsPaginated', 'Page/Index');
}

if ($this->tableHasHeading($resource)) {
$stubs[] = $this->getStubPath('Heading', 'Page/Index/Table');
}

if ($this->tableHasDescription($resource)) {
$stubs[] = $this->getStubPath('Description', 'Page/Index/Table');
}
}

// Check if there is a create page
Expand Down Expand Up @@ -591,6 +619,8 @@ protected function getStubVariables(Resource $resource, string $stubPath): array
'RESOURCE_TABLE_TOGGLEABLE_COLUMNS' => $this->getToggleableColumns($resource)->keys(),
'RESOURCE_TABLE_ACTIONS' => $this->getTableActionNames($resource)->keys(),
'RESOURCE_TABLE_BULK_ACTIONS' => $this->getTableBulkActionNames($resource)->keys(),
'RESOURCE_TABLE_HEADING' => str($this->getTableHeading($resource))->wrap('\''),
'RESOURCE_TABLE_DESCRIPTION' => str($this->getTableDescription($resource))->wrap('\''),
'DEFAULT_PER_PAGE_OPTION' => $this->getTableDefaultPaginationPageOption($resource),
'DEFAULT_PAGINATED_RECORDS_FACTORY_COUNT' => $this->getTableDefaultPaginationPageOption($resource) * 2,
];
Expand Down
4 changes: 4 additions & 0 deletions stubs/Page/Index/Table/Description.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
it('has the correct table description', function () {
livewire(List{{ MODEL_PLURAL_NAME }}::class)
->assertSee({{ RESOURCE_TABLE_DESCRIPTION }}, escape: false);
}){{ RESOLVED_GROUP_METHOD }};
4 changes: 4 additions & 0 deletions stubs/Page/Index/Table/Heading.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
it('has the correct table heading', function () {
livewire(List{{ MODEL_PLURAL_NAME }}::class)
->assertSee({{ RESOURCE_TABLE_HEADING }}, escape: false);
}){{ RESOLVED_GROUP_METHOD }};

0 comments on commit e193278

Please sign in to comment.