-
-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c933120
commit 23ac059
Showing
8 changed files
with
215 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
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,80 @@ | ||
<?php | ||
|
||
use PowerComponents\LivewirePowerGrid\Facades\Rule; | ||
use PowerComponents\LivewirePowerGrid\Tests\Concerns\Components\DishesTable; | ||
use PowerComponents\LivewirePowerGrid\{Button, Column, Detail}; | ||
|
||
$baseRuleComponent = new class () extends DishesTable { | ||
public function setUp(): array | ||
{ | ||
$this->showCheckBox(); | ||
|
||
return [ | ||
...parent::setUp(), | ||
|
||
Detail::make() | ||
->view('components.detail') | ||
->showCollapseIcon() | ||
->params(['name' => 'Luan']), | ||
]; | ||
} | ||
|
||
public function columns(): array | ||
{ | ||
return [ | ||
Column::make('id', 'id'), | ||
|
||
Column::add() | ||
->title('In Stock') | ||
->field('in_stock') | ||
->toggleable(hasPermission: true, trueLabel: 'it-is-in-stock', falseLabel: 'it-is-not-in-stock') | ||
->sortable(), | ||
|
||
Column::make('NEVER HAS TOGGLEABLE', 'active') | ||
->toggleable(hasPermission: false, trueLabel: 'it-is-active', falseLabel: 'it-is-not-active') | ||
->sortable(), | ||
|
||
Column::make('Name', 'name') | ||
->searchable() | ||
->editOnClick(hasPermission: true, dataField: 'name') | ||
->sortable(), | ||
|
||
Column::make('NEVER HAS EDIT ON CLICK', 'serving_at') | ||
->searchable() | ||
->sortable(), | ||
|
||
Column::action('Action'), | ||
]; | ||
} | ||
|
||
public function actions($row): array | ||
{ | ||
return [ | ||
Button::make('dispatch') | ||
->slot('dispatch: ' . $row->id) | ||
->dispatch('executeDispatch', ['id' => $row->id]), | ||
]; | ||
} | ||
|
||
public function actionRules($row): array | ||
{ | ||
return [ | ||
Rule::rows() | ||
->when(fn ($dish) => $dish->id == 1) | ||
->hideToggleDetail(), | ||
|
||
Rule::toggleable('active') | ||
->when(fn ($dish) => $dish->id == 1) | ||
->show(), | ||
|
||
Rule::editOnClick('serving_at') | ||
->when(fn ($dish) => $dish->id == 1) | ||
->enable(), | ||
|
||
Rule::rows() | ||
->when(fn ($dish) => $dish->id == 5) | ||
->hideToggleable() | ||
->disableEditOnClick(), | ||
]; | ||
} | ||
}; |
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 was deleted.
Oops, something went wrong.
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,23 @@ | ||
<?php | ||
|
||
use function PowerComponents\LivewirePowerGrid\Tests\Plugins\livewire; | ||
|
||
require(__DIR__ . '/../../Concerns/Components/ComponentsForTestRule.php'); | ||
|
||
it('properly enabled EditOnClick with Rule::toggleable for dish #1 in a column that has it disabled', function (string $baseRuleComponent, object $params) { | ||
livewire($baseRuleComponent, [ | ||
'join' => $params->join, | ||
])->call($params->theme) | ||
->set('setUp.footer.perPage', 5) | ||
->assertSeeHtml("pgEditable(JSON.parse('{\u0022theme\u0022:\u0022{$params->themeName}\u0022,\u0022tableName\u0022:\u0022default\u0022,\u0022id\u0022:1,\u0022dataField\u0022:\u0022serving_at") | ||
->assertDontSeeHtml("pgEditable(JSON.parse('{\u0022theme\u0022:\u0022{$params->themeName}\u0022,\u0022tableName\u0022:\u0022default\u0022,\u0022id\u0022:2,\u0022dataField\u0022:\u0022serving_at") | ||
->assertDontSeeHtml("pgEditable(JSON.parse('{\u0022theme\u0022:\u0022{$params->themeName}\u0022,\u0022tableName\u0022:\u0022default\u0022,\u0022id\u0022:3,\u0022dataField\u0022:\u0022serving_at"); | ||
}) | ||
->with([ | ||
'tailwind using when' => [$baseRuleComponent::class, (object) ['theme' => 'tailwind', 'join' => false, 'themeName' => 'tailwind']], | ||
'bootstrap using when' => [$baseRuleComponent::class, (object) ['theme' => 'bootstrap', 'join' => false, 'themeName' => 'bootstrap5']], | ||
'tailwind join using when' => [$baseRuleComponent::class, (object) ['theme' => 'tailwind', 'join' => true, 'themeName' => 'tailwind']], | ||
'bootstrap join using when' => [$baseRuleComponent::class, (object) ['theme' => 'bootstrap', 'join' => true, 'themeName' => 'bootstrap5']], | ||
]) | ||
->only() | ||
->group('actionRules'); |
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,23 @@ | ||
<?php | ||
|
||
use function PowerComponents\LivewirePowerGrid\Tests\Plugins\livewire; | ||
|
||
require(__DIR__ . '/../../Concerns/Components/ComponentsForTestRule.php'); | ||
|
||
it('properly hides the toggle detail button', function (string $baseRuleComponent, object $params) { | ||
livewire($baseRuleComponent, [ | ||
'join' => $params->join, | ||
])->call($params->theme) | ||
->set('setUp.footer.perPage', 5) | ||
->assertDontSeeHtml('$wire.toggleDetail(\'1\')') | ||
->assertSeeHtml('$wire.toggleDetail(\'2\')') | ||
->assertSeeHtml('$wire.toggleDetail(\'3\')'); | ||
}) | ||
->with([ | ||
'tailwind using when' => [$baseRuleComponent::class, (object) ['theme' => 'tailwind', 'join' => false]], | ||
'bootstrap using when' => [$baseRuleComponent::class, (object) ['theme' => 'bootstrap', 'join' => false]], | ||
'tailwind join using when' => [$baseRuleComponent::class, (object) ['theme' => 'tailwind', 'join' => true]], | ||
'bootstrap join using when' => [$baseRuleComponent::class, (object) ['theme' => 'bootstrap', 'join' => true], | ||
], | ||
]) | ||
->group('actionRules'); |
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,46 @@ | ||
<?php | ||
|
||
use function PowerComponents\LivewirePowerGrid\Tests\Plugins\livewire; | ||
|
||
require(__DIR__ . '/../../Concerns/Components/ComponentsForTestRule.php'); | ||
|
||
it('properly hides toggleable with Row->hideToggleable() for dish #5', function (string $baseRuleComponent, object $params) { | ||
livewire($baseRuleComponent, [ | ||
'join' => $params->join, | ||
])->call($params->theme) | ||
->set('setUp.footer.perPage', 5) | ||
->assertDontSeeHtml("pgToggleable(JSON.parse('{\u0022id\u0022:5,\u0022isHidden\u0022:false,\u0022tableName\u0022:\u0022default\u0022,\u0022field\u0022:\u0022in_stock\u0022,") | ||
->assertSeeHtmlInOrder( | ||
[ | ||
"pgToggleable(JSON.parse('{\u0022id\u0022:3,\u0022isHidden\u0022:false,\u0022tableName\u0022:\u0022default\u0022,\u0022field\u0022:\u0022in_stock\u0022,", | ||
|
||
"pgToggleable(JSON.parse('{\u0022id\u0022:4,\u0022isHidden\u0022:false,\u0022tableName\u0022:\u0022default\u0022,\u0022field\u0022:\u0022in_stock\u0022,", | ||
] | ||
); | ||
}) | ||
->with([ | ||
'tailwind using when' => [$baseRuleComponent::class, (object) ['theme' => 'tailwind', 'join' => false]], | ||
'bootstrap using when' => [$baseRuleComponent::class, (object) ['theme' => 'bootstrap', 'join' => false]], | ||
'tailwind join using when' => [$baseRuleComponent::class, (object) ['theme' => 'tailwind', 'join' => true]], | ||
'bootstrap join using when' => [$baseRuleComponent::class, (object) ['theme' => 'bootstrap', 'join' => true], | ||
], | ||
]) | ||
->group('actionRules'); | ||
|
||
it('properly shows toggleable with Rule::toggleable for dish #1', function (string $baseRuleComponent, object $params) { | ||
livewire($baseRuleComponent, [ | ||
'join' => $params->join, | ||
])->call($params->theme) | ||
->set('setUp.footer.perPage', 5) | ||
->assertSeeHtml("pgToggleable(JSON.parse('{\u0022id\u0022:1,\u0022isHidden\u0022:false,\u0022tableName\u0022:\u0022default\u0022,\u0022field\u0022:\u0022active\u0022,") | ||
->assertSeeHtml("pgToggleable(JSON.parse('{\u0022id\u0022:2,\u0022isHidden\u0022:true,\u0022tableName\u0022:\u0022default\u0022,\u0022field\u0022:\u0022active\u0022,") | ||
->assertSeeHtml("pgToggleable(JSON.parse('{\u0022id\u0022:3,\u0022isHidden\u0022:true,\u0022tableName\u0022:\u0022default\u0022,\u0022field\u0022:\u0022active\u0022,"); | ||
}) | ||
->with([ | ||
'tailwind using when' => [$baseRuleComponent::class, (object) ['theme' => 'tailwind', 'join' => false]], | ||
'bootstrap using when' => [$baseRuleComponent::class, (object) ['theme' => 'bootstrap', 'join' => false]], | ||
'tailwind join using when' => [$baseRuleComponent::class, (object) ['theme' => 'tailwind', 'join' => true]], | ||
'bootstrap join using when' => [$baseRuleComponent::class, (object) ['theme' => 'bootstrap', 'join' => true], | ||
], | ||
]) | ||
->group('actionRules'); |