-
-
Notifications
You must be signed in to change notification settings - Fork 211
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] Filtering with Filter::number and methods: thousands() / decima…
…l() not working (#1538) * Enhance tests for Filter::Number dec/thousand separators * [FIX] set dec/thousand separators in Filter::Number * remove errors from ignore * Split and refactor Multiple Filters Test * improve feedback message on skip
- Loading branch information
1 parent
5897535
commit 615da76
Showing
11 changed files
with
295 additions
and
171 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
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,45 @@ | ||
<?php | ||
|
||
use PowerComponents\LivewirePowerGrid\Facades\Filter; | ||
|
||
use PowerComponents\LivewirePowerGrid\Tests\{Concerns\Components\DishesQueryBuilderTable, | ||
Concerns\Components\DishesTable, | ||
Concerns\Components\DishesTableWithJoin}; | ||
|
||
$component = new class () extends DishesTable { | ||
public function filters(): array | ||
{ | ||
return [ | ||
Filter::number('price_BRL')->placeholder('min_xyz_placeholder', 'max_xyz_placeholder')->thousands("'")->decimal(','), | ||
Filter::number('price') ->placeholder('min_xyz_placeholder', 'max_xyz_placeholder')->thousands("'")->decimal(','), | ||
Filter::inputText('name')->placeholder('dish_name_xyz_placeholder')->operators(), | ||
Filter::number('price')->placeholder('min_xyz_placeholder', 'max_xyz_placeholder')->thousands("'")->decimal(','), | ||
Filter::boolean('in_stock'), | ||
]; | ||
} | ||
}; | ||
|
||
$componentQueryBuilder = new class () extends DishesQueryBuilderTable { | ||
public function filters(): array | ||
{ | ||
return [ | ||
Filter::number('price_BRL')->placeholder('min_xyz_placeholder', 'max_xyz_placeholder')->thousands("'")->decimal(','), | ||
Filter::number('price') ->placeholder('min_xyz_placeholder', 'max_xyz_placeholder')->thousands("'")->decimal(','), | ||
Filter::inputText('name')->placeholder('dish_name_xyz_placeholder')->operators(), | ||
Filter::number('price')->placeholder('min_xyz_placeholder', 'max_xyz_placeholder')->thousands("'")->decimal(','), | ||
Filter::boolean('in_stock'), | ||
]; | ||
} | ||
}; | ||
|
||
$componentJoin = new class () extends DishesTableWithJoin { | ||
public function filters(): array | ||
{ | ||
return [ | ||
Filter::number('price_BRL') ->placeholder('min_xyz_placeholder', 'max_xyz_placeholder')->thousands("'")->decimal(','), | ||
Filter::inputText('dish_name')->placeholder('dish_name_xyz_placeholder')->operators(), | ||
Filter::number('price')->placeholder('min_xyz_placeholder', 'max_xyz_placeholder')->thousands("'")->decimal(','), | ||
Filter::boolean('in_stock'), | ||
]; | ||
} | ||
}; |
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,10 @@ | ||
<?php | ||
|
||
require(__DIR__ . '/../Concerns/Components/ComponentsForFilterTest.php'); | ||
|
||
dataset('filterComponent', [ | ||
'tailwind -> id' => [$component::class, (object) ['theme' => 'tailwind', 'field' => 'name']], | ||
'bootstrap -> id' => [$component::class, (object) ['theme' => 'bootstrap', 'field' => 'name']], | ||
'tailwind -> dishes.id' => [$componentJoin::class, (object) ['theme' => 'tailwind', 'field' => 'dishes.name']], | ||
'bootstrap -> dishes.id' => [$componentJoin::class, (object) ['theme' => 'bootstrap', 'field' => 'dishes.name']], | ||
]); |
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,65 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Str; | ||
use PowerComponents\LivewirePowerGrid\PowerGridComponent; | ||
|
||
use function PowerComponents\LivewirePowerGrid\Tests\Plugins\livewire; | ||
|
||
require(__DIR__ . '/../../Concerns/Components/ComponentsForFilterTest.php'); | ||
|
||
it('properly filters by inputText', function (string $component, object $params) { | ||
$component = livewire($component) | ||
->call($params->theme); | ||
|
||
/** @var PowerGridComponent $component */ | ||
expect($component->filters) | ||
->toMatchArray([]); | ||
|
||
$component->set('filters', filterInputText('ba', 'contains', $params->field)); | ||
|
||
if (str_contains($params->field, '.')) { | ||
$data = Str::of($params->field)->explode('.'); | ||
$table = $data->get(0); | ||
$field = $data->get(1); | ||
|
||
expect($component->filters) | ||
->toMatchArray([ | ||
'input_text' => [ | ||
$table => [ | ||
$field => 'ba', | ||
], | ||
], | ||
'input_text_options' => [ | ||
$table => [ | ||
$field => 'contains', | ||
], | ||
], | ||
]); | ||
} else { | ||
expect($component->filters) | ||
->toMatchArray([ | ||
'input_text' => [ | ||
$params->field => 'ba', | ||
], | ||
'input_text_options' => [ | ||
$params->field => 'contains', | ||
], | ||
]); | ||
} | ||
|
||
$component->assertSee('Barco-Sushi da Sueli') | ||
->assertSeeHtml('dish_name_xyz_placeholder'); | ||
|
||
$filters = array_merge($component->filters, filterNumber('price', min: '1\'500.20', max: '3\'000.00')); | ||
|
||
$component->set('filters', $filters) | ||
->assertSeeHtml('placeholder="min_xyz_placeholder"') | ||
->assertSeeHtml('placeholder="max_xyz_placeholder"') | ||
->assertSee('Barco-Sushi Simples') | ||
->assertDontSee('Barco-Sushi da Sueli') | ||
->assertDontSee('Polpetone Filé Mignon') | ||
->assertDontSee('борщ'); | ||
|
||
expect($component->filters)->toBe($filters); | ||
})->group('filters') | ||
->with('filterComponent'); |
Oops, something went wrong.