From bb20141f481da36cce04360cba18b017b859374c Mon Sep 17 00:00:00 2001 From: Jan Goralski Date: Fri, 14 Jun 2024 09:49:29 +0200 Subject: [PATCH] [Behat][Admin] Update tests of product searching from dashboard --- ...cts_via_the_dashboard_search_field.feature | 13 +++++++++--- .../Context/Ui/Admin/DashboardContext.php | 14 ++++++++++--- src/Sylius/Behat/Page/Admin/DashboardPage.php | 21 ++++++++++++++----- .../Page/Admin/DashboardPageInterface.php | 4 +++- .../crud/common/navbar/menu/search.html.twig | 4 ++-- .../crud/common/sidebar/search.html.twig | 4 ++-- 6 files changed, 44 insertions(+), 16 deletions(-) diff --git a/features/admin/searching_products_via_the_dashboard_search_field.feature b/features/admin/searching_products_via_the_dashboard_search_field.feature index 40232fca987..8d22da34c2c 100644 --- a/features/admin/searching_products_via_the_dashboard_search_field.feature +++ b/features/admin/searching_products_via_the_dashboard_search_field.feature @@ -1,8 +1,8 @@ @admin_dashboard -Feature: Searching products via the dashboard search field +Feature: Searching products via the search field In order to search for products easily As an Administrator - I want to be able to search for products via the dashboard search field + I want to be able to search for products from any admin page Background: Given the store operates on a channel named "WEB-POLAND" @@ -12,6 +12,13 @@ Feature: Searching products via the dashboard search field @ui @no-api Scenario: Searching for a product via the dashboard search field When I open administration dashboard - And I search for product "Onion" + And I search for product "Onion" via the navbar + Then I should see a single product in the list + And I should see a product with name "Onion" + + @ui @no-api + Scenario: Searching for a product via the menu search field + When I open administration dashboard + And I search for product "Onion" via the menu Then I should see a single product in the list And I should see a product with name "Onion" diff --git a/src/Sylius/Behat/Context/Ui/Admin/DashboardContext.php b/src/Sylius/Behat/Context/Ui/Admin/DashboardContext.php index d7b929bb0a7..94119ca03ca 100644 --- a/src/Sylius/Behat/Context/Ui/Admin/DashboardContext.php +++ b/src/Sylius/Behat/Context/Ui/Admin/DashboardContext.php @@ -83,11 +83,19 @@ public function iChooseChannel(string $channelName): void } /** - * @When I search for product :product + * @When I search for product :product via the navbar */ - public function iSearchForProduct(ProductInterface $product): void + public function iSearchForProductVuaNavbar(ProductInterface $product): void { - $this->dashboardPage->searchForProduct($product); + $this->dashboardPage->searchForProductViaNavbar($product); + } + + /** + * @When I search for product :product via the menu + */ + public function iSearchForProductViaMenu(ProductInterface $product): void + { + $this->dashboardPage->searchForProductViaSidebar($product); } /** diff --git a/src/Sylius/Behat/Page/Admin/DashboardPage.php b/src/Sylius/Behat/Page/Admin/DashboardPage.php index b0a3014bcc3..e18bb9cbbcf 100644 --- a/src/Sylius/Behat/Page/Admin/DashboardPage.php +++ b/src/Sylius/Behat/Page/Admin/DashboardPage.php @@ -125,10 +125,14 @@ public function chooseNextPeriod(): void usleep(500000); } - public function searchForProduct(ProductInterface $productName): void + public function searchForProductViaNavbar(ProductInterface $productName): void { - $this->getElement('product_search')->setValue($productName->getName()); - $this->getElement('search_button')->click(); + $this->searchForProductIn($productName->getName(), 'product_navbar_search'); + } + + public function searchForProductViaSidebar(ProductInterface $productName): void + { + $this->searchForProductIn($productName->getName(), 'product_sidebar_search'); } public function getRouteName(): string @@ -152,11 +156,18 @@ protected function getDefinedElements(): array 'new_customers' => '#new-customers', 'new_orders' => '#new-orders', 'order_list' => '#orders', - 'product_search' => '[data-test-product-search]', - 'search_button' => '[data-test-search-button]', + 'product_navbar_search' => '[data-test-navbar-product-search]', + 'product_sidebar_search' => '[data-test-sidebar-product-search]', 'sub_header' => '.ui.header .content .sub.header', 'total_sales' => '#total-sales', 'year_split_by_months_statistics_button' => 'button[data-stats-button="year"]', ]); } + + private function searchForProductIn(string $productName, string $searchForm): void + { + $form = $this->getElement($searchForm); + $form->find('css', 'input')->setValue($productName); + $form->find('css', 'button')->click(); + } } diff --git a/src/Sylius/Behat/Page/Admin/DashboardPageInterface.php b/src/Sylius/Behat/Page/Admin/DashboardPageInterface.php index 195dd6a4828..b7592bf3d98 100644 --- a/src/Sylius/Behat/Page/Admin/DashboardPageInterface.php +++ b/src/Sylius/Behat/Page/Admin/DashboardPageInterface.php @@ -46,5 +46,7 @@ public function choosePreviousPeriod(): void; public function chooseNextPeriod(): void; - public function searchForProduct(ProductInterface $productName): void; + public function searchForProductViaNavbar(ProductInterface $productName): void; + + public function searchForProductViaSidebar(ProductInterface $productName): void; } diff --git a/src/Sylius/Bundle/AdminBundle/templates/shared/crud/common/navbar/menu/search.html.twig b/src/Sylius/Bundle/AdminBundle/templates/shared/crud/common/navbar/menu/search.html.twig index 5a88c2c0251..5ed04c10070 100644 --- a/src/Sylius/Bundle/AdminBundle/templates/shared/crud/common/navbar/menu/search.html.twig +++ b/src/Sylius/Bundle/AdminBundle/templates/shared/crud/common/navbar/menu/search.html.twig @@ -1,8 +1,8 @@ {% from '@SyliusAdmin/shared/helper/icon.html.twig' import icon %} -
+
- + diff --git a/src/Sylius/Bundle/AdminBundle/templates/shared/crud/common/sidebar/search.html.twig b/src/Sylius/Bundle/AdminBundle/templates/shared/crud/common/sidebar/search.html.twig index 9d1e98ef499..b007e132bc3 100644 --- a/src/Sylius/Bundle/AdminBundle/templates/shared/crud/common/sidebar/search.html.twig +++ b/src/Sylius/Bundle/AdminBundle/templates/shared/crud/common/sidebar/search.html.twig @@ -1,8 +1,8 @@ {% from '@SyliusAdmin/shared/helper/icon.html.twig' import icon %} - +
- +