Skip to content

Fix broken filterTable testing helper#3139

Merged
danharrin merged 4 commits into
filamentphp:2.xfrom
austincarpenter:fix/filter-testing-helper
Jul 17, 2022
Merged

Fix broken filterTable testing helper#3139
danharrin merged 4 commits into
filamentphp:2.xfrom
austincarpenter:fix/filter-testing-helper

Conversation

@austincarpenter
Copy link
Copy Markdown
Contributor

Currently it's not possible to use the filterTable() testing helper in the way described in the docs for anything other than a basic Filter filter)

If you'd like to set the value of a `SelectFilter` or `TernaryFilter`, pass the value as a second argument:
```php
use function Pest\Livewire\livewire;
it('can filter posts by `author_id`', function () {
$posts = Post::factory()->count(10)->create();
$authorId = $posts->first()->author_id;
livewire(PostResource\Pages\ListPosts::class)
->assertCanSeeTableRecords($posts)
->filterTable('author_id', $authorId)
->assertCanSeeTableRecords($posts->where('author_id', $authorId))
->assertCanNotSeeTableRecords($posts->where('author_id', '!=', $authorId));
});
```

This is due to a few incorrect parameter/return types referencing Filter instead of BaseFilter. This PR fixes those.

May also be worth it to document the usage of testing a MultiSelectFilter with an example by passing in an array, although I'll leave this one for the reviewer to decide and implement how they wish.

chore: styling
@danharrin danharrin added the bug Something isn't working label Jul 17, 2022
@danharrin danharrin merged commit bae72b9 into filamentphp:2.x Jul 17, 2022
@danharrin
Copy link
Copy Markdown
Member

Thanks, I've added another test for this too

@austincarpenter austincarpenter deleted the fix/filter-testing-helper branch July 17, 2022 10:09
@austincarpenter
Copy link
Copy Markdown
Contributor Author

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants