Skip to content

Commit

Permalink
[Behat] Removed hardcoded button positions
Browse files Browse the repository at this point in the history
  • Loading branch information
mnocon committed Nov 7, 2023
1 parent 161f563 commit 992f9b1
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions src/lib/Behat/Component/Fields/RichText.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,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
Expand Down Expand Up @@ -194,20 +192,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);
Expand Down

0 comments on commit 992f9b1

Please sign in to comment.