Skip to content

Commit

Permalink
feature #13068 [CatalogPromotions][Api] Add test for creation rule (T…
Browse files Browse the repository at this point in the history
…omanhez)

This PR was merged into the 1.11-dev branch.

Discussion
----------

| Q               | A
| --------------- | -----
| Branch?         | master
| Bug fix?        | no
| New feature?    | yes
| BC breaks?      | no
| Deprecations?   | no
| License         | MIT

<!--
 - Bug fixes must be submitted against the 1.9 or 1.10 branch (the lowest possible)
 - Features and deprecations must be submitted against the master branch
 - Make sure that the correct base branch is set

 To be sure you are not breaking any Backward Compatibilities, check the documentation:
 https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html
-->


Commits
-------

73e22d3 Add test for creation rule
  • Loading branch information
GSadee committed Sep 10, 2021
2 parents 6835306 + 73e22d3 commit d227d64
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Feature: Validating a catalog promotion creation
Then I should be notified that rule configuration is invalid
And there should be an empty list of catalog promotions

@api
@api @ui @javascript
Scenario: Trying to create a catalog promotion with not configured for variants rule
When I want to create a new catalog promotion
And I specify its code as "winter_sale"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@
use Sylius\Behat\Page\Admin\CatalogPromotion\CreatePageInterface;
use Sylius\Behat\Page\Admin\CatalogPromotion\UpdatePageInterface;
use Sylius\Behat\Page\Admin\Crud\IndexPageInterface;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Core\Model\CatalogPromotionInterface;
use Sylius\Component\Core\Model\CatalogPromotionRuleInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Promotion\Model\CatalogPromotionActionInterface;
use Webmozart\Assert\Assert;

final class ManagingCatalogPromotionsContext implements Context
Expand All @@ -35,20 +32,16 @@ final class ManagingCatalogPromotionsContext implements Context

private FormElementInterface $formElement;

private SharedStorageInterface $sharedStorage;

public function __construct(
IndexPageInterface $indexPage,
CreatePageInterface $createPage,
UpdatePageInterface $updatePage,
FormElementInterface $formElement,
SharedStorageInterface $sharedStorage
FormElementInterface $formElement
) {
$this->indexPage = $indexPage;
$this->createPage = $createPage;
$this->updatePage = $updatePage;
$this->formElement = $formElement;
$this->sharedStorage = $sharedStorage;
}

/**
Expand Down Expand Up @@ -158,7 +151,7 @@ public function iAddActionThatGivesPercentageDiscount(string $discount): void
}

/**
* @When I add it
* @When I (try to) add it
*/
public function iAddIt(): void
{
Expand Down Expand Up @@ -214,6 +207,14 @@ public function iEditCatalogPromotionToHaveDiscount(CatalogPromotionInterface $c
$this->updatePage->saveChanges();
}

/**
* @When I add for variants rule without variants configured
*/
public function iAddForVariantsRuleWithoutVariantsConfigured(): void
{
$this->formElement->addRule();
}

/**
* @Then there should be :amount catalog promotions on the list
* @Then there should be :amount new catalog promotion on the list
Expand Down Expand Up @@ -401,4 +402,12 @@ public function iShouldNotBeAbleToEditItsCode(): void
{
Assert::true($this->updatePage->isCodeDisabled());
}

/**
* @Then I should be notified that at least 1 variant is required
*/
public function iShouldBeNotifiedThatAtLeast1VariantIsRequired(): void
{
Assert::same($this->formElement->getValidationMessageForAction(), 'Please add at least 1 variant.');
}
}
12 changes: 12 additions & 0 deletions src/Sylius/Behat/Element/Admin/CatalogPromotion/FormElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sylius\Behat\Element\Admin\CatalogPromotion;

use Behat\Mink\Element\NodeElement;
use Behat\Mink\Exception\ElementNotFoundException;
use FriendsOfBehat\PageObjectExtension\Element\Element;
use Webmozart\Assert\Assert;

Expand Down Expand Up @@ -87,6 +88,17 @@ public function getLastActionDiscount(): string
return $lastAction->find('css', 'input')->getValue();
}

public function getValidationMessageForAction(): string
{
$foundElement = $this->getDocument()->find('css', '.sylius-validation-error');

if (null === $foundElement) {
throw new ElementNotFoundException($this->getSession(), 'Tag', 'css', '.sylius-validation-error');
}

return $foundElement->getText();
}

protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ public function getFieldValueInLocale(string $field, string $localeCode): string
public function getLastRuleVariantCodes(): array;

public function getLastActionDiscount(): string;

public function getValidationMessageForAction(): string;
}
1 change: 0 additions & 1 deletion src/Sylius/Behat/Resources/config/services/contexts/ui.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
<argument type="service" id="sylius.behat.page.admin.catalog_promotion.create" />
<argument type="service" id="sylius.behat.page.admin.catalog_promotion.update" />
<argument type="service" id="Sylius\Behat\Element\Admin\CatalogPromotion\FormElement" />
<argument type="service" id="sylius.behat.shared_storage" />
</service>

<service id="sylius.behat.context.ui.admin.managing_channels" class="Sylius\Behat\Context\Ui\Admin\ManagingChannelsContext">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
{% form_theme form '@SyliusAdmin/CatalogPromotion/theme.html.twig' %}

<div class="ui two column stackable grid">
{{ form_errors(form) }}
<div class="column">
{{ form_errors(form) }}
<div class="ui segment">
{{ form_row(form.code) }}
{{ form_row(form.name) }}
Expand Down

0 comments on commit d227d64

Please sign in to comment.