Skip to content

Commit 1617a52

Browse files
authored
Add initial tests for LivewireComponentArrayFilter
1 parent 19b3723 commit 1617a52

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace Rappasoft\LaravelLivewireTables\Tests\Unit\Views\Filters;
4+
5+
use Illuminate\Database\Eloquent\Builder;
6+
use PHPUnit\Framework\Attributes\Group;
7+
use Rappasoft\LaravelLivewireTables\Views\Filters\LivewireComponentArrayFilter;
8+
9+
#[Group('Filters')]
10+
final class LivewireComponentArrayFilterTest extends FilterTestCase
11+
{
12+
protected function setUp(): void
13+
{
14+
parent::setUp();
15+
self::$filterInstance = LivewireComponentArrayFilter::make('Active');
16+
}
17+
18+
public function test_can_get_filter_callback(): void
19+
{
20+
$this->assertFalse(self::$filterInstance->hasFilterCallback());
21+
22+
self::$filterInstance
23+
->filter(function (Builder $builder, array $values) {
24+
return $builder->whereIn('name', $values);
25+
});
26+
27+
$this->assertTrue(self::$filterInstance->hasFilterCallback());
28+
$this->assertIsCallable(self::$filterInstance->getFilterCallback());
29+
}
30+
31+
public function test_can_set_livewire_component_filter_to_text(): void
32+
{
33+
$this->assertSame(['test'], self::$filterInstance->validate(['test']));
34+
$this->assertSame([123], self::$filterInstance->validate([123]));
35+
36+
}
37+
38+
public function test_can_get_if_livewire_component_filter_empty(): void
39+
{
40+
$this->assertTrue(self::$filterInstance->isEmpty());
41+
$this->assertTrue(self::$filterInstance->isEmpty([]));
42+
$this->assertTrue(self::$filterInstance->isEmpty(['']));
43+
$this->assertFalse(self::$filterInstance->isEmpty(['123']));
44+
$this->assertFalse(self::$filterInstance->isEmpty(['test']));
45+
$this->assertFalse(self::$filterInstance->isEmpty([1234]));
46+
47+
}
48+
49+
public function test_can_get_filter_default_value(): void
50+
{
51+
$this->assertSame([],self::$filterInstance->getDefaultValue());
52+
}
53+
54+
}

0 commit comments

Comments
 (0)