-
-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split and refactor Multiple Filters Test
- Loading branch information
1 parent
7ac36f0
commit 05556c9
Showing
6 changed files
with
182 additions
and
52 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
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
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'); |
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,42 @@ | ||
<?php | ||
|
||
use function PowerComponents\LivewirePowerGrid\Tests\Plugins\livewire; | ||
|
||
require(__DIR__ . '/../../Concerns/Components/ComponentsForFilterTest.php'); | ||
|
||
it('properly filters by filter Number', function (string $component, object $params) { | ||
$component = livewire($component) | ||
->call($params->theme); | ||
|
||
$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); | ||
|
||
// Use wrong separators | ||
$filters = array_merge($component->filters, filterNumber('price', min: '1@500#20', max: '3@000#00')); | ||
|
||
$component->set('filters', $filters) | ||
->assertSee('No records found'); | ||
})->group('filters') | ||
->with('filterComponent'); | ||
|
||
it('properly filters by filter Number with wrong separators', function (string $component, object $params) { | ||
$component = livewire($component) | ||
->call($params->theme); | ||
|
||
// Use wrong separators | ||
$filters = array_merge($component->filters, filterNumber('price', min: '1@500#20', max: '3@000#00')); | ||
|
||
$component->set('filters', $filters) | ||
->assertSee('No records found'); | ||
})->skipOnPostgreSQL() | ||
->group('filters') | ||
->with('filterComponent'); |
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