Skip to content

Commit

Permalink
[Behat] Extract waitForFormUpdate function to CrudFormElement
Browse files Browse the repository at this point in the history
  • Loading branch information
Wojdylak authored and GSadee committed May 15, 2024
1 parent e6deeb4 commit e3909ab
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,4 @@ protected function getDefinedElements(): array
'start_date_time' => '#sylius_catalog_promotion_startDate_time',
]);
}

private function waitForFormUpdate(): void
{
$form = $this->getElement('form');
sleep(1); // we need to sleep, as sometimes the check below is executed faster than the form sets the busy attribute
$form->waitFor(1500, function () use ($form) {
return !$form->hasAttribute('busy');
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
namespace Sylius\Behat\Element\Admin\Channel;

use Behat\Mink\Session;
use FriendsOfBehat\PageObjectExtension\Element\Element;
use FriendsOfBehat\SymfonyExtension\Mink\MinkParameters;
use Sylius\Behat\Element\Admin\Crud\FormElement as BaseFormElement;
use Sylius\Behat\Service\Helper\AutocompleteHelperInterface;
use Sylius\Component\Core\Model\TaxonInterface;

final class ExcludeTaxonsFromShowingLowestPriceInputElement extends Element implements ExcludeTaxonsFromShowingLowestPriceInputElementInterface
final class ExcludeTaxonsFromShowingLowestPriceInputElement extends BaseFormElement implements ExcludeTaxonsFromShowingLowestPriceInputElementInterface
{
public function __construct(
Session $session,
array|MinkParameters $minkParameters = [],
array|MinkParameters $minkParameters,
private AutocompleteHelperInterface $autocompleteHelper,
) {
parent::__construct($session, $minkParameters);
Expand Down Expand Up @@ -68,13 +68,4 @@ protected function getDefinedElements(): array
'taxons_excluded_from_showing_lowest_price' => '[data-test-taxons-excluded-from-showing-lowest-price]',
]);
}

private function waitForFormUpdate(): void
{
$form = $this->getElement('form');
sleep(1); // we need to sleep, as sometimes the check below is executed faster than the form sets the busy attribute
$form->waitFor(1500, function () use ($form) {
return !$form->hasAttribute('busy');
});
}
}
9 changes: 9 additions & 0 deletions src/Sylius/Behat/Element/Admin/Crud/FormElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ public function getValidationMessage(string $element, array $parameters = []): s
return $validationMessage->getText();
}

protected function waitForFormUpdate(): void
{
$form = $this->getElement('form');
sleep(1); // we need to sleep, as sometimes the check below is executed faster than the form sets the busy attribute
$form->waitFor(1500, function () use ($form) {
return !$form->hasAttribute('busy');
});
}

/** @throws ElementNotFoundException */
private function getFieldElement(string $element, array $parameters): ?NodeElement
{
Expand Down
9 changes: 0 additions & 9 deletions src/Sylius/Behat/Element/Admin/Promotion/FormElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,13 +277,4 @@ private function getChannelConfigurationOfLastRule(string $channelCode): NodeEle
sprintf('[id^="sylius_promotion_rules_"][id$="_configuration_%s"]', $channelCode),
);
}

private function waitForFormUpdate(): void
{
$form = $this->getElement('form');
sleep(1); // we need to sleep, as sometimes the check below is executed faster than the form sets the busy attribute
$form->waitFor(1500, function () use ($form) {
return !$form->hasAttribute('busy');
});
}
}
7 changes: 0 additions & 7 deletions src/Sylius/Behat/Element/Admin/ShippingMethod/FormElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,11 +176,4 @@ private function selectCalculatorConfigurationChannelTab(string $channelCode): v

$this->getElement('calculator_configuration_channel_tab', ['%channelCode%' => $channelCode])->click();
}

private function waitForFormUpdate(): void
{
$form = $this->getElement('form');
usleep(500000);
$form->waitFor(1500, fn () => !$form->hasAttribute('busy'));
}
}
9 changes: 0 additions & 9 deletions src/Sylius/Behat/Element/Admin/Taxon/FormElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,4 @@ protected function getDefinedElements(): array
'slug' => '[name="taxon[translations][%locale_code%][slug]"]',
]);
}

private function waitForFormUpdate(): void
{
$form = $this->getElement('form');
sleep(1); // we need to sleep, as sometimes the check below is executed faster than the form sets the busy attribute
$form->waitFor(1500, function () use ($form) {
return !$form->hasAttribute('busy');
});
}
}

0 comments on commit e3909ab

Please sign in to comment.