Skip to content

Commit

Permalink
Add search tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lruozzi9 committed Apr 11, 2024
1 parent ee52f56 commit 7d3e3f0
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 71 deletions.
71 changes: 0 additions & 71 deletions features/product/search_products/search_products.feature

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@search_products
Feature: Search products by attributes
In order to find products that fits my needs
As a Visitor
I want to be able to search products from a keyword

Background:
Given the store operates on a channel named "US Channel" with hostname "127.0.0.1"
And that channel allows to shop using "English (United States)" and "Italian (Italy)" locales
And it uses the "English (United States)" locale by default
And the store operates on another channel named "IT Channel" with hostname "shop.it"
And that channel allows to shop using "English (United States)" and "Italian (Italy)" locales
And it uses the "Italian (Italy)" locale by default

And the store has a product "T-Shirt Banana" with code "T_SHIRT_BANANA"
And this product is available in "US Channel" channel
And this product is also available in "IT Channel" channel

And the store has a product "T-Shirt Apple" available in "US Channel" channel
And this product is also available in "IT Channel" channel

And the store has a "T-Shirt Orange" configurable product
And this product has a "T-Shirt Orange - Medium size" variant with code "T_SHIRT_ORANGE_M"
And this product is available in "US Channel" channel
And this product is also available in "IT Channel" channel

And the store is indexed on Elasticsearch
And I am browsing the channel "US Channel"
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@search_products
Feature: Search products by options
In order to find products that fits my needs
As a Visitor
I want to be able to search products from a keyword

Background:
Given the store operates on a channel named "US Channel" with hostname "127.0.0.1"
And that channel allows to shop using "English (United States)" and "Italian (Italy)" locales
And it uses the "English (United States)" locale by default
And the store operates on another channel named "IT Channel" with hostname "shop.it"
And that channel allows to shop using "English (United States)" and "Italian (Italy)" locales
And it uses the "Italian (Italy)" locale by default

And the store has a product "T-Shirt Banana" with code "T_SHIRT_BANANA"
And this product is available in "US Channel" channel
And this product is also available in "IT Channel" channel

And the store has a product "T-Shirt Apple" available in "US Channel" channel
And this product is also available in "IT Channel" channel

And the store has a "T-Shirt Orange" configurable product
And this product has a "T-Shirt Orange - Medium size" variant with code "T_SHIRT_ORANGE_M"
And this product is available in "US Channel" channel
And this product is also available in "IT Channel" channel

And the store is indexed on Elasticsearch
And I am browsing the channel "US Channel"
128 changes: 128 additions & 0 deletions features/product/search_products/search_products_by_properties.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
@search_products
Feature: Search products by properties
In order to find products that fits my needs
As a Visitor
I want to be able to search products from a keyword

Background:
Given the store operates on a channel named "US Channel" with hostname "127.0.0.1"
And that channel allows to shop using "English (United States)" and "Italian (Italy)" locales
And it uses the "English (United States)" locale by default
And the store operates on another channel named "IT Channel" with hostname "shop.it"
And that channel allows to shop using "English (United States)" and "Italian (Italy)" locales
And it uses the "Italian (Italy)" locale by default

And the store has taxonomy named "T-Shirts" in "English (United States)" locale and "Magliette" in "Italian (Italy)" locale

And the store has a product "T-Shirt Banana" with code "T_SHIRT_BANANA"
And this product is available in "US Channel" channel
And this product is also available in "IT Channel" channel
And this product is named "Maglietta Banana" in the "Italian (Italy)" locale
And the description of product "T-Shirt Banana" is "Yellow t-shirt with a banana stamp on it. Composition is 100% cotton. No bananas were harmed during the making of this t-shirt." in the "English (United States)" locale
And the short description of product "T-Shirt Banana" is "Yellow t-shirt with a banana stamp on it" in the "English (United States)" locale
And the slug of product "T-Shirt Banana" is "yellow-shirt" in the "English (United States)" locale
And the meta-description of product "T-Shirt Banana" is "Ut autem corrupti aut quaerat" in the "English (United States)" locale
And the meta-keywords of product "T-Shirt Banana" are "Neque porro quisquam est" in the "English (United States)" locale
And this product belongs to "T-Shirts"

And the store has a product "T-Shirt Apple" available in "US Channel" channel
And this product is also available in "IT Channel" channel
And this product is named "Maglietta Mela" in the "Italian (Italy)" locale
And the description of product "T-Shirt Apple" is "Green t-shirt with an apple stamp on it. Composition is 100% cotton. No apples were harmed during the making of this t-shirt." in the "English (United States)" locale
And the short description of product "T-Shirt Apple" is "Apple t-shirt lorem ipsum dolor" in the "English (United States)" locale
And the slug of product "T-Shirt Apple" is "apple-green-shirt-slug" in the "English (United States)" locale
And this product belongs to "T-Shirts"

And the store has a "T-Shirt Orange" configurable product
And this product has a "T-Shirt Orange - Medium size" variant with code "T_SHIRT_ORANGE_M"
And this product is available in "US Channel" channel
And this product is also available in "IT Channel" channel
And this product is named "Maglietta Arancia" in the "Italian (Italy)" locale
And the description of product "T-Shirt Orange" is "Orange t-shirt with an orange stamp on it. Composition is 100% cotton. No oranges were harmed during the making of this t-shirt." in the "English (United States)" locale
And the short description of product "T-Shirt Orange" is "Orange t-shirt with an orange stamp on it" in the "English (United States)" locale
And the slug of product "T-Shirt Orange" is "orange-shirt" in the "English (United States)" locale
And this product belongs to "T-Shirts"

And the store is indexed on Elasticsearch
And I am browsing the channel "US Channel"

@ui
Scenario: Search only enabled products
Given the store has a product "T-Shirt disabled" available in "US Channel" channel
And this product has been disabled
And the store is indexed on Elasticsearch
When I search for "shirt"
Then I should see "3" results

@ui
Scenario: Search products by code
When I search for "T_SHIRT_BANANA"
Then I should be redirected to the product "T-Shirt Banana" page

@ui
Scenario: Search products by variant code
When I search for "T_SHIRT_ORANGE_M"
Then I should be redirected to the product "T-Shirt Orange" page

@ui
Scenario: Search products by name
When I search for "shirt"
Then I should see "3" results
And I should see the product "T-Shirt Banana"
And I should see the product "T-Shirt Apple"
And I should see the product "T-Shirt Orange"

@ui
Scenario: Search products by name in different locale
Given I am browsing the channel "IT Channel"
When I search for "maglietta"
Then I should see "3" results
And I should see the product "Maglietta Banana"
And I should see the product "Maglietta Mela"
And I should see the product "Maglietta Arancia"

@ui
Scenario: Search products by variant name
When I search for "medium"
Then I should be redirected to the product "T-Shirt Orange" page

@ui
Scenario: Search products by description
When I search for "harmed making"
Then I should see "3" results
And I should see the product "T-Shirt Banana"
And I should see the product "T-Shirt Apple"
And I should see the product "T-Shirt Orange"

@ui
Scenario: Search products by short description
When I search for "lorem ipsum"
Then I should be redirected to the product "T-Shirt Apple" page

@ui
Scenario: Search products by slug
When I search for "slug"
Then I should be redirected to the product "T-Shirt Apple" page

@ui
Scenario: Search products by slug
When I search for "slug"
Then I should be redirected to the product "T-Shirt Apple" page

@ui
Scenario: Search products by meta-description
When I search for "autem corrupti"
Then I should be redirected to the product "T-Shirt Banana" page

@ui
Scenario: Search products by meta-keywords
When I search for "neque porro"
Then I should be redirected to the product "T-Shirt Banana" page

@ui
Scenario: Search products by taxon name
When I search for "T-Shirts"
Then I should see "3" results
And I should see the product "T-Shirt Banana"
And I should see the product "T-Shirt Apple"
And I should see the product "T-Shirt Orange"
72 changes: 72 additions & 0 deletions tests/Behat/Context/Setup/ProductContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

declare(strict_types=1);

namespace Tests\Webgriffe\SyliusElasticsearchPlugin\Behat\Context\Setup;

use Behat\Behat\Context\Context;
use Doctrine\Persistence\ObjectManager;
use Sylius\Component\Core\Model\ProductInterface;

final readonly class ProductContext implements Context
{
public function __construct(
private ObjectManager $objectManager,
) {
}

/**
* @Given /^the description of (product "[^"]+") is "([^"]+)" (in the "([^"]+)" locale)$/
*/
public function descriptionOfProductIsInTheLocale(ProductInterface $product, string $description, string $locale): void
{
$productTranslation = $product->getTranslation($locale);
$productTranslation->setDescription($description);

$this->objectManager->flush();
}

/**
* @Given /^the short description of (product "[^"]+") is "([^"]+)" (in the "([^"]+)" locale)$/
*/
public function shortDescriptionOfProductIsInTheLocale(ProductInterface $product, string $shortDescription, string $locale): void
{
$productTranslation = $product->getTranslation($locale);
$productTranslation->setShortDescription($shortDescription);

$this->objectManager->flush();
}

/**
* @Given /^the slug of (product "[^"]+") is "([^"]+)" (in the "([^"]+)" locale)$/
*/
public function slugOfProductIsInTheLocale(ProductInterface $product, string $slug, string $locale): void
{
$productTranslation = $product->getTranslation($locale);
$productTranslation->setSlug($slug);

$this->objectManager->flush();
}

/**
* @Given /^the meta-description of (product "[^"]+") is "([^"]+)" (in the "([^"]+)" locale)$/
*/
public function metaDescriptionOfProductIsInTheLocale(ProductInterface $product, string $metaDescription, string $locale): void
{
$productTranslation = $product->getTranslation($locale);
$productTranslation->setMetaDescription($metaDescription);

$this->objectManager->flush();
}

/**
* @Given /^the meta-keywords of (product "[^"]+") are "([^"]+)" (in the "([^"]+)" locale)$/
*/
public function metaKeywordsOfProductIsInTheLocale(ProductInterface $product, string $metaKeywords, string $locale): void
{
$productTranslation = $product->getTranslation($locale);
$productTranslation->setMetaKeywords($metaKeywords);

$this->objectManager->flush();
}
}
8 changes: 8 additions & 0 deletions tests/Behat/Resources/services/setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Tests\Webgriffe\SyliusElasticsearchPlugin\Behat\Context\Setup\ElasticsearchContext;
use Tests\Webgriffe\SyliusElasticsearchPlugin\Behat\Context\Setup\ProductAttributeContext;
use Tests\Webgriffe\SyliusElasticsearchPlugin\Behat\Context\Setup\ProductContext;

return static function (ContainerConfigurator $containerConfigurator) {
$services = $containerConfigurator->services();
Expand All @@ -30,4 +31,11 @@
service('sylius.behat.shared_storage'),
])
;

$services->set('webgriffe.sylius_elasticsearch_plugin.behat.context.setup.product', ProductContext::class)
->public()
->args([
service('doctrine.orm.entity_manager'),
])
;
};
1 change: 1 addition & 0 deletions tests/Behat/Resources/suites/search_products.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ default:
- Sylius\Behat\Context\Setup\CatalogPromotionContext
- webgriffe.sylius_elasticsearch_plugin.behat.context.setup.elasticsearch
- webgriffe.sylius_elasticsearch_plugin.behat.context.setup.product_attribute
- webgriffe.sylius_elasticsearch_plugin.behat.context.setup.product

- sylius.behat.context.ui.admin.managing_product_attributes
- sylius.behat.context.ui.admin.product_showpage
Expand Down

0 comments on commit 7d3e3f0

Please sign in to comment.