Skip to content

Commit

Permalink
Merge branch '1.11'
Browse files Browse the repository at this point in the history
* 1.11:
  Bugfix: display full cart promotion rule form when adding a new rule
  • Loading branch information
lchrusciel committed Jan 21, 2022
2 parents eac2d29 + 923ea63 commit 0584e29
Show file tree
Hide file tree
Showing 9 changed files with 135 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,11 @@ Feature: Creating a catalog promotion
Then there should be 1 new catalog promotion on the list
And it should have "winter_sale" code and "Winter sale" name
And it should have priority equal to 10

@ui @javascript
Scenario: Adding a new catalog promotion of default type with one action
When I want to create a new catalog promotion
And I add a new catalog promotion scope
And I add a new catalog promotion action
Then I should see the catalog promotion scope configuration form
And I should see the catalog promotion action configuration form
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,11 @@ Feature: Adding a new promotion with rule
And I add it
Then I should be notified that it has been successfully created
And the "Wholesale promotion" promotion should appear in the registry

@ui @javascript
Scenario: Adding a new promotion of default type with one action
When I want to create a new promotion
And I add a new rule
And I add a new action
Then I should see the rule configuration form
And I should see the action configuration form
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ public function iChangeItsEndDateTo(string $endDate): void
$this->formElement->specifyEndDate(new \DateTime($endDate));
}

/**
* @When I add a new catalog promotion scope
*/
public function iAddANewCatalogPromotionScope(): void
{
$this->formElement->addScope();
}

/**
* @When /^I add(?:| another) scope that applies on ("[^"]+" variant)$/
* @When /^I add scope that applies on ("[^"]+" variant) and ("[^"]+" variant)$/
Expand Down Expand Up @@ -265,6 +273,14 @@ public function iRemoveItsEveryAction(): void
$this->formElement->removeAllActions();
}

/**
* @When I add a new catalog promotion action
*/
public function iAddANewCatalogPromotionAction(): void
{
$this->formElement->addAction();
}

/**
* @When I add another action that gives ":discount%" percentage discount
* @When I add action that gives ":discount%" percentage discount
Expand Down Expand Up @@ -1035,4 +1051,20 @@ public function itsPriorityShouldBe(int $priority): void
{
Assert::same($this->showPage->getPriority(), $priority);
}

/**
* @Then I should see the catalog promotion scope configuration form
*/
public function iShouldSeeTheCatalogPromotionScopeConfigurationForm(): void
{
Assert::true($this->createPage->checkIfScopeConfigurationFormIsVisible(), 'Catalog promotion scope configuration form is not visible.');
}

/**
* @Then I should see the catalog promotion action configuration form
*/
public function iShouldSeeTheCatalogPromotionActionConfigurationForm(): void
{
Assert::true($this->createPage->checkIfActionConfigurationFormIsVisible(), 'Catalog promotion action configuration form is not visible.');
}
}
32 changes: 32 additions & 0 deletions src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,38 @@ public function iFilterPromotionsByCouponCodeEqual(string $value): void
$this->indexPage->filter();
}

/**
* @When I add a new rule
*/
public function iAddANewRule()
{
$this->createPage->addRule(null);
}

/**
* @When I add a new action
*/
public function iAddANewAction()
{
$this->createPage->addAction(null);
}

/**
* @Then I should see the rule configuration form
*/
public function iShouldSeeTheRuleConfigurationForm()
{
Assert::true($this->createPage->checkIfRuleConfigurationFormIsVisible(), 'Cart promotion rule configuration form is not visible.');
}

/**
* @Then I should see the action configuration form
*/
public function iShouldSeeTheActionConfigurationForm()
{
Assert::true($this->createPage->checkIfActionConfigurationFormIsVisible(), 'Cart promotion action configuration form is not visible.');
}

/**
* @param string $element
* @param string $expectedMessage
Expand Down
12 changes: 12 additions & 0 deletions src/Sylius/Behat/Page/Admin/CatalogPromotion/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,24 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
{
use SpecifiesItsCode;

public function checkIfScopeConfigurationFormIsVisible(): bool
{
return $this->hasElement('products');
}

public function checkIfActionConfigurationFormIsVisible(): bool
{
return $this->hasElement('amount');
}

protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
'code' => '#sylius_catalog_promotion_code',
'endDate' => '#sylius_catalog_promotion_endDate',
'name' => '#sylius_catalog_promotion_name',
'products' => '[name="sylius_catalog_promotion[scopes][0][configuration][products]"]',
'amount' => '[name="sylius_catalog_promotion[actions][0][configuration][amount]"]',
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@

interface CreatePageInterface extends BaseCreatePageInterface
{
public function checkIfScopeConfigurationFormIsVisible(): bool;

public function checkIfActionConfigurationFormIsVisible(): bool;

public function specifyCode(string $code): void;
}
24 changes: 20 additions & 4 deletions src/Sylius/Behat/Page/Admin/Promotion/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CreatePage extends BaseCreatePage implements CreatePageInterface
use NamesIt;
use SpecifiesItsCode;

public function addRule(string $ruleName): void
public function addRule(?string $ruleName): void
{
$count = count($this->getCollectionItems('rules'));

Expand All @@ -36,7 +36,9 @@ public function addRule(string $ruleName): void
return $count + 1 === count($this->getCollectionItems('rules'));
});

$this->selectRuleOption('Type', $ruleName);
if (null !== $ruleName) {
$this->selectRuleOption('Type', $ruleName);
}
}

public function selectRuleOption(string $option, string $value, bool $multiple = false): void
Expand Down Expand Up @@ -74,7 +76,7 @@ public function fillRuleOptionForChannel(string $channelName, string $option, st
$lastAction->fillField($option, $value);
}

public function addAction(string $actionName): void
public function addAction(?string $actionName): void
{
$count = count($this->getCollectionItems('actions'));

Expand All @@ -84,7 +86,9 @@ public function addAction(string $actionName): void
return $count + 1 === count($this->getCollectionItems('actions'));
});

$this->selectActionOption('Type', $actionName);
if (null !== $actionName) {
$this->selectActionOption('Type', $actionName);
}
}

public function selectActionOption(string $option, string $value, bool $multiple = false): void
Expand Down Expand Up @@ -175,6 +179,16 @@ public function selectAutoCompleteFilterOption(string $option, $value, bool $mul
AutocompleteHelper::chooseValue($this->getSession(), $filterAutocomplete, $value);
}

public function checkIfRuleConfigurationFormIsVisible(): bool
{
return $this->hasElement('count');
}

public function checkIfActionConfigurationFormIsVisible(): bool
{
return $this->hasElement('amount');
}

protected function getDefinedElements(): array
{
return [
Expand All @@ -186,6 +200,8 @@ protected function getDefinedElements(): array
'name' => '#sylius_promotion_name',
'rules' => '#sylius_promotion_rules',
'starts_at' => '#sylius_promotion_startsAt',
'count' => '#sylius_promotion_rules_0_configuration_count',
'amount' => '#sylius_promotion_actions_0_configuration_WEB-US_amount',
];
}

Expand Down
8 changes: 6 additions & 2 deletions src/Sylius/Behat/Page/Admin/Promotion/CreatePageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function specifyCode(string $code): void;

public function nameIt(string $name): void;

public function addRule(string $ruleName): void;
public function addRule(?string $ruleName): void;

public function selectRuleOption(string $option, string $value, bool $multiple = false): void;

Expand All @@ -35,7 +35,7 @@ public function fillRuleOption(string $option, string $value): void;

public function fillRuleOptionForChannel(string $channelName, string $option, string $value): void;

public function addAction(string $actionName): void;
public function addAction(?string $actionName): void;

public function selectActionOption(string $option, string $value, bool $multiple = false): void;

Expand Down Expand Up @@ -66,4 +66,8 @@ public function getValidationMessageForAction(): string;
* @param string|string[] $value
*/
public function selectAutoCompleteFilterOption(string $option, $value, bool $multiple = false): void;

public function checkIfRuleConfigurationFormIsVisible(): bool;

public function checkIfActionConfigurationFormIsVisible(): bool;
}
18 changes: 13 additions & 5 deletions src/Sylius/Bundle/AdminBundle/Resources/private/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,24 @@ $(document).ready(() => {
containerSelector: '.configuration',
});

$('#actions a[data-form-collection="add"]').on('click', () => {
$('#sylius_promotion_actions > a[data-form-collection="add"]').on('click', () => {
setTimeout(() => {
$('select[name^="sylius_promotion[actions]"][name$="[type]"]').last().change();
}, 50);
});
$('#scopes a[data-form-collection="add"]').on('click', (event) => {
const name = $(event.target).closest('form').attr('name');

$('#sylius_promotion_rules > a[data-form-collection="add"]').on('click', () => {
setTimeout(() => {
$(`select[name^="sylius_promotion[rules]"][name$="[type]"]`).last().change();
}, 50);
});
$('#sylius_catalog_promotion_actions > a[data-form-collection="add"]').on('click', () => {
setTimeout(() => {
$('select[name^="sylius_catalog_promotion[actions]"][name$="[type]"]').last().change();
}, 50);
});
$('#sylius_catalog_promotion_scopes > a[data-form-collection="add"]').on('click', () => {
setTimeout(() => {
$(`select[name^="${name}[scopes]"][name$="[type]"]`).last().change();
$(`select[name^="sylius_catalog_promotion[scopes]"][name$="[type]"]`).last().change();
}, 50);
});

Expand Down

0 comments on commit 0584e29

Please sign in to comment.