From 13586256cece90b2d11e513dd35e2d47ef6bd97d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Noco=C5=84?= Date: Tue, 7 Nov 2023 11:49:23 +0100 Subject: [PATCH] [Behat] Removed hardcoded button positions --- src/lib/Behat/Component/Fields/RichText.php | 30 ++++----------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/src/lib/Behat/Component/Fields/RichText.php b/src/lib/Behat/Component/Fields/RichText.php index 90f2054860..1fe5e34120 100644 --- a/src/lib/Behat/Component/Fields/RichText.php +++ b/src/lib/Behat/Component/Fields/RichText.php @@ -8,13 +8,11 @@ namespace Ibexa\AdminUi\Behat\Component\Fields; -use Behat\Mink\Session; use Ibexa\Behat\Browser\Element\Condition\ElementExistsCondition; use Ibexa\Behat\Browser\Element\Criterion\ElementTextCriterion; use Ibexa\Behat\Browser\Element\ElementInterface; use Ibexa\Behat\Browser\Element\Mapper\ElementTextMapper; use Ibexa\Behat\Browser\Locator\VisibleCSSLocator; -use Ibexa\FieldTypeRichText\Configuration\Provider\CustomStyle; use PHPUnit\Framework\Assert; class RichText extends FieldTypeComponent @@ -29,15 +27,6 @@ class RichText extends FieldTypeComponent 'Heading 6' => 'h6', ]; - /** @var \Ibexa\FieldTypeRichText\Configuration\Provider\CustomStyle */ - private $customStyleProvider; - - public function __construct(Session $session, CustomStyle $customStyleProvider) - { - parent::__construct($session); - $this->customStyleProvider = $customStyleProvider; - } - private function getFieldInput(): ElementInterface { return $this->getHTMLPage()->find($this->parentLocator)->find($this->getLocator('fieldInput')); @@ -141,16 +130,14 @@ public function addUnorderedList(array $listElements): void public function clickEmbedInlineButton(): void { - $buttonPosition = 11 + $this->getCustomStylesOffset(); $this->openElementsToolbar(); - $this->clickElementsToolbarButton($buttonPosition); + $this->clickElementsToolbarButton('Embed inline'); } public function clickEmbedButton(): void { - $buttonPosition = 8 + $this->getCustomStylesOffset(); $this->openElementsToolbar(); - $this->clickElementsToolbarButton($buttonPosition); + $this->clickElementsToolbarButton('Embed'); } public function equalsEmbedInlineItem($itemName): bool @@ -194,20 +181,13 @@ private function executeCommand(string $commandName): void $this->getSession()->executeScript($script); } - private function getCustomStylesOffset(): int - { - return count(array_filter($this->customStyleProvider->getConfiguration(), static function (array $config): bool { - return $config['inline'] === true; - })); - } - - private function clickElementsToolbarButton(int $buttonPosition): void + private function clickElementsToolbarButton(string $buttonText): void { $script = sprintf( - "document.querySelectorAll('%s %s')[%d].click()", + "Array.from(document.querySelectorAll('%s %s')).filter(e => e.textContent =='%s')[0].click()", $this->getLocator('additionalToolbar')->getSelector(), $this->getLocator('toolbarElement')->getSelector(), - $buttonPosition, + $buttonText ); $this->getSession()->executeScript($script);