Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMilek committed Jun 13, 2024
1 parent d80e370 commit 73df6bd
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@admin_dashboard
Feature: Searching products via the dashboard 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

Background:
Given the store operates on a channel named "WEB-POLAND"
And there is product "Onion" available in this channel
And the store ships everywhere for Free
And the store allows paying Offline
And I am logged in as an administrator

@ui @no-api
Scenario: Searching for a product via the dashboard search field
When I open administration dashboard
And I search for product "Onion"
Then I should see a single product in the list
And I should see a product with name "Onion"
9 changes: 9 additions & 0 deletions src/Sylius/Behat/Context/Ui/Admin/DashboardContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use FriendsOfBehat\PageObjectExtension\Page\UnexpectedPageException;
use Sylius\Behat\Page\Admin\DashboardPageInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Webmozart\Assert\Assert;

final class DashboardContext implements Context
Expand Down Expand Up @@ -81,6 +82,14 @@ public function iChooseChannel(string $channelName): void
$this->dashboardPage->chooseChannel($channelName);
}

/**
* @When I search for product :product
*/
public function iSearchForProduct(ProductInterface $product): void
{
$this->dashboardPage->searchForProduct($product);
}

/**
* @When I log out
*/
Expand Down
9 changes: 9 additions & 0 deletions src/Sylius/Behat/Page/Admin/DashboardPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Behat\Mink\Session;
use FriendsOfBehat\PageObjectExtension\Page\SymfonyPage;
use Sylius\Behat\Service\Accessor\TableAccessorInterface;
use Sylius\Component\Core\Model\ProductInterface;
use Symfony\Component\Routing\RouterInterface;

class DashboardPage extends SymfonyPage implements DashboardPageInterface
Expand Down Expand Up @@ -124,6 +125,12 @@ public function chooseNextPeriod(): void
usleep(500000);
}

public function searchForProduct(ProductInterface $productName): void
{
$this->getElement('product_search')->setValue($productName->getName());
$this->getElement('search_button')->click();
}

public function getRouteName(): string
{
return 'sylius_admin_dashboard';
Expand All @@ -145,6 +152,8 @@ 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]',
'sub_header' => '.ui.header .content .sub.header',
'total_sales' => '#total-sales',
'year_split_by_months_statistics_button' => 'button[data-stats-button="year"]',
Expand Down
3 changes: 3 additions & 0 deletions src/Sylius/Behat/Page/Admin/DashboardPageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Sylius\Behat\Page\Admin;

use FriendsOfBehat\PageObjectExtension\Page\SymfonyPageInterface;
use Sylius\Component\Core\Model\ProductInterface;

interface DashboardPageInterface extends SymfonyPageInterface
{
Expand Down Expand Up @@ -44,4 +45,6 @@ public function chooseMonthSplitByDaysInterval(): void;
public function choosePreviousPeriod(): void;

public function chooseNextPeriod(): void;

public function searchForProduct(ProductInterface $productName): void;
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ default:

- sylius.behat.context.ui.admin.dashboard
- sylius.behat.context.ui.admin.login
- sylius.behat.context.ui.admin.managing_products
- sylius.behat.context.ui.admin.notification
- sylius.behat.context.ui.browser

Expand Down

0 comments on commit 73df6bd

Please sign in to comment.