diff --git a/features/promotion/managing_promotions/filtering_promotions_by_coupon_code.feature b/features/promotion/managing_promotions/filtering_promotions_by_coupon_code.feature new file mode 100644 index 0000000000..e7c3c5d469 --- /dev/null +++ b/features/promotion/managing_promotions/filtering_promotions_by_coupon_code.feature @@ -0,0 +1,19 @@ +@managing_promotions +Feature: Filtering promotions by coupon code + In order to filter promotions by coupon code + As an Administrator + I want to filter the promotions on the list + + Background: + Given the store operates on a single channel in "United States" + And there is a promotion "Basic promotion" + And the store has promotion "Holiday sale" with coupon "HOLIDAY" + And the store has promotion "Christmas sale" with coupon "MAGIC" + And I am logged in as an administrator + + @ui + Scenario: Filtering promotions by coupon code + When I want to browse promotions + And I filter promotions by coupon code equal "MAGIC" + And I should see a single promotion in the list + And I should see the promotion "Christmas sale" in the list diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php index ac18a967a5..fa26f2a714 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingPromotionsContext.php @@ -272,7 +272,7 @@ final class ManagingPromotionsContext implements Context */ public function thereShouldBePromotion(int $amount = 1): void { - Assert::same($amount, $this->indexPage->countItems()); + Assert::same($this->indexPage->countItems(), $amount); } /** @@ -671,6 +671,17 @@ final class ManagingPromotionsContext implements Context Assert::false($this->updatePage->hasAnyRule()); } + /** + * @When /^I filter promotions by coupon code equal "([^"]+)"/ + */ + public function iFilterPromotionsByCouponCodeEqual(string $value): void + { + $this->indexPage->specifyFilterType('coupon_code', 'equal'); + $this->indexPage->specifyFilterValue('coupon_code', $value); + + $this->indexPage->filter(); + } + /** * @param string $element * @param string $expectedMessage diff --git a/src/Sylius/Behat/Page/Admin/Promotion/IndexPage.php b/src/Sylius/Behat/Page/Admin/Promotion/IndexPage.php index 229044cd03..38121d7e10 100644 --- a/src/Sylius/Behat/Page/Admin/Promotion/IndexPage.php +++ b/src/Sylius/Behat/Page/Admin/Promotion/IndexPage.php @@ -40,6 +40,16 @@ class IndexPage extends BaseIndexPage implements IndexPageInterface return 'Yes' === $coupons->getText(); } + public function specifyFilterType(string $field, string $type): void + { + $this->getDocument()->fillField(sprintf('criteria_%s_type', $field), $type); + } + + public function specifyFilterValue(string $field, string $value): void + { + $this->getDocument()->fillField(sprintf('criteria_%s_value', $field), $value); + } + private function getPromotionFieldsWithHeader(PromotionInterface $promotion, string $header): NodeElement { $tableAccessor = $this->getTableAccessor(); diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/promotion.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/promotion.yml index c498a06b33..0e9782964e 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/promotion.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/promotion.yml @@ -46,6 +46,11 @@ sylius_grid: couponBased: type: boolean label: sylius.ui.coupon_based + coupon_code: + type: string + label: sylius.ui.coupon + options: + fields: [coupons.code] actions: main: create: