Skip to content

Commit

Permalink
[Behat][Admin] Update tests of product searching from dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
NoResponseMate committed Jun 14, 2024
1 parent d8aa308 commit bb20141
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"
14 changes: 11 additions & 3 deletions src/Sylius/Behat/Context/Ui/Admin/DashboardContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
21 changes: 16 additions & 5 deletions src/Sylius/Behat/Page/Admin/DashboardPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();
}
}
4 changes: 3 additions & 1 deletion src/Sylius/Behat/Page/Admin/DashboardPageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% from '@SyliusAdmin/shared/helper/icon.html.twig' import icon %}

<form action="{{ path('sylius_admin_product_index') }}" method="get">
<form action="{{ path('sylius_admin_product_index') }}" method="get" {{ sylius_test_html_attribute('navbar-product-search') }}>
<div class="input-group">
<input type="text" name="criteria[search][value]" placeholder="{{ 'sylius.ui.search_products'|trans }}..." class="form-control" {{ sylius_test_html_attribute('product-search') }}>
<input type="text" name="criteria[search][value]" placeholder="{{ 'sylius.ui.search_products'|trans }}..." class="form-control">
<button type="submit" class="btn" {{ sylius_test_html_attribute('search-button') }}>
{{ icon({icon: 'search', class: 'icon icon-tabler mx-1'}) }}
</button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% from '@SyliusAdmin/shared/helper/icon.html.twig' import icon %}

<form action="{{ path('sylius_admin_product_index') }}" method="get" class="mb-3 mt-3 mt-md-0">
<form action="{{ path('sylius_admin_product_index') }}" method="get" class="mb-3 mt-3 mt-md-0" {{ sylius_test_html_attribute('sidebar-product-search') }}>
<div class="input-group">
<input type="text" name="criteria[search][value]" placeholder="{{ 'sylius.ui.search_products'|trans }}..." class="form-control" {{ sylius_test_html_attribute('product-search') }}>
<input type="text" name="criteria[search][value]" placeholder="{{ 'sylius.ui.search_products'|trans }}..." class="form-control">
<button type="submit" class="btn" {{ sylius_test_html_attribute('search-button') }}>
{{ icon({icon: 'search', class: 'icon icon-tabler mx-0'}) }}
</button>
Expand Down

0 comments on commit bb20141

Please sign in to comment.