Skip to content

Commit

Permalink
Add missing LivewireComponentFilterTest and BooleanFilterTest (#2121)
Browse files Browse the repository at this point in the history
* Add missing LivewireComponentFilterTest and BooleanFilterTest

* Fix styling

---------

Co-authored-by: lrljoe <[email protected]>
  • Loading branch information
lrljoe and lrljoe authored Dec 8, 2024
1 parent 9ef4587 commit 91d183e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/Unit/Views/Filters/BooleanFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ public function test_can_set_boolean_filter_to_integer(): void
$this->assertTrue(self::$filterInstance->validate(1));
}

public function test_can_set_boolean_filter_to_valid_string(): void
{
$this->assertTrue(self::$filterInstance->validate('1'));
$this->assertFalse(self::$filterInstance->validate('0'));
}

public function test_cannot_set_boolean_filter_to_valid_string(): void
{
$this->assertFalse(self::$filterInstance->validate('abc'));
$this->assertFalse(self::$filterInstance->validate('def'));
}

public function test_can_get_custom_filter_pills(): void
{
$filter = self::$filterInstance;
Expand Down Expand Up @@ -74,6 +86,11 @@ public function test_can_get_if_boolean_filter_not_empty_string(): void
$this->assertFalse(self::$filterInstance->isEmpty('0'));
}

public function test_can_get_if_boolean_filter_not_empty_invalid_string(): void
{
$this->assertTrue(self::$filterInstance->isEmpty('abc'));
}

public function test_can_validate_null_boolean_filter_value(): void
{
$filter = self::$filterInstance;
Expand Down
49 changes: 49 additions & 0 deletions tests/Unit/Views/Filters/LivewireComponentFilterTest.php
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));

}
}

0 comments on commit 91d183e

Please sign in to comment.