Skip to content

Commit

Permalink
Fix Header::can method (#1774)
Browse files Browse the repository at this point in the history
  • Loading branch information
luanfreitasdev authored Nov 18, 2024
1 parent ac29ea8 commit 941cf25
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Components/Filters/Builders/InputText.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/Concerns/HasActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -90,6 +92,7 @@ public function storeActionsHeaderInJSWindow(): void
'iconAttributes' => $action->iconAttributes,
'attributes' => $action->attributes,
'rules' => [],
'can' => $can instanceof \Closure ? $can() : $can,
];
});

Expand Down
18 changes: 18 additions & 0 deletions tests/cypress/cypress/e2e/header/header-can.cy.js
Original file line number Diff line number Diff line change
@@ -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');
})
})
});

0 comments on commit 941cf25

Please sign in to comment.