From 7eca0967189ea9cd57d2b8f86e50e7e9d9dc3613 Mon Sep 17 00:00:00 2001 From: Jan Goralski Date: Fri, 5 Jul 2024 11:27:00 +0200 Subject: [PATCH] [Admin][PaymentMethod] Upgrade index [Admin][Behat][PaymentMethod] Fix sorting and cover filtration --- .../filtering_payment_methods.feature | 33 +++++++++++++++++++ .../sorting_payment_methods.feature | 6 ++-- .../Behat/Context/Setup/PaymentContext.php | 2 +- .../Admin/ManagingPaymentMethodsContext.php | 20 +++++++++-- .../ui/payment/managing_payment_methods.yml | 1 + .../Resources/config/grids/payment_method.yml | 2 ++ .../title_block/actions/cancel.html.twig | 4 +-- 7 files changed, 59 insertions(+), 9 deletions(-) create mode 100644 features/admin/payment/managing_payment_methods/filtering_payment_methods.feature diff --git a/features/admin/payment/managing_payment_methods/filtering_payment_methods.feature b/features/admin/payment/managing_payment_methods/filtering_payment_methods.feature new file mode 100644 index 0000000000..399c996718 --- /dev/null +++ b/features/admin/payment/managing_payment_methods/filtering_payment_methods.feature @@ -0,0 +1,33 @@ +@managing_payment_methods +Feature: Filtering payment methods + In order to quickly find the payment method I need + As an Administrator + I want to filter available payment methods + + Background: + Given the store operates on a single channel in "United States" + And the store has a payment method "PayPal Express Checkout" with a code "paypal_xyz" and "Paypal Express Checkout" gateway + And the store has a payment method "Offline" with a code "offline_abc" + And this payment method is disabled + And the store has a payment method "Cash on Delivery" with a code "cash_on_delivery_xyz" + And I am logged in as an administrator + And I am browsing payment methods + + @todo-api @ui + Scenario: Filtering payment methods by name + When I search by "PayPal" name + Then I should see a single payment method in the list + And I should see the payment method "PayPal Express Checkout" + + @todo-api @ui + Scenario: Filtering payment methods by code + When I search by "xyz" code + Then I should see 2 payment methods in the list + And I should not see the payment method "Offline" + + @todo-api @ui + Scenario: Filtering enabled payment methods + When I choose enabled filter + And I filter + Then I should see 2 payment methods in the list + And I should not see the payment method "Offline" diff --git a/features/admin/payment/managing_payment_methods/sorting_payment_methods.feature b/features/admin/payment/managing_payment_methods/sorting_payment_methods.feature index 0a56746426..8fa3a58adb 100644 --- a/features/admin/payment/managing_payment_methods/sorting_payment_methods.feature +++ b/features/admin/payment/managing_payment_methods/sorting_payment_methods.feature @@ -7,9 +7,9 @@ Feature: Sorting listed payment methods Background: Given the store operates on a single channel in "United States" And that channel allows to shop using "English (United States)" and "Polish (Poland)" locales - And the store has a payment method "PayPal Express Checkout" with a code "PAYPAL" and "Paypal Express Checkout" gateway + And the store has a payment method "PayPal Express Checkout" with a code "paypal" and "Paypal Express Checkout" gateway And this payment method is named "Ekspresowy Paypal" in the "Polish (Poland)" locale - And the store has a payment method "Offline" with a code "Offline" + And the store has a payment method "Offline" with a code "offline" And this payment method is named "Płatność Offline" in the "Polish (Poland)" locale And the store has a payment method "Cash on Delivery" with a code "cash_on_delivery" And this payment method is named "Płatność Przy Odbiorze" in the "Polish (Poland)" locale @@ -28,7 +28,7 @@ Feature: Sorting listed payment methods And the payment methods are already sorted by code When I switch the way payment methods are sorted to descending by code Then I should see 3 payment methods in the list - And the first payment method on the list should have code "PAYPAL" + And the first payment method on the list should have code "paypal" @api @ui Scenario: Payment methods can be sorted by their names diff --git a/src/Sylius/Behat/Context/Setup/PaymentContext.php b/src/Sylius/Behat/Context/Setup/PaymentContext.php index c072b2f1b9..9fa1a569e2 100644 --- a/src/Sylius/Behat/Context/Setup/PaymentContext.php +++ b/src/Sylius/Behat/Context/Setup/PaymentContext.php @@ -128,7 +128,7 @@ final readonly class PaymentContext implements Context /** * @Given the payment method :paymentMethod is disabled - * @Given /^(this payment method) has been disabled$/ + * @Given /^(this payment method) (?:has been|is) disabled$/ * @When the payment method :paymentMethod gets disabled */ public function theStoreHasAPaymentMethodDisabled(PaymentMethodInterface $paymentMethod) diff --git a/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentMethodsContext.php b/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentMethodsContext.php index d525ad5579..e794959388 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentMethodsContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/ManagingPaymentMethodsContext.php @@ -255,6 +255,22 @@ final readonly class ManagingPaymentMethodsContext implements Context $this->indexPage->bulkDelete(); } + /** + * @Then I should see the payment method :paymentMethodName + */ + public function IShouldSeeThePaymentMethod(string $paymentMethodName): void + { + Assert::true($this->indexPage->isSingleResourceOnPage(['name' => $paymentMethodName])); + } + + /** + * @Then I should not see the payment method :paymentMethodName + */ + public function IShouldNotSeeThePaymentMethod(string $paymentMethodName): void + { + Assert::false($this->indexPage->isSingleResourceOnPage(['name' => $paymentMethodName])); + } + /** * @Then the payment method :paymentMethodName should appear in the registry * @Then the payment method :paymentMethodName should be in the registry @@ -262,9 +278,7 @@ final readonly class ManagingPaymentMethodsContext implements Context */ public function thePaymentMethodShouldAppearInTheRegistry(string $paymentMethodName): void { - $this->indexPage->open(); - - Assert::true($this->indexPage->isSingleResourceOnPage(['name' => $paymentMethodName])); + $this->thereShouldStillBeOnlyOnePaymentMethodWith('name', $paymentMethodName); } /** diff --git a/src/Sylius/Behat/Resources/config/suites/ui/payment/managing_payment_methods.yml b/src/Sylius/Behat/Resources/config/suites/ui/payment/managing_payment_methods.yml index 71758d0e60..50fdba42d9 100644 --- a/src/Sylius/Behat/Resources/config/suites/ui/payment/managing_payment_methods.yml +++ b/src/Sylius/Behat/Resources/config/suites/ui/payment/managing_payment_methods.yml @@ -29,6 +29,7 @@ default: - sylius.behat.context.ui.admin.managing_payment_methods - sylius.behat.context.ui.admin.notification + - sylius.behat.context.ui.admin.search_filter - sylius.behat.context.ui.shop.locale filters: diff --git a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment_method.yml b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment_method.yml index 93f6185240..ce60f82f97 100644 --- a/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment_method.yml +++ b/src/Sylius/Bundle/AdminBundle/Resources/config/grids/payment_method.yml @@ -54,6 +54,8 @@ sylius_grid: label: sylius.ui.search options: fields: [code, translation.name] + form_options: + type: !php/const Sylius\Component\Grid\Filter\StringFilter::TYPE_CONTAINS enabled: type: boolean label: sylius.ui.enabled diff --git a/src/Sylius/Bundle/AdminBundle/templates/shared/crud/common/content/header/title_block/actions/cancel.html.twig b/src/Sylius/Bundle/AdminBundle/templates/shared/crud/common/content/header/title_block/actions/cancel.html.twig index 873e8f42f0..263f9617ee 100644 --- a/src/Sylius/Bundle/AdminBundle/templates/shared/crud/common/content/header/title_block/actions/cancel.html.twig +++ b/src/Sylius/Bundle/AdminBundle/templates/shared/crud/common/content/header/title_block/actions/cancel.html.twig @@ -2,9 +2,9 @@ {% set configuration = hookable_metadata.context.configuration %} -{% set index_url = path( +{% set index_url = sylius_generate_redirect_path(app.request.headers.get('referer')|default(path( configuration.vars.index.route.name|default(configuration.getRouteName('index')), configuration.vars.index.route.parameters|default(configuration.vars.route.parameters|default({})) -) %} +))) %} {{ _button.cancel(sylius_test_form_attribute('cancel-changes-button')|merge({ text: 'sylius.ui.cancel'|trans, url: index_url, class: 'btn' })) }}