Skip to content

Commit

Permalink
Make filtering out scenario available in both ui and api contexts
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubtobiasz committed Jul 18, 2022
1 parent 55edb2d commit 673eb91
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 22 deletions.
11 changes: 7 additions & 4 deletions features/channel/filtering_out_disabled_channels.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ Feature: Filtering out disabled channels
Background:
Given the store operates on a channel named "Fashion" in "USD" currency and with hostname "127.0.0.1"
And the store operates on a channel named "Furniture" in "EUR" currency and with hostname "127.0.0.1"
And there is product "Black T-Shirt" available in "Fashion" channel
And there is product "Old Wardrobe" available in "Furniture" channel
And the channel "Fashion" is disabled

@ui
Scenario: Seeing Furniture shop homepage
When I visit the homepage
Then I should see "Furniture" shop
@ui @api
Scenario: Seeing Furniture shop products
When I check latest products
Then I should see "Old Wardrobe" product
And I should not see "Black T-Shirt" product
28 changes: 28 additions & 0 deletions src/Sylius/Behat/Context/Api/Shop/HomepageContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,34 @@ public function iCheckLatestProducts(): void
);
}

/**
* @Then I should see :productName product
*/
public function iShouldSeeProduct(string $productName): void
{
Assert::true(
$this->responseChecker->hasItemWithValue(
$this->productsClient->getLastResponse(),
'name',
$productName
)
);
}

/**
* @Then I should not see :productName product
*/
public function iShouldNotSeeProduct(string $productName): void
{
Assert::false(
$this->responseChecker->hasItemWithValue(
$this->productsClient->getLastResponse(),
'name',
$productName
)
);
}

/**
* @When I check available taxons
*/
Expand Down
8 changes: 0 additions & 8 deletions src/Sylius/Behat/Context/Ui/ChannelContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,4 @@ public function shouldSeePluginMainPageWithContent(string $content): void
{
Assert::same($this->pluginMainPage->getContent(), $content);
}

/**
* @Then I should see :channel shop
*/
public function iShouldSeeShop(ChannelInterface $channel): void
{
Assert::eq($this->homePage->getMetaTitle(), $channel->getName());
}
}
17 changes: 16 additions & 1 deletion src/Sylius/Behat/Context/Ui/Shop/HomepageContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public function __construct(
/**
* @When I check latest products
* @When I check available taxons
* @When I visit the homepage
*/
public function iCheckLatestProducts(): void
{
Expand All @@ -52,6 +51,22 @@ public function iShouldSeeProductsInTheList(int $numberOfProducts): void
Assert::same(count($this->homePage->getLatestProductsNames()), $numberOfProducts);
}

/**
* @Then I should see :productName product
*/
public function iShouldSeeProduct(string $productName): void
{
Assert::inArray($productName, $this->homePage->getLatestProductsNames());
}

/**
* @Then I should not see :productName product
*/
public function iShouldNotSeeProduct(string $productName): void
{
Assert::true(!in_array($productName, $this->homePage->getLatestProductsNames()));
}

/**
* @Then I should see :firstMenuItem in the menu
* @Then I should see :firstMenuItem and :secondMenuItem in the menu
Expand Down
6 changes: 0 additions & 6 deletions src/Sylius/Behat/Page/Shop/HomePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ public function getLatestProductsNames(): array
);
}

public function getMetaTitle(): string
{
return $this->getElement('meta_title')->getText();
}

protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
Expand All @@ -110,7 +105,6 @@ protected function getDefinedElements(): array
'latest_products' => '[data-test-latest-products]',
'locale_selector' => '[data-test-locale-selector]',
'logout_button' => '[data-test-logout-button]',
'meta_title' => 'title',
]);
}
}
2 changes: 0 additions & 2 deletions src/Sylius/Behat/Page/Shop/HomePageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,4 @@ public function getAvailableLocales(): array;
public function switchLocale(string $localeCode): void;

public function getLatestProductsNames(): array;

public function getMetaTitle(): string;
}
19 changes: 19 additions & 0 deletions src/Sylius/Behat/Resources/config/suites/api/channel/channels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file is part of the Sylius package.
# (c) Paweł Jędrzejewski

default:
suites:
ui_channels:
contexts:
- sylius.behat.context.hook.doctrine_orm

- sylius.behat.context.transform.channel

- sylius.behat.context.setup.channel
- sylius.behat.context.setup.product

- sylius.behat.context.api.channel
- sylius.behat.context.api.shop.homepage

filters:
tags: "@channels&&@api"
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ default:
- sylius.behat.context.transform.channel

- sylius.behat.context.setup.channel
- sylius.behat.context.setup.product

- sylius.behat.context.ui.channel

- sylius.behat.context.ui.shop.homepage

filters:
tags: "@channels&&@ui"

0 comments on commit 673eb91

Please sign in to comment.