-
-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add missing LivewireComponentFilterTest and BooleanFilterTest (#2121)
* Add missing LivewireComponentFilterTest and BooleanFilterTest * Fix styling --------- Co-authored-by: lrljoe <[email protected]>
- Loading branch information
Showing
2 changed files
with
66 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
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,49 @@ | ||
<?php | ||
|
||
namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Views\Filters; | ||
|
||
use Illuminate\Database\Eloquent\Builder; | ||
use Rappasoft\LaravelLivewireTables\Views\Filters\LivewireComponentFilter; | ||
|
||
final class LivewireComponentFilterTest extends FilterTestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
self::$filterInstance = LivewireComponentFilter::make('Active'); | ||
} | ||
|
||
public function test_can_get_filter_callback(): void | ||
{ | ||
$filter = LivewireComponentFilter::make('Active'); | ||
|
||
$this->assertFalse($filter->hasFilterCallback()); | ||
|
||
$filter = LivewireComponentFilter::make('Active') | ||
->filter(function (Builder $builder, int $value) { | ||
return $builder->where('name', '=', $value); | ||
}); | ||
|
||
$this->assertTrue($filter->hasFilterCallback()); | ||
$this->assertIsCallable($filter->getFilterCallback()); | ||
} | ||
|
||
public function test_can_set_livewire_component_filter_to_text(): void | ||
{ | ||
$filter = LivewireComponentFilter::make('BreedID'); | ||
$this->assertSame('test', $filter->validate('test')); | ||
$this->assertSame('123', $filter->validate(123)); | ||
|
||
} | ||
|
||
public function test_can_get_if_livewire_component_filter_empty(): void | ||
{ | ||
$filter = LivewireComponentFilter::make('Active'); | ||
$this->assertTrue($filter->isEmpty(null)); | ||
$this->assertTrue($filter->isEmpty('')); | ||
$this->assertFalse($filter->isEmpty('123')); | ||
$this->assertFalse($filter->isEmpty('test')); | ||
$this->assertFalse($filter->isEmpty(1234)); | ||
|
||
} | ||
} |