Skip to content

Commit

Permalink
[Behat] Add tests for filtering and sorting customer groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafikooo authored and GSadee committed Jul 9, 2024
1 parent aa52703 commit 9fad890
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@managing_customer_groups
Feature: Filtering customer groups
In order to see specific customer groups in the store
As an Administrator
I want to filter customer groups

Background:
Given the store has a customer group "Online sale" with "sale" code
And the store has a customer group "Retail" with "retail" code
And the store has a customer group "Wholesale" with "whole" code
And I am logged in as an administrator

@api-todo @ui
Scenario: Filtering customer groups
When I browse customer groups
And I search for them by "sale"
Then there should be 2 customer groups in the list
And the 1st customer group on the list should have code "sale" and name "Online sale"
And the 2nd customer group on the list should have code "whole" and name "Wholesale"
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
@managing_customer_groups
Feature: Sorting customer groups
In order to see all customer groups in the store sorted in a specific way
As an Administrator
I want to sort customer groups

Background:
Given the store has a customer group "Wholesale" with "aaa" code
And the store has a customer group "Retail" with "bbb" code
And the store has a customer group "Online sale" with "ccc" code
And I am logged in as an administrator

@api-todo @ui
Scenario: Sorting customer groups by name in ascending order
When I browse customer groups
And I sort them by the name in ascending order
Then there should be 3 customer groups in the list
And the 1st customer group on the list should have code "ccc" and name "Online sale"
And the 2nd customer group on the list should have code "bbb" and name "Retail"
And the 3rd customer group on the list should have code "aaa" and name "Wholesale"

@api-todo @ui
Scenario: Sorting customer groups by name in descending order
When I browse customer groups
And I sort them by the name in descending order
Then there should be 3 customer groups in the list
And the 1st customer group on the list should have code "aaa" and name "Wholesale"
And the 2nd customer group on the list should have code "bbb" and name "Retail"
And the 3rd customer group on the list should have code "ccc" and name "Online sale"

@api-todo @ui
Scenario: Sorting customer groups by code in ascending order
When I browse customer groups
And I sort them by the code in ascending order
Then there should be 3 customer groups in the list
And the 1st customer group on the list should have code "aaa" and name "Wholesale"
And the 2nd customer group on the list should have code "bbb" and name "Retail"
And the 3rd customer group on the list should have code "ccc" and name "Online sale"

@api-todo @ui
Scenario: Sorting customer groups by code in descending order
When I browse customer groups
And I sort them by the code in descending order
Then there should be 3 customer groups in the list
And the 1st customer group on the list should have code "ccc" and name "Online sale"
And the 2nd customer group on the list should have code "bbb" and name "Retail"
And the 3rd customer group on the list should have code "aaa" and name "Wholesale"
65 changes: 51 additions & 14 deletions src/Sylius/Behat/Context/Ui/Admin/ManagingCustomerGroupsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,6 @@ public function iAddIt(): void
$this->createPage->create();
}

/**
* @Then the customer group :customerGroup should appear in the store
*/
public function theCustomerGroupShouldAppearInTheStore(CustomerGroupInterface $customerGroup): void
{
$this->indexPage->open();

Assert::true($this->indexPage->isSingleResourceOnPage(['name' => $customerGroup->getName()]));
}

/**
* @When /^I want to edit (this customer group)$/
*/
Expand Down Expand Up @@ -113,6 +103,33 @@ public function iDeleteThem(): void
$this->indexPage->bulkDelete();
}

/**
* @When I browse customer groups
* @When I want to browse customer groups
*/
public function iWantToBrowseCustomerGroups(): void
{
$this->indexPage->open();
}

/**
* @When /^I sort them by the (code|name) in (asc|desc)ending order$/
*/
public function iSortThemByTheField(string $field, string $order): void
{
$this->indexPage->sortBy($field, $order);
}

/**
* @Then the customer group :customerGroup should appear in the store
*/
public function theCustomerGroupShouldAppearInTheStore(CustomerGroupInterface $customerGroup): void
{
$this->indexPage->open();

Assert::true($this->indexPage->isSingleResourceOnPage(['name' => $customerGroup->getName()]));
}

/**
* @Then this customer group with name :name should appear in the store
* @Then I should see the customer group :name in the list
Expand All @@ -125,17 +142,18 @@ public function thisCustomerGroupWithNameShouldAppearInTheStore(string $name): v
}

/**
* @When I browse customer groups
* @When I want to browse customer groups
* @Then there should be :amountOfCustomerGroups customer groups in the list
*/
public function iWantToBrowseCustomerGroups(): void
public function thereShouldBeCustomerGroupsInTheList(int $amountOfCustomerGroups = 1): void
{
$this->indexPage->open();
Assert::same($this->indexPage->countItems(), $amountOfCustomerGroups);
}

/**
* @Then I should see a single customer group in the list
* @Then I should see :amountOfCustomerGroups customer groups in the list
*
* This step is a duplicate of the above because some scenarios require to open the index page before checking anything
*/
public function iShouldSeeCustomerGroupsInTheList(int $amountOfCustomerGroups = 1): void
{
Expand All @@ -144,6 +162,25 @@ public function iShouldSeeCustomerGroupsInTheList(int $amountOfCustomerGroups =
Assert::same($this->indexPage->countItems(), $amountOfCustomerGroups);
}

/**
* @Then /^the (\d+)(?:|st|nd|rd|th) customer group on the list should have (name|code) "([^"]+)" and (name|code) "([^"]+)"$/
*/
public function theFirstCustomerGroupOnTheListShouldHave(
int $position,
string $firstField,
string $firstValue,
string $secondField,
string $secondValue,
): void {
$fields = $this->indexPage->getColumnFields($firstField);

Assert::same($fields[$position - 1], $firstValue);

$fields = $this->indexPage->getColumnFields($secondField);

Assert::same($fields[$position - 1], $secondValue);
}

/**
* @Then /^(this customer group) should still be named "([^"]+)"$/
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Context/Ui/Admin/SearchFilterContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Behat\Behat\Context\Context;
use Sylius\Behat\Element\Admin\Crud\Index\SearchFilterElementInterface;

final class SearchFilterContext implements Context
final readonly class SearchFilterContext implements Context
{
public function __construct(
private SearchFilterElementInterface $searchFilterElement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ default:

- sylius.behat.context.ui.admin.managing_customer_groups
- sylius.behat.context.ui.admin.notification
- sylius.behat.context.ui.admin.search_filter

filters:
tags: "@managing_customer_groups&&@ui"

0 comments on commit 9fad890

Please sign in to comment.