Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/DataSource/Processors/CollectionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class CollectionProcessor extends DataSourceBase
{
public static function match(mixed $key): bool
{
return $key instanceof Collection;
return $key instanceof Collection
|| is_iterable($key);
}

public function process(array $properties = []): array
Expand Down
168 changes: 0 additions & 168 deletions tests/Concerns/Components/DishesCollectionTable.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
PowerGridComponent,
PowerGridFields};

class DishesArrayTable extends PowerGridComponent
class DishesIterableTable extends PowerGridComponent
{
public string $tableName = 'testing-dishes-array-table';
public string $tableName = 'testing-dishes-iterable-table';

public array $eventId = [];

public array $testFilters = [];

public string $iterableType = 'array';

protected function getListeners()
{
return array_merge(
Expand All @@ -33,9 +35,9 @@ public function openModal(array $params)
$this->eventId = $params;
}

public function datasource(): array
public function datasource()
{
return [
$data = [
[
'id' => 1,
'name' => 'Name 1',
Expand Down Expand Up @@ -77,6 +79,12 @@ public function datasource(): array
'chef_name' => 'Luan',
],
];

if ($this->iterableType === 'collection') {
return collect($data);
}

return $data;
}

public function setUp(): array
Expand Down
10 changes: 6 additions & 4 deletions tests/Feature/CollectionSearchTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php

use PowerComponents\LivewirePowerGrid\Tests\Concerns\Components\{DishesCollectionTable};
use PowerComponents\LivewirePowerGrid\Tests\Concerns\Components\DishesIterableTable;
use PowerComponents\LivewirePowerGrid\Themes\{Bootstrap5, Tailwind};

use function PowerComponents\LivewirePowerGrid\Tests\Plugins\livewire;

it('searches', function (string $component, object $params) {
livewire($component)
livewire($component, [
'iterableType' => 'collection',
])
->call('setTestThemeClass', $params->theme)
->set('search', 'Name 1')
->assertSee('Name 1')
Expand All @@ -29,6 +31,6 @@
})->with('search');

dataset('search', [
'tailwind' => [DishesCollectionTable::class, (object) ['theme' => Tailwind::class]],
'bootstrap' => [DishesCollectionTable::class, (object) ['theme' => Bootstrap5::class]],
'tailwind' => [DishesIterableTable::class, (object) ['theme' => Tailwind::class]],
'bootstrap' => [DishesIterableTable::class, (object) ['theme' => Bootstrap5::class]],
]);
43 changes: 22 additions & 21 deletions tests/Feature/Filters/FilterBooleanTest.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

use PowerComponents\LivewirePowerGrid\Facades\Filter;
use PowerComponents\LivewirePowerGrid\Tests\{Concerns\Components\DishesArrayTable,
Concerns\Components\DishesCollectionTable,
use PowerComponents\LivewirePowerGrid\Tests\{
Concerns\Components\DishesIterableTable,
Concerns\Components\DishesQueryBuilderTable,
Concerns\Components\DishesTable,
Concerns\Components\DishesTableWithJoin};
Expand Down Expand Up @@ -131,7 +131,7 @@ public function filters(): array
expect($component->filters)
->toMatchArray([]);
})->group('filters', 'filterBoolean')
->with('filter_boolean_themes_collection', 'filter_boolean_themes_array');
->with('iterable_datasource');

it('properly filters by bool true - using collection', function (string $component, string $theme) {
$component = livewire($component, [
Expand Down Expand Up @@ -169,7 +169,7 @@ public function filters(): array
expect($component->filters)
->toMatchArray([]);
})->group('filters', 'filterBoolean')
->with('filter_boolean_themes_collection');
->with('iterable_datasource');

it('properly filters by bool true - using collection - custom builder', function (string $componentName, string $theme) {
$component = livewire($componentName, [
Expand All @@ -192,9 +192,9 @@ public function filters(): array
->assertSee('Name 4')
->assertDontSee('Name 5');
})->group('filters', 'filterBoolean')
->with('filter_boolean_themes_collection');
->with('iterable_datasource');

$customCollection = new class() extends DishesCollectionTable
$customCollection = new class() extends DishesIterableTable
{
public int $dishId;

Expand All @@ -214,7 +214,9 @@ public function filters(): array
};

it('properly filters by bool true - using collection - custom builder - using tablename in field', function (string $component, string $theme) {
$component = livewire($component)
$component = livewire($component, [
'iterableType' => 'collection',
])
->call('setTestThemeClass', $theme)
->assertSeeHtml('wire:input.live.debounce.600ms="filterBoolean(\'in_stock\', $event.target.value, \'In Stock\')"');

Expand Down Expand Up @@ -320,7 +322,7 @@ public function filters(): array
expect($component->filters)
->toMatchArray([]);
})->group('filters', 'filterBoolean')
->with('filter_boolean_themes_collection', 'filter_boolean_themes_array');
->with('iterable_datasource');

it('properly filters by bool "all"', function (string $component, object $params) {
$component = livewire($component, [
Expand Down Expand Up @@ -352,8 +354,10 @@ public function filters(): array
})->group('filters', 'filterBoolean')
->with('filter_boolean_join', 'filter_boolean_query_builder');

it('properly filters by bool "all" - using collection & array table', function (string $component, string $theme) {
$component = livewire($component)
it('properly filters by bool "all" - using collection', function (string $component, string $theme, string $iterableType) {
$component = livewire($component, [
'iterableType' => $iterableType,
])
->call('setTestThemeClass', $theme);

expect($component->filters)
Expand All @@ -373,7 +377,7 @@ public function filters(): array
],
]);
})->group('filters', 'filterBoolean')
->with('filter_boolean_themes_collection', 'filter_boolean_themes_array');
->with('iterable_datasource');

dataset('filter_boolean_join', [
'tailwind -> id' => [DishesTable::class, (object) ['theme' => \PowerComponents\LivewirePowerGrid\Themes\Tailwind::class, 'field' => 'id']],
Expand All @@ -390,14 +394,11 @@ public function filters(): array
'daisyui query builder -> id' => [DishesQueryBuilderTable::class, (object) ['theme' => \PowerComponents\LivewirePowerGrid\Themes\DaisyUI::class, 'field' => 'id']],
]);

dataset('filter_boolean_themes_array', [
[DishesArrayTable::class, \PowerComponents\LivewirePowerGrid\Themes\Tailwind::class],
[DishesArrayTable::class, \PowerComponents\LivewirePowerGrid\Themes\Bootstrap5::class],
[DishesArrayTable::class, \PowerComponents\LivewirePowerGrid\Themes\DaisyUI::class],
]);

dataset('filter_boolean_themes_collection', [
'tailwind' => [DishesCollectionTable::class, \PowerComponents\LivewirePowerGrid\Themes\Tailwind::class],
'bootstrap' => [DishesCollectionTable::class, \PowerComponents\LivewirePowerGrid\Themes\Bootstrap5::class],
'daisyui' => [DishesCollectionTable::class, \PowerComponents\LivewirePowerGrid\Themes\DaisyUI::class],
dataset('iterable_datasource', [
'tailwind datasource array' => [DishesIterableTable::class, \PowerComponents\LivewirePowerGrid\Themes\Tailwind::class, 'array'],
'bootstrap datasource array' => [DishesIterableTable::class, \PowerComponents\LivewirePowerGrid\Themes\Bootstrap5::class, 'array'],
'daisyui datasource array' => [DishesIterableTable::class, \PowerComponents\LivewirePowerGrid\Themes\DaisyUI::class, 'array'],
'tailwind datasource collection' => [DishesIterableTable::class, \PowerComponents\LivewirePowerGrid\Themes\Tailwind::class, 'collection'],
'bootstrap datasource collection' => [DishesIterableTable::class, \PowerComponents\LivewirePowerGrid\Themes\Bootstrap5::class, 'collection'],
'daisyui datasource collection' => [DishesIterableTable::class, \PowerComponents\LivewirePowerGrid\Themes\DaisyUI::class, 'collection'],
]);
Loading