Skip to content

Commit

Permalink
added new CheckBox widget, fixed IndexPage method and added filter an…
Browse files Browse the repository at this point in the history
…d sorting to Grid class (#106)

* added new CheckBox widget and fixed IndexPage method

* added php doc to function

* changed input element style

* added sort and filter to grid class

* added space in grid
  • Loading branch information
strorch authored and SilverFire committed May 15, 2019
1 parent 090eb4b commit 72fae73
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/widgets/IndexPage.php
Expand Up @@ -439,6 +439,7 @@ public function withPermission(string $permission, string $button): ?string
if (Yii::$app->user->can($permission)) {
return $button;
}
return null;
}
/**
Expand Down
22 changes: 11 additions & 11 deletions tests/_support/Page/IndexPage.php
Expand Up @@ -18,6 +18,11 @@

class IndexPage extends Authenticated
{
/**
* @var string
*/
protected $gridPath = "//form[contains(@id, 'bulk') and contains(@id, 'search')]";

/**
* @param TestableInput[] $inputs example:
* ```php
Expand Down Expand Up @@ -74,8 +79,7 @@ public function containsBulkButtons(array $buttons): void
public function containsColumns(array $columnNames, $representation = null): void
{
$I = $this->tester;
$gridPath = "//form[contains(@id, 'bulk') and contains(@id, 'search')]";
(new Grid($I, $gridPath))
(new Grid($I, $this->gridPath))
->containsColumns($columnNames, $representation);
}

Expand All @@ -98,17 +102,13 @@ public function getRowDataKeyByNumber(int $rowNumber): string
* Filters index page table.
*
* @param TestableInput $inputElement
* @param $value
* @param string $value
* @throws \Codeception\Exception\ModuleException
*/
public function filterBy(TestableInput $inputElement, string $value): void
{
$inputElement->setValue($value);
if ($inputElement instanceof Input) {
$this->tester->pressKey($inputElement->getSelector(),WebDriverKeys::ENTER);
}
$this->tester->wait(1);
$this->tester->waitForPageUpdate();
$I = $this->tester;
(new Grid($I, $this->gridPath))->filterBy($inputElement, $value);
}

/**
Expand Down Expand Up @@ -190,8 +190,8 @@ public function checkFilterBy(string $filterBy, string $name): void
*/
public function sortBy(string $columnName): void
{
$this->tester->click("//th/a[contains(text(), '$columnName')]");
$this->tester->waitForPageUpdate();
$I = $this->tester;
(new Grid($I, $this->gridPath))->sortBy($columnName);
}

/**
Expand Down
33 changes: 32 additions & 1 deletion tests/_support/Page/Widget/Grid.php
Expand Up @@ -4,6 +4,9 @@

use hipanel\tests\_support\AcceptanceTester;
use hipanel\tests\_support\Page\Authenticated;
use hipanel\tests\_support\Page\Widget\Input\Input;
use hipanel\tests\_support\Page\Widget\Input\TestableInput;
use WebDriverKeys;

class Grid extends Authenticated
{
Expand Down Expand Up @@ -38,4 +41,32 @@ public function containsColumns(array $columnNames, $representation = null): voi
$I->see($column, "//form[@id='$formId']//table/thead/tr/th");
}
}
}

/**
* Filters grids table.
*
* @param TestableInput $inputElement
* @param string $value
* @throws \Codeception\Exception\ModuleException
*/
public function filterBy(TestableInput $inputElement, string $value): void
{
$inputElement->setValue($value);
if ($inputElement instanceof Input) {
$this->tester->pressKey($inputElement->getSelector(), WebDriverKeys::ENTER);
}
$this->tester->waitForPageUpdate();
}

/**
* Sorts grid by specified column.
*
* @param string $columnName
* @throws \Codeception\Exception\ModuleException
*/
public function sortBy(string $columnName): void
{
$this->tester->click("//th/a[contains(text(), '$columnName')]");
$this->tester->waitForPageUpdate();
}
}
60 changes: 60 additions & 0 deletions tests/_support/Page/Widget/Input/CheckBox.php
@@ -0,0 +1,60 @@
<?php

namespace hipanel\tests\_support\Page\Widget\Input;

/**
* Class CheckBox.
*
* Represents checkbox element
*/
class CheckBox extends TestableInput
{
/**
* @return string
*/
protected function getSearchSelector(): string
{
// TODO: Implement getSearchSelector() method.
}

/**
* @return string
*/
protected function getFilterSelector(): string
{
// TODO: Implement getFilterSelector() method.
}

/**
* @param string $value
*/
public function setValue(string $value): void
{
$checkBoxState = $this->getCheckBoxState();
if ($checkBoxState === (bool)$value) {
return;
}
$this->clickCheckBox();
}

private function clickCheckBox(): void
{
$this->tester->executeJS(<<<JS
document.querySelector(arguments[0]).click();
JS
, [$this->selector]);
}

/**
* @return bool
*/
private function getCheckBoxState(): bool
{
$state = $this->tester->executeJS(<<<JS
return document.querySelector(arguments[0]).checked;
JS
, [$this->selector]);

return $state;
}
}

0 comments on commit 72fae73

Please sign in to comment.