Skip to content

Commit 05f9840

Browse files
committed
Add Filter Slidedown Row Test
1 parent b5447f2 commit 05f9840

File tree

2 files changed

+88
-7
lines changed

2 files changed

+88
-7
lines changed

src/Traits/Filters/HasFilterQueryString.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,6 @@ protected function queryStringHasFilterQueryString(): array
2020
] : [];
2121
}
2222

23-
protected function setupQueryStringStatusForFilter(): void
24-
{
25-
if (! $this->hasQueryStringStatusForFilter()) {
26-
$this->setQueryStringForFilterEnabled();
27-
}
28-
}
29-
3023
public function hasQueryStringStatusForFilter(): bool
3124
{
3225
return $this->hasQueryStringConfigStatus('filters');

tests/Unit/Traits/Filters/FilterMenuTest.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
use PHPUnit\Framework\Attributes\Group;
66
use Rappasoft\LaravelLivewireTables\Exceptions\DataTableConfigurationException;
7+
use Rappasoft\LaravelLivewireTables\Tests\Http\Livewire\PetsTable;
78
use Rappasoft\LaravelLivewireTables\Tests\TestCase;
9+
use Rappasoft\LaravelLivewireTables\Views\Filters\MultiSelectFilter;
10+
use Illuminate\Database\Eloquent\Builder;
11+
use Rappasoft\LaravelLivewireTables\Tests\Models\Breed;
812

913
#[Group('Filters')]
1014
final class FilterMenuTest extends TestCase
@@ -25,4 +29,88 @@ public function test_can_get_default_filter_slidedown_row_attributes(): void
2529
$this->assertSame(['class' => '', 'default-colors' => true, 'default-styling' => true, 'row' => 2], $this->basicTable->getFilterSlidedownRowAttributes('2'));
2630

2731
}
32+
33+
public function test_can_check_filters_with_no_defined_slidedown_rows(): void
34+
{
35+
$testTableDefault = new class extends PetsTable
36+
{
37+
public function configure(): void
38+
{
39+
parent::configure();
40+
$this->useComputedPropertiesDisabled();
41+
42+
}
43+
44+
public function publiclySetFilterPillsItemAttributes(array $attributes = [])
45+
{
46+
$this->setFilterPillsItemAttributes($attributes);
47+
}
48+
49+
public function publiclySetResetFilterButtonAttributes(array $attributes = [])
50+
{
51+
$this->setFilterPillsResetFilterButtonAttributes($attributes);
52+
}
53+
54+
public function publiclySetResetFilterAllButtonAttributes(array $attributes = [])
55+
{
56+
$this->setFilterPillsResetAllButtonAttributes($attributes);
57+
}
58+
};
59+
$this->assertFalse($testTableDefault->hasFiltersWithSlidedownRows());
60+
}
61+
62+
public function test_can_check_filters_with_defined_slidedown_rows(): void
63+
{
64+
$testTableDefault = new class extends PetsTable
65+
{
66+
public function configure(): void
67+
{
68+
parent::configure();
69+
$this->useComputedPropertiesDisabled();
70+
71+
}
72+
73+
public function filters(): array
74+
{
75+
return [
76+
MultiSelectFilter::make('Breed', 'breed')
77+
->setFilterSlidedownRow(2)
78+
->options(
79+
Breed::query()
80+
->orderBy('name')
81+
->get()
82+
->keyBy('id')
83+
->map(fn ($breed) => $breed->name)
84+
->toArray()
85+
)
86+
->filter(function (Builder $builder, array $values) {
87+
return $builder->whereIn('breed_id', $values);
88+
}),
89+
];
90+
}
91+
92+
public function publiclySetFilterPillsItemAttributes(array $attributes = [])
93+
{
94+
$this->setFilterPillsItemAttributes($attributes);
95+
}
96+
97+
public function publiclySetResetFilterButtonAttributes(array $attributes = [])
98+
{
99+
$this->setFilterPillsResetFilterButtonAttributes($attributes);
100+
}
101+
102+
public function publiclySetResetFilterAllButtonAttributes(array $attributes = [])
103+
{
104+
$this->setFilterPillsResetAllButtonAttributes($attributes);
105+
}
106+
};
107+
$this->assertTrue($testTableDefault->hasFiltersWithSlidedownRows());
108+
}
109+
110+
111+
/*
112+
}*/
113+
114+
115+
28116
}

0 commit comments

Comments
 (0)