From e0d0b1d826c24dd66da5b0b3ac380455c5774edf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Noco=C5=84?= Date: Fri, 6 Oct 2023 11:10:36 +0200 Subject: [PATCH] Behat actions usage (#922) [Behat] Refactored code to use Actions --- .../Fields/ContentRelationSingle.php | 14 ++++++---- src/lib/Behat/Component/SubItemsList.php | 18 ++++++------ src/lib/Behat/Component/Table/TableRow.php | 28 ++++++------------- src/lib/Behat/Page/ContentTypeUpdatePage.php | 7 +++-- src/lib/Behat/Page/RoleUpdatePage.php | 6 ++-- 5 files changed, 30 insertions(+), 43 deletions(-) diff --git a/src/lib/Behat/Component/Fields/ContentRelationSingle.php b/src/lib/Behat/Component/Fields/ContentRelationSingle.php index 5c5c695329..f92808ab64 100644 --- a/src/lib/Behat/Component/Fields/ContentRelationSingle.php +++ b/src/lib/Behat/Component/Fields/ContentRelationSingle.php @@ -11,6 +11,7 @@ use Behat\Mink\Session; use Ibexa\AdminUi\Behat\Component\Table\TableBuilder; use Ibexa\AdminUi\Behat\Component\UniversalDiscoveryWidget; +use Ibexa\Behat\Browser\Element\Action\MouseOverAndClick; use Ibexa\Behat\Browser\Locator\CSSLocatorBuilder; use Ibexa\Behat\Browser\Locator\VisibleCSSLocator; use PHPUnit\Framework\Assert; @@ -46,18 +47,19 @@ public function __construct(Session $session, UniversalDiscoveryWidget $universa public function setValue(array $parameters): void { if (!$this->isRelationEmpty()) { - $this->getHTMLPage()->find($this->getLocator('buttonRemove'))->mouseOver(); - usleep(100 * 5000); // 500ms - $this->getHTMLPage()->find($this->getLocator('buttonRemove'))->click(); + $this->getHTMLPage() + ->find($this->getLocator('buttonRemove')) + ->execute(new MouseOverAndClick()); } $buttonLocator = CSSLocatorBuilder::base($this->parentLocator) ->withDescendant($this->getLocator('selectContent')) ->build(); - $this->getHTMLPage()->setTimeout(5)->find($buttonLocator)->mouseOver(); - usleep(100); - $this->getHTMLPage()->find($buttonLocator)->click(); + $this->getHTMLPage() + ->setTimeout(5) + ->find($buttonLocator) + ->execute(new MouseOverAndClick()); $this->universalDiscoveryWidget->verifyIsLoaded(); $this->universalDiscoveryWidget->selectContent($parameters['value']); diff --git a/src/lib/Behat/Component/SubItemsList.php b/src/lib/Behat/Component/SubItemsList.php index 268d05e4b4..8ac34dd4cb 100644 --- a/src/lib/Behat/Component/SubItemsList.php +++ b/src/lib/Behat/Component/SubItemsList.php @@ -13,6 +13,7 @@ use Ibexa\AdminUi\Behat\Component\Table\TableBuilder; use Ibexa\AdminUi\Behat\Component\Table\TableInterface; use Ibexa\Behat\Browser\Component\Component; +use Ibexa\Behat\Browser\Element\Action\MouseOverAndClick; use Ibexa\Behat\Browser\Element\Condition\ElementNotExistsCondition; use Ibexa\Behat\Browser\Element\Criterion\ElementTextCriterion; use Ibexa\Behat\Browser\Locator\CSSLocator; @@ -46,23 +47,20 @@ public function sortBy(string $columnName, bool $ascending): void return; } - $header = $this->getHTMLPage() + $this->getHTMLPage() ->setTimeout(3) ->findAll($this->getLocator('horizontalHeaders')) - ->getByCriterion(new ElementTextCriterion($columnName)); - $header->mouseOver(); - usleep(100 * 2500); // 250 ms TODO: Remove after redesign - $header->click(); + ->getByCriterion(new ElementTextCriterion($columnName)) + ->execute(new MouseOverAndClick()); + $isSortedDescending = $this->getHTMLPage()->findAll($this->getLocator('sortingOrderDescending'))->any(); if (!$isSortedDescending && !$ascending) { - $header = $this->getHTMLPage() + $this->getHTMLPage() ->setTimeout(3) ->findAll($this->getLocator('horizontalHeaders')) - ->getByCriterion(new ElementTextCriterion($columnName)); - $header->mouseOver(); - usleep(100 * 2500); // 250 ms TODO: Remove after redesign - $header->click(); + ->getByCriterion(new ElementTextCriterion($columnName)) + ->execute(new MouseOverAndClick()); } $verificationLocator = $ascending ? diff --git a/src/lib/Behat/Component/Table/TableRow.php b/src/lib/Behat/Component/Table/TableRow.php index 69bdde3239..341aae82f7 100644 --- a/src/lib/Behat/Component/Table/TableRow.php +++ b/src/lib/Behat/Component/Table/TableRow.php @@ -10,6 +10,7 @@ use Behat\Mink\Session; use Ibexa\Behat\Browser\Component\Component; +use Ibexa\Behat\Browser\Element\Action\MouseOverAndClick; use Ibexa\Behat\Browser\Element\ElementInterface; use Ibexa\Behat\Browser\Locator\LocatorCollection; use Ibexa\Behat\Browser\Locator\LocatorInterface; @@ -32,10 +33,7 @@ public function __construct(Session $session, ElementInterface $element, Locator public function goToItem(): void { - // TODO: Revisit during redesign - $this->element->find($this->getLocator('link'))->mouseOver(); - usleep(100 * 5000); // 500ms - $this->element->find($this->getLocator('link'))->click(); + $this->element->find($this->getLocator('link'))->execute(new MouseOverAndClick()); } public function select(): void @@ -45,34 +43,24 @@ public function select(): void public function edit(): void { - // TODO: Revisit during redesign - $this->element->find($this->getLocator('edit'))->mouseOver(); - usleep(100 * 5000); // 500ms - $this->element->find($this->getLocator('edit'))->click(); + $this->element->find($this->getLocator('edit'))->execute(new MouseOverAndClick()); } public function copy(): void { - // TODO: Revisit during redesign - $this->element->find($this->getLocator('copy'))->mouseOver(); - usleep(100 * 5000); // 500ms - $this->element->find($this->getLocator('copy'))->click(); + $this->element->find($this->getLocator('copy'))->execute(new MouseOverAndClick()); } public function deactivate(): void { - // TODO: Revisit during redesign - $this->element->find($this->getLocator('de-active'))->mouseOver(); - usleep(100 * 5000); // 500ms - $this->element->find($this->getLocator('de-active'))->click(); + $this->element->find($this->getLocator('de-active'))->execute(new MouseOverAndClick()); } public function activate(): void { - // TODO: Revisit during redesign - $this->element->find($this->getLocator('active'))->mouseOver(); - usleep(100 * 5000); // 500ms - $this->element->find($this->getLocator('active'))->click(); + $this->element + ->find($this->getLocator('active')) + ->execute(new MouseOverAndClick()); } public function assign(): void diff --git a/src/lib/Behat/Page/ContentTypeUpdatePage.php b/src/lib/Behat/Page/ContentTypeUpdatePage.php index b8b446847e..b2d252ef06 100644 --- a/src/lib/Behat/Page/ContentTypeUpdatePage.php +++ b/src/lib/Behat/Page/ContentTypeUpdatePage.php @@ -8,6 +8,7 @@ namespace Ibexa\AdminUi\Behat\Page; +use Ibexa\Behat\Browser\Element\Action\MouseOverAndClick; use Ibexa\Behat\Browser\Element\Condition\ElementExistsCondition; use Ibexa\Behat\Browser\Element\Condition\ElementNotExistsCondition; use Ibexa\Behat\Browser\Element\Condition\ElementsCountCondition; @@ -108,9 +109,9 @@ public function addFieldDefinition(string $fieldName) public function clickAddButton(): void { - $this->getHTMLPage()->find($this->getLocator('contentTypeAddButton'))->mouseOver(); - usleep(100 * 5000); // 500ms - $this->getHTMLPage()->find($this->getLocator('contentTypeAddButton'))->click(); + $this->getHTMLPage() + ->find($this->getLocator('contentTypeAddButton')) + ->execute(new MouseOverAndClick()); $this->getHTMLPage() ->setTimeout(3) ->waitUntilCondition( diff --git a/src/lib/Behat/Page/RoleUpdatePage.php b/src/lib/Behat/Page/RoleUpdatePage.php index a23dba2fd5..7d912c0c63 100644 --- a/src/lib/Behat/Page/RoleUpdatePage.php +++ b/src/lib/Behat/Page/RoleUpdatePage.php @@ -13,6 +13,7 @@ use Ibexa\AdminUi\Behat\Component\ContentActionsMenu; use Ibexa\AdminUi\Behat\Component\IbexaDropdown; use Ibexa\AdminUi\Behat\Component\UniversalDiscoveryWidget; +use Ibexa\Behat\Browser\Element\Action\MouseOverAndClick; use Ibexa\Behat\Browser\Element\Criterion\ChildElementTextCriterion; use Ibexa\Behat\Browser\Element\Criterion\ElementTextCriterion; use Ibexa\Behat\Browser\Locator\VisibleCSSLocator; @@ -135,10 +136,7 @@ public function selectSubtreeLimitationForPolicy(string $itemPath) ->findAll($this->getLocator('button')) ->filterBy(new ElementTextCriterion('Select Locations')) ->toArray(); - - $buttons[1]->mouseOver(); - usleep(100 * 2500); // 250 ms TODO: Remove after redesign is done - $buttons[1]->click(); + $buttons[1]->execute(new MouseOverAndClick()); $this->universalDiscoveryWidget->verifyIsLoaded(); $this->universalDiscoveryWidget->selectContent($itemPath);