Skip to content

Commit

Permalink
Start add filters cypress test
Browse files Browse the repository at this point in the history
  • Loading branch information
luanfreitasdev committed Dec 18, 2023
1 parent 51683ca commit a2ebc6b
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/cypress.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions tests/cypress/cypress/e2e/filters/number.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('simple', () => {
it('can visit filter page', () => {
cy.visit('/cypress?testType=filters');
})
})
43 changes: 39 additions & 4 deletions tests/cypress/stubs/CypressTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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) {
Expand All @@ -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(),
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions tests/cypress/stubs/filters-controller.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
<div data-cy="filters-log">
@json($filters)
</div>
</div>

0 comments on commit a2ebc6b

Please sign in to comment.