Skip to content

Commit 91d183e

Browse files
authored
Add missing LivewireComponentFilterTest and BooleanFilterTest (#2121)
* Add missing LivewireComponentFilterTest and BooleanFilterTest * Fix styling --------- Co-authored-by: lrljoe <[email protected]>
1 parent 9ef4587 commit 91d183e

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

tests/Unit/Views/Filters/BooleanFilterTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@ public function test_can_set_boolean_filter_to_integer(): void
2727
$this->assertTrue(self::$filterInstance->validate(1));
2828
}
2929

30+
public function test_can_set_boolean_filter_to_valid_string(): void
31+
{
32+
$this->assertTrue(self::$filterInstance->validate('1'));
33+
$this->assertFalse(self::$filterInstance->validate('0'));
34+
}
35+
36+
public function test_cannot_set_boolean_filter_to_valid_string(): void
37+
{
38+
$this->assertFalse(self::$filterInstance->validate('abc'));
39+
$this->assertFalse(self::$filterInstance->validate('def'));
40+
}
41+
3042
public function test_can_get_custom_filter_pills(): void
3143
{
3244
$filter = self::$filterInstance;
@@ -74,6 +86,11 @@ public function test_can_get_if_boolean_filter_not_empty_string(): void
7486
$this->assertFalse(self::$filterInstance->isEmpty('0'));
7587
}
7688

89+
public function test_can_get_if_boolean_filter_not_empty_invalid_string(): void
90+
{
91+
$this->assertTrue(self::$filterInstance->isEmpty('abc'));
92+
}
93+
7794
public function test_can_validate_null_boolean_filter_value(): void
7895
{
7996
$filter = self::$filterInstance;
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Views\Filters;
4+
5+
use Illuminate\Database\Eloquent\Builder;
6+
use Rappasoft\LaravelLivewireTables\Views\Filters\LivewireComponentFilter;
7+
8+
final class LivewireComponentFilterTest extends FilterTestCase
9+
{
10+
protected function setUp(): void
11+
{
12+
parent::setUp();
13+
self::$filterInstance = LivewireComponentFilter::make('Active');
14+
}
15+
16+
public function test_can_get_filter_callback(): void
17+
{
18+
$filter = LivewireComponentFilter::make('Active');
19+
20+
$this->assertFalse($filter->hasFilterCallback());
21+
22+
$filter = LivewireComponentFilter::make('Active')
23+
->filter(function (Builder $builder, int $value) {
24+
return $builder->where('name', '=', $value);
25+
});
26+
27+
$this->assertTrue($filter->hasFilterCallback());
28+
$this->assertIsCallable($filter->getFilterCallback());
29+
}
30+
31+
public function test_can_set_livewire_component_filter_to_text(): void
32+
{
33+
$filter = LivewireComponentFilter::make('BreedID');
34+
$this->assertSame('test', $filter->validate('test'));
35+
$this->assertSame('123', $filter->validate(123));
36+
37+
}
38+
39+
public function test_can_get_if_livewire_component_filter_empty(): void
40+
{
41+
$filter = LivewireComponentFilter::make('Active');
42+
$this->assertTrue($filter->isEmpty(null));
43+
$this->assertTrue($filter->isEmpty(''));
44+
$this->assertFalse($filter->isEmpty('123'));
45+
$this->assertFalse($filter->isEmpty('test'));
46+
$this->assertFalse($filter->isEmpty(1234));
47+
48+
}
49+
}

0 commit comments

Comments
 (0)