Skip to content

Commit

Permalink
Merge pull request Sylius#7843 from NeverResponse/why-slug-more-slug
Browse files Browse the repository at this point in the history
[Behat] Upgraded javascript related tests
  • Loading branch information
pjedrzejewski committed Mar 28, 2017
2 parents 1d849e4 + 2b96efe commit 3a997f3
Show file tree
Hide file tree
Showing 15 changed files with 208 additions and 100 deletions.
Expand Up @@ -3,7 +3,7 @@ Feature: Editing taxon's slug in multiple locales
In order to manage access path to taxon page in many languages
As an Administrator
I want to be able to edit taxon's slug in multiple locales

Background:
Given the store is available in "English (United States)"
And the store is also available in "Polish (Poland)"
Expand Down
Expand Up @@ -417,7 +417,7 @@ public function theCodeFieldShouldBeDisabled()
*/
public function theSlugFieldShouldNotBeEditable($localeCode = 'en_US')
{
Assert::true($this->updateSimpleProductPage->isSlugReadOnlyIn($localeCode));
Assert::true($this->updateSimpleProductPage->isSlugReadonlyIn($localeCode));
}

/**
Expand Down
Expand Up @@ -155,9 +155,7 @@ public function iAddTheHasTaxonRuleConfiguredWith(...$taxons)
{
$this->createPage->addRule('Has at least one from taxons');

foreach ($taxons as $taxon) {
$this->createPage->selectAutocompleteRuleOption('Taxons', $taxon, true);
}
$this->createPage->selectAutocompleteRuleOption('Taxons', $taxons, true);
}

/**
Expand Down
Expand Up @@ -138,7 +138,7 @@ public function iSetItsSlugToIn($slug = null, $language = 'en_US')
*/
public function theSlugFieldShouldNotBeEditable($language = 'en_US')
{
Assert::true($this->updatePage->isSlugReadOnly($language));
Assert::true($this->updatePage->isSlugReadonly($language));
}

/**
Expand Down
Expand Up @@ -15,6 +15,7 @@
use Behat\Mink\Element\NodeElement;
use Sylius\Behat\Behaviour\SpecifiesItsCode;
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
use Sylius\Behat\Service\SlugGenerationHelper;
use Webmozart\Assert\Assert;

/**
Expand All @@ -33,7 +34,9 @@ public function nameItIn($name, $localeCode)
sprintf('sylius_product_translations_%s_name', $localeCode), $name
);

$this->waitForSlugGenerationIfNecessary();
if ($this->getDriver() instanceof Selenium2Driver) {
SlugGenerationHelper::waitForSlugGeneration($this->getSession(), $this->getElement('slug'));
}
}

/**
Expand Down Expand Up @@ -100,13 +103,4 @@ private function getLastImageElement()

return end($items);
}

private function waitForSlugGenerationIfNecessary()
{
if ($this->getDriver() instanceof Selenium2Driver) {
$this->getDocument()->waitFor(10, function () {
return '' !== $this->getElement('slug')->getValue();
});
}
}
}
20 changes: 7 additions & 13 deletions src/Sylius/Behat/Page/Admin/Product/CreateSimpleProductPage.php
Expand Up @@ -15,6 +15,7 @@
use Behat\Mink\Element\NodeElement;
use Sylius\Behat\Behaviour\SpecifiesItsCode;
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
use Sylius\Behat\Service\SlugGenerationHelper;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Currency\Model\CurrencyInterface;
use Sylius\Component\Product\Model\ProductAssociationTypeInterface;
Expand Down Expand Up @@ -44,7 +45,12 @@ public function nameItIn($name, $localeCode)
$this->activateLanguageTab($localeCode);
$this->getElement('name', ['%locale%' => $localeCode])->setValue($name);

$this->waitForSlugGenerationIfNecessary($localeCode);
if ($this->getDriver() instanceof Selenium2Driver) {
SlugGenerationHelper::waitForSlugGeneration(
$this->getSession(),
$this->getElement('slug', ['%locale%' => $localeCode])
);
}
}

/**
Expand Down Expand Up @@ -342,16 +348,4 @@ private function getLastImageElement()

return end($items);
}

/**
* @param string $locale
*/
private function waitForSlugGenerationIfNecessary($locale)
{
if ($this->getDriver() instanceof Selenium2Driver) {
$this->getDocument()->waitFor(10, function () use ($locale) {
return '' !== $this->getElement('slug', ['%locale%' => $locale])->getValue();
});
}
}
}
42 changes: 16 additions & 26 deletions src/Sylius/Behat/Page/Admin/Product/UpdateSimpleProductPage.php
Expand Up @@ -16,6 +16,7 @@
use Sylius\Behat\Behaviour\ChecksCodeImmutability;
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage;
use Sylius\Behat\Service\AutocompleteHelper;
use Sylius\Behat\Service\SlugGenerationHelper;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\TaxonInterface;
use Sylius\Component\Currency\Model\CurrencyInterface;
Expand All @@ -38,7 +39,12 @@ public function nameItIn($name, $localeCode)
$this->activateLanguageTab($localeCode);
$this->getElement('name', ['%locale%' => $localeCode])->setValue($name);

$this->waitForSlugGenerationIfNecessary($localeCode);
if ($this->getDriver() instanceof Selenium2Driver) {
SlugGenerationHelper::waitForSlugGeneration(
$this->getSession(),
$this->getElement('slug', ['%locale%' => $localeCode])
);
}
}

/**
Expand Down Expand Up @@ -113,8 +119,6 @@ public function selectMainTaxon(TaxonInterface $taxon)
{
$this->openTaxonBookmarks();

Assert::isInstanceOf($this->getDriver(), Selenium2Driver::class);

$mainTaxonElement = $this->getElement('main_taxon')->getParent();

AutocompleteHelper::chooseValue($this->getSession(), $mainTaxonElement, $taxon->getName());
Expand Down Expand Up @@ -153,7 +157,10 @@ public function isTracked()
*/
public function enableSlugModification($locale)
{
$this->getElement('toggle_slug_modification_button', ['%locale%' => $locale])->press();
SlugGenerationHelper::enableSlugModification(
$this->getSession(),
$this->getElement('toggle_slug_modification_button', ['%locale%' => $locale])
);
}

/**
Expand Down Expand Up @@ -248,9 +255,12 @@ public function countImages()
/**
* {@inheritdoc}
*/
public function isSlugReadOnlyIn($locale)
public function isSlugReadonlyIn($locale)
{
return 'readonly' === $this->getElement('slug', ['%locale%' => $locale])->getAttribute('readonly');
return SlugGenerationHelper::isSlugReadonly(
$this->getSession(),
$this->getElement('slug', ['%locale%' => $locale])
);
}

/**
Expand Down Expand Up @@ -517,26 +527,6 @@ private function getFirstImageElement()
return reset($imageElements);
}

/**
* @param string $locale
*/
private function waitForSlugGenerationIfNecessary($locale)
{
if (!$this->getDriver() instanceof Selenium2Driver) {
return;
}

$slugElement = $this->getElement('slug', ['%locale%' => $locale]);
if ($slugElement->hasAttribute('readonly')) {
return;
}

$value = $slugElement->getValue();
$this->getDocument()->waitFor(10, function () use ($slugElement, $value) {
return $value !== $slugElement->getValue();
});
}

/**
* @param NodeElement $imageElement
* @param string $type
Expand Down
Expand Up @@ -29,9 +29,11 @@ interface UpdateSimpleProductPageInterface extends BaseUpdatePageInterface
public function isCodeDisabled();

/**
* @param string $locale
*
* @return bool
*/
public function isSlugReadOnlyIn($locale);
public function isSlugReadonlyIn($locale);

/**
* @param string $channelName
Expand Down
12 changes: 12 additions & 0 deletions src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php
Expand Up @@ -66,6 +66,12 @@ public function selectAutocompleteRuleOption($option, $value, $multiple = false)
->getParent()
;

if ($multiple && is_array($value)) {
AutocompleteHelper::chooseValues($this->getSession(), $ruleAutocomplete, $value);

return;
}

AutocompleteHelper::chooseValue($this->getSession(), $ruleAutocomplete, $value);
}

Expand Down Expand Up @@ -200,6 +206,12 @@ public function selectAutoCompleteFilterOption($option, $value, $multiple = fals
->getParent()
;

if ($multiple && is_array($value)) {
AutocompleteHelper::chooseValues($this->getSession(), $filterAutocomplete, $value);

return;
}

AutocompleteHelper::chooseValue($this->getSession(), $filterAutocomplete, $value);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php
Expand Up @@ -44,7 +44,7 @@ public function selectRuleOption($option, $value, $multiple = false);

/**
* @param string $option
* @param string $value
* @param string|string[] $value
* @param bool $multiple
*/
public function selectAutocompleteRuleOption($option, $value, $multiple = false);
Expand Down Expand Up @@ -120,7 +120,7 @@ public function getValidationMessageForAction();

/**
* @param string $option
* @param string $value
* @param string|string[] $value
* @param bool $multiple
*/
public function selectAutoCompleteFilterOption($option, $value, $multiple = false);
Expand Down
20 changes: 7 additions & 13 deletions src/Sylius/Behat/Page/Admin/Taxon/CreatePage.php
Expand Up @@ -16,6 +16,7 @@
use Behat\Mink\Exception\ElementNotFoundException;
use Sylius\Behat\Behaviour\SpecifiesItsCode;
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
use Sylius\Behat\Service\SlugGenerationHelper;
use Sylius\Component\Core\Model\TaxonInterface;
use Webmozart\Assert\Assert;

Expand Down Expand Up @@ -91,7 +92,12 @@ public function nameIt($name, $languageCode)
$this->activateLanguageTab($languageCode);
$this->getElement('name', ['%language%' => $languageCode])->setValue($name);

$this->waitForSlugGenerationIfNecessary($languageCode);
if ($this->getDriver() instanceof Selenium2Driver) {
SlugGenerationHelper::waitForSlugGeneration(
$this->getSession(),
$this->getElement('slug', ['%language%' => $languageCode])
);
}
}

/**
Expand Down Expand Up @@ -194,16 +200,4 @@ private function getLastImageElement()

return end($items);
}

/**
* @param string $languageCode
*/
private function waitForSlugGenerationIfNecessary($languageCode)
{
if ($this->getDriver() instanceof Selenium2Driver) {
$this->getDocument()->waitFor(10, function () use ($languageCode) {
return '' !== $this->getElement('slug', ['%language%' => $languageCode])->getValue();
});
}
}
}
40 changes: 16 additions & 24 deletions src/Sylius/Behat/Page/Admin/Taxon/UpdatePage.php
Expand Up @@ -17,6 +17,7 @@
use Sylius\Behat\Behaviour\ChecksCodeImmutability;
use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage;
use Sylius\Behat\Service\AutocompleteHelper;
use Sylius\Behat\Service\SlugGenerationHelper;
use Sylius\Component\Core\Model\TaxonInterface;
use Webmozart\Assert\Assert;

Expand Down Expand Up @@ -51,7 +52,12 @@ public function nameIt($name, $languageCode)
$this->activateLanguageTab($languageCode);
$this->getDocument()->fillField(sprintf('sylius_taxon_translations_%s_name', $languageCode), $name);

$this->waitForSlugGenerationIfNecessary();
if ($this->getDriver() instanceof Selenium2Driver) {
SlugGenerationHelper::waitForSlugGeneration(
$this->getSession(),
$this->getElement('slug', ['%language%' => $languageCode])
);
}
}

/**
Expand Down Expand Up @@ -101,9 +107,12 @@ public function isImageWithTypeDisplayed($type)
/**
* {@inheritdoc}
*/
public function isSlugReadOnly($languageCode = 'en_US')
public function isSlugReadonly($languageCode = 'en_US')
{
return 'readonly' === $this->getElement('slug', ['%language%' => $languageCode])->getAttribute('readonly');
return SlugGenerationHelper::isSlugReadonly(
$this->getSession(),
$this->getElement('slug', ['%language%' => $languageCode])
);
}

/**
Expand All @@ -126,7 +135,10 @@ public function removeFirstImage()
*/
public function enableSlugModification($languageCode = 'en_US')
{
$this->getElement('toggle_taxon_slug_modification_button', ['%locale%' => $languageCode])->press();
SlugGenerationHelper::enableSlugModification(
$this->getSession(),
$this->getElement('toggle_taxon_slug_modification_button', ['%locale%' => $languageCode])
);
}

/**
Expand Down Expand Up @@ -313,24 +325,4 @@ private function getImageElementByType($type)

return $typeInput->getParent()->getParent()->getParent();
}

/**
* @param string $languageCode
*/
private function waitForSlugGenerationIfNecessary($languageCode = 'en_US')
{
if (!$this->getDriver() instanceof Selenium2Driver) {
return;
}

$slugElement = $this->getElement('slug', ['%language%' => $languageCode]);
if ($slugElement->hasAttribute('readonly')) {
return;
}

$value = $slugElement->getValue();
$this->getDocument()->waitFor(10, function () use ($slugElement, $value) {
return $value !== $slugElement->getValue();
});
}
}
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Page/Admin/Taxon/UpdatePageInterface.php
Expand Up @@ -66,7 +66,7 @@ public function isImageWithTypeDisplayed($type);
*
* @return bool
*/
public function isSlugReadOnly($languageCode = 'en_US');
public function isSlugReadonly($languageCode = 'en_US');

/**
* @param string $type
Expand Down

0 comments on commit 3a997f3

Please sign in to comment.