Add missing tests for product taxons filtering

This commit is contained in:
Kamil Grygierzec 2024-08-13 17:07:14 +02:00
parent 48a8e74587
commit d0a17ce308
No known key found for this signature in database
GPG key ID: 7F54EE42DAD4B9E9
5 changed files with 130 additions and 0 deletions

View file

@ -0,0 +1,26 @@
@managing_products
Feature: Filtering listed products from a taxon
In order to quickly find products from a specific category
As an Administrator
I want to filter listed products from a taxon
Background:
Given the store operates on a single channel in "United States"
And the store classifies its products as "Jeans" and "T-Shirts"
And the store has a product "Old t-shirt" belonging to the "T-Shirts" taxon
And the store has a product "Small jeans" belonging to the "Jeans" taxon
And the store has a product "Big jeans" belonging to the "Jeans" taxon
And I am logged in as an administrator
@api @no-ui
Scenario: Filtering listed products by taxon
When I am browsing products from "T-Shirts" taxon
Then I should see the "T-Shirts" taxon
But I should not see the "Jeans" taxon
@api @ui
Scenario: Filtering listed products by product
When I am browsing products from "Jeans" taxon
And I filter them by "Small jeans" product
Then I should see the "Small jeans" product
But I should not see the "Big jeans" product

View file

@ -60,6 +60,17 @@ final class ManagingProductTaxonsContext implements Context
$this->sharedStorage->set('response', $this->client->getLastResponse());
}
/**
* @When I filter them by :product product
*/
public function iFilterThemByProduct(ProductInterface $product): void
{
$this->client->addFilter('product.code', $product->getCode());
$this->client->filter();
$this->sharedStorage->set('response', $this->client->getLastResponse());
}
/**
* @When I set the position of :product to :position
*/
@ -188,4 +199,58 @@ final class ManagingProductTaxonsContext implements Context
'The type of the "position" attribute must be "int", "string" given.',
);
}
/**
* @Then I should see the :taxon taxon
*/
public function iShouldSeeTheTaxon(TaxonInterface $taxon): void
{
Assert::true(
$this->isTaxonVisible($taxon),
sprintf('Taxon with code %s does not exist, but it should', $taxon->getCode()),
);
}
/**
* @Then I should see the :product product
*/
public function iShouldSeeTheProduct(ProductInterface $product): void
{
Assert::true(
$this->isProductVisible($product),
sprintf('Product with code %s does not exist, but it should', $product->getCode()),
);
}
/**
* @Then I should not see the :taxon taxon
*/
public function iShouldNotSeeTheTaxon(TaxonInterface $taxon): void
{
Assert::false(
$this->isTaxonVisible($taxon),
sprintf('Taxon with code %s exists, but it should not', $taxon->getCode()),
);
}
/**
* @Then I should not see the :product product
*/
public function iShouldNotSeeTheProduct(ProductInterface $product): void
{
Assert::false(
$this->isProductVisible($product),
sprintf('Product with code %s does not exist, but it should not', $product->getCode()),
);
}
private function isTaxonVisible(TaxonInterface $taxon): bool
{
return in_array($this->iriConverter->getIriFromResource($taxon), array_column($this->responseChecker->getCollection($this->sharedStorage->get('response')), 'taxon'));
}
private function isProductVisible(ProductInterface $product): bool
{
return in_array($this->iriConverter->getIriFromResource($product), array_column($this->responseChecker->getCollection($this->sharedStorage->get('response')), 'product'));
}
}

View file

@ -294,6 +294,15 @@ final readonly class ManagingProductsContext implements Context
$this->indexPage->filter();
}
/**
* @When I filter them by :productName product
*/
public function iFilterThemByProduct(string $productName): void
{
$this->indexPerTaxonPage->filterByName($productName);
$this->indexPerTaxonPage->filter();
}
/**
* @When I filter them by :taxonName main taxon
*/
@ -1436,6 +1445,28 @@ final readonly class ManagingProductsContext implements Context
Assert::false($this->updateSimpleProductPage->hasGenerateVariantsButton(), 'Generate variants button should not be visible');
}
/**
* @Then I should see the :product product
*/
public function iShouldSeeTheProduct(ProductInterface $product): void
{
Assert::true(
$this->indexPerTaxonPage->isSingleResourceOnPage(['name' => $product->getName()]),
sprintf('Product with code %s does not exist, but it should', $product->getCode()),
);
}
/**
* @Then I should not see the :product product
*/
public function iShouldNotSeeTheProduct(ProductInterface $product): void
{
Assert::false(
$this->indexPerTaxonPage->isSingleResourceOnPage(['name' => $product->getName()]),
sprintf('Product with code %s does not exist, but it should', $product->getCode()),
);
}
private function assertValidationMessage(string $element, string $message): void
{
/** @var CreatePageInterface|UpdatePageInterface $currentPage */

View file

@ -58,10 +58,16 @@ class IndexPerTaxonPage extends CrudIndexPage implements IndexPerTaxonPageInterf
$this->getDocument()->waitFor(5, fn () => null === $saveConfigurationButton->find('css', '.loading'));
}
public function filterByName(string $name): void
{
$this->getElement('name_filter')->setValue($name);
}
/** @return array<string, string> */
protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
'name_filter' => '#criteria_search_value',
'save_configuration_button' => '[data-test-save-configuration-button]',
]);
}

View file

@ -24,4 +24,6 @@ interface IndexPerTaxonPageInterface extends CrudIndexPageInterface
public function setPositionOfProduct(string $productName, string $position): void;
public function savePositions(): void;
public function filterByName(string $name): void;
}