From a2ebc6be922954ac8efd7b7e1bdf85153f0ee5d7 Mon Sep 17 00:00:00 2001 From: luanfreitasdev Date: Mon, 18 Dec 2023 17:57:07 -0300 Subject: [PATCH] Start add filters cypress test --- .github/workflows/cypress.yml | 1 + .../cypress/cypress/e2e/filters/number.cy.js | 5 +++ tests/cypress/stubs/CypressTable.php | 43 +++++++++++++++++-- .../stubs/filters-controller.blade.php | 5 +++ 4 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 tests/cypress/cypress/e2e/filters/number.cy.js create mode 100644 tests/cypress/stubs/filters-controller.blade.php diff --git a/.github/workflows/cypress.yml b/.github/workflows/cypress.yml index eb5fa77e..68a71b5f 100644 --- a/.github/workflows/cypress.yml +++ b/.github/workflows/cypress.yml @@ -76,6 +76,7 @@ jobs: cd tests/cypress && cp stubs/CypressTable.php app/app/Livewire/CypressTable.php && cp stubs/rules-controllers.blade.php app/resources/views/components/header/rules-controllers.blade.php + cp stubs/filters-controllers.blade.php app/resources/views/components/header/filters-controllers.blade.php cd ./../../ chmod +x ./tests/cypress/run.sh ./tests/cypress/run.sh diff --git a/tests/cypress/cypress/e2e/filters/number.cy.js b/tests/cypress/cypress/e2e/filters/number.cy.js new file mode 100644 index 00000000..067b0ed4 --- /dev/null +++ b/tests/cypress/cypress/e2e/filters/number.cy.js @@ -0,0 +1,5 @@ +describe('simple', () => { + it('can visit filter page', () => { + cy.visit('/cypress?testType=filters'); + }) +}) diff --git a/tests/cypress/stubs/CypressTable.php b/tests/cypress/stubs/CypressTable.php index ad062a66..bb39e63d 100644 --- a/tests/cypress/stubs/CypressTable.php +++ b/tests/cypress/stubs/CypressTable.php @@ -7,7 +7,15 @@ use Illuminate\Support\Carbon; use Livewire\Attributes\Url; use PowerComponents\LivewirePowerGrid\Traits\WithExport; -use PowerComponents\LivewirePowerGrid\{Button, Column, Exportable, Footer, Header, PowerGrid, PowerGridColumns, PowerGridComponent}; +use PowerComponents\LivewirePowerGrid\{Button, + Column, + Exportable, + Facades\Filter, + Footer, + Header, + PowerGrid, + PowerGridColumns, + PowerGridComponent}; final class CypressTable extends PowerGridComponent { @@ -20,6 +28,9 @@ final class CypressTable extends PowerGridComponent #[Url] public int $rule = 1; + #[Url] + public string $testType = 'rule'; // rule, filters + public function setUp(): array { if ($this->rule === 4) { @@ -30,13 +41,24 @@ public function setUp(): array $this->showCheckBox(); } + $headerTest = match ($this->testType) { + 'filters' => [ + Header::make() + ->includeViewOnTop('components.header.filters-controllers') + ->showSearchInput(), + ], + default => [ + Header::make() + ->includeViewOnTop('components.header.rules-controllers') + ->showSearchInput(), + ], + }; + return [ Exportable::make('export') ->striped() ->type(Exportable::TYPE_XLS, Exportable::TYPE_CSV), - Header::make() - ->includeViewOnTop('components.header.rules-controllers') - ->showSearchInput(), + ...$headerTest, Footer::make() ->showPerPage() ->showRecordCount(), @@ -96,6 +118,19 @@ public function applyRules(): void $this->applyRules = true; } + public function filters(): array + { + return [ + Filter::inputText('name'), + Filter::inputText('email'), + Filter::number('id'), + Filter::datetimepicker('created_at_formatted', 'created_at') + ->params([ + 'timezone' => 'America/Sao_Paulo', + ]), + ]; + } + public function actionRules($row): array { $apply = null; diff --git a/tests/cypress/stubs/filters-controller.blade.php b/tests/cypress/stubs/filters-controller.blade.php new file mode 100644 index 00000000..a70b3f4f --- /dev/null +++ b/tests/cypress/stubs/filters-controller.blade.php @@ -0,0 +1,5 @@ +
+
+ @json($filters) +
+