Skip to content

Commit

Permalink
[Product] Add scenarios for deleting used product
Browse files Browse the repository at this point in the history
  • Loading branch information
GSadee committed Oct 26, 2017
1 parent 0f9baca commit 9e179de
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
25 changes: 21 additions & 4 deletions features/product/managing_products/deleting_product.feature
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,35 @@ Feature: Deleting a product

Background:
Given the store operates on a single channel in "United States"
And the store has a product "Toyota GT86 model"
And the store has a product "Lamborghini Gallardo model"
And this product has "1:43" variant priced at "$15.00"
And this product has one review from customer "john@doe.com"
And I am logged in as an administrator

@ui
Scenario: Deleted product disappears from the product catalog
When I delete the "Toyota GT86 model" product
Scenario: Deleting product from the product catalog
When I delete the "Lamborghini Gallardo model" product
Then I should be notified that it has been successfully deleted
And this product should not exist in the product catalog

@ui
Scenario: Deleting used product should not be possible
Given there is a customer "batman@dc.com" that placed an order
And the customer bought a single "Lamborghini Gallardo model"
When I delete the "Lamborghini Gallardo model" product
Then I should be notified that this product cannot be deleted
And the product "Lamborghini Gallardo model" should still be in the shop

@ui @javascript @todo
Scenario: Deleting used product should not remove the image
Given this product has an image "lamborghini.jpg" with "thumbnail" type
And there is a customer "batman@dc.com" that placed an order
And the customer bought a single "Lamborghini Gallardo model"
When I delete the "Lamborghini Gallardo model" product
Then I should be notified that this product cannot be deleted
And this product should still have an image with "thumbnail" type

@domain
Scenario: Deleted product variants disappear from the product catalog
When I delete the "Toyota GT86 model" product
When I delete the "Lamborghini Gallardo model" product
Then there should be no variants of this product in the product catalog
27 changes: 24 additions & 3 deletions src/Sylius/Behat/Context/Ui/Admin/ManagingProductsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,10 @@ public function iEnableSlugModification($localeCode = 'en_US')

/**
* @Then the product :productName should appear in the store
* @Then the product :productName should be in the shop
* @Then the product :productName should (still) be in the shop
* @Then this product should still be named :productName
*/
public function theProductShouldAppearInTheShop($productName)
public function theProductShouldAppearInTheShop(string $productName): void
{
$this->iWantToBrowseProducts();

Expand Down Expand Up @@ -660,13 +660,23 @@ public function iRemoveAnAssociatedProductFromProductAssociation(
/**
* @Then /^(?:this product|the product "[^"]+"|it) should(?:| also) have an image with "([^"]*)" type$/
*/
public function thisProductShouldHaveAnImageWithType($type)
public function thisProductShouldHaveAnImageWithType(string $type): void
{
$currentPage = $this->resolveCurrentPage();

Assert::true($currentPage->isImageWithTypeDisplayed($type));
}

/**
* @Then /^(this product) should still have an image with "([^"]*)" type$/
*/
public function thisProductShouldStillHaveAnImageWithType(ProductInterface $product, string $type): void
{
$this->iWantToModifyAProduct($product);

$this->thisProductShouldHaveAnImageWithType($type);
}

/**
* @Then /^(?:this product|it)(?:| also) should not have any images with "([^"]*)" type$/
*/
Expand Down Expand Up @@ -938,6 +948,17 @@ public function iShouldBeNotifiedThatTheAttributeInShouldBeLongerThan($attribute
);
}

/**
* @Then I should be notified that this product cannot be deleted
*/
public function iShouldBeNotifiedThatThisProductCannotBeDeleted(): void
{
$this->notificationChecker->checkNotification(
'Error Cannot delete, the product is in use.',
NotificationType::failure()
);
}

/**
* @param string $element
* @param string $value
Expand Down
10 changes: 10 additions & 0 deletions src/Sylius/Behat/Page/Admin/Crud/IndexPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Sylius\Behat\Page\Admin\Crud;

use Behat\Mink\Driver\Selenium2Driver;
use Behat\Mink\Exception\ElementNotFoundException;
use Behat\Mink\Session;
use Sylius\Behat\Page\SymfonyPage;
Expand Down Expand Up @@ -130,6 +131,14 @@ public function deleteResourceOnPage(array $parameters)
$deletedRow = $tableAccessor->getRowWithFields($table, $parameters);
$actionButtons = $tableAccessor->getFieldFromRow($table, $deletedRow, 'actions');

if ($this->getDriver() instanceof Selenium2Driver) {
$button = $actionButtons->find('css', 'button:contains("Delete")');
$button->press();
$this->getElement('confirmation_button')->click();

return;
}

$actionButtons->pressButton('Delete');
}

Expand Down Expand Up @@ -173,6 +182,7 @@ protected function getTableAccessor()
protected function getDefinedElements()
{
return array_merge(parent::getDefinedElements(), [
'confirmation_button' => '#confirmation-button',
'filter' => 'button:contains("Filter")',
'table' => '.table',
]);
Expand Down

0 comments on commit 9e179de

Please sign in to comment.