Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Behat] Removed hardcoded button positions #980

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 5 additions & 25 deletions src/lib/Behat/Component/Fields/RichText.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'));
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Loading