From 941cf2572e507c53191d5da835b37e457329f27c Mon Sep 17 00:00:00 2001 From: Luan Freitas <33601626+luanfreitasdev@users.noreply.github.com> Date: Mon, 18 Nov 2024 16:52:42 -0300 Subject: [PATCH] Fix Header::can method (#1774) --- src/Components/Filters/Builders/InputText.php | 2 +- src/Concerns/HasActions.php | 3 +++ .../cypress/e2e/header/header-can.cy.js | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/cypress/cypress/e2e/header/header-can.cy.js diff --git a/src/Components/Filters/Builders/InputText.php b/src/Components/Filters/Builders/InputText.php index 7058e6444..9cce80cb9 100644 --- a/src/Components/Filters/Builders/InputText.php +++ b/src/Components/Filters/Builders/InputText.php @@ -117,7 +117,7 @@ public function collection(Collection $collection, string $field, int|array|stri 'is_empty' => $collection->filter(function ($row) use ($field) { $row = (object) $row; - return $row->{$field} == '' || is_null($row->{$field}); + return $row->{$field} == '' || is_null($row->{$field}); // @phpstan-ignore-line }), 'is_not_empty' => $collection->filter(function ($row) use ($field) { $row = (object) $row; diff --git a/src/Concerns/HasActions.php b/src/Concerns/HasActions.php index 39cb6c92a..09997b8fc 100644 --- a/src/Concerns/HasActions.php +++ b/src/Concerns/HasActions.php @@ -82,6 +82,8 @@ public function storeActionsHeaderInJSWindow(): void $actionsHtml = collect($this->header()) ->transform(function (Button $action) { + $can = data_get($action, 'can'); + return [ 'action' => $action->action, 'slot' => $action->slot, @@ -90,6 +92,7 @@ public function storeActionsHeaderInJSWindow(): void 'iconAttributes' => $action->iconAttributes, 'attributes' => $action->attributes, 'rules' => [], + 'can' => $can instanceof \Closure ? $can() : $can, ]; }); diff --git a/tests/cypress/cypress/e2e/header/header-can.cy.js b/tests/cypress/cypress/e2e/header/header-can.cy.js new file mode 100644 index 000000000..9679a9022 --- /dev/null +++ b/tests/cypress/cypress/e2e/header/header-can.cy.js @@ -0,0 +1,18 @@ +describe('Header can (show/hide)', () => { + [ + '/header-can?powerGridTheme=tailwind', + '/header-can?powerGridTheme=bootstrap' + ].forEach((route) => { + beforeEach(() => { + cy.visit(route); + }); + + it('can se only visible header button', () => { + cy.get('[data-cy="btn-header-visible"]').should("be.visible"); + + cy.get('body').should('contain.text', 'Visible'); + + cy.get('body').should('not.contain.text', 'Invisible'); + }) + }) +});