Skip to content

Commit

Permalink
OP-326: Behat - deleting content element
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Jul 10, 2024
1 parent bc81d10 commit 391330d
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 12 deletions.
9 changes: 9 additions & 0 deletions features/admin/managing_blocks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ Feature: Managing cms blocks
Then I should be notified that the block has been successfully updated
And I should see "New content" in the textarea content element

@ui @javascript
Scenario: Deleting content element in block
Given there is a block with "store_phone_number" code and "Textarea" content element
When I go to the update "store_phone_number" block page
And I delete the content element
And I update it
Then I should be notified that the block has been successfully updated
And I should not see "Textarea" content element in the Content elements section

@ui
Scenario: Disabling block
Given there is an existing block with "bitbag_quote" code
Expand Down
9 changes: 9 additions & 0 deletions features/admin/managing_pages.feature
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,12 @@ Feature: Managing cms pages
And I update it
Then I should be notified that the page was updated
And I should see "New content" in the textarea content element

@ui @javascript
Scenario: Deleting content element in page
Given there is a page in the store with "Textarea" content element
When I want to edit this page
And I delete the content element
And I update it
Then I should be notified that the page was updated
And I should not see "Textarea" content element in the Content elements section
13 changes: 7 additions & 6 deletions tests/Behat/Context/Setup/BlockContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Core\Model\ChannelInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Tests\BitBag\SyliusCmsPlugin\Behat\Helpers\ContentElementHelper;
use Tests\BitBag\SyliusCmsPlugin\Behat\Service\RandomStringGeneratorInterface;

final class BlockContext implements Context
Expand Down Expand Up @@ -61,11 +62,11 @@ public function thereIsABlockWithCodeAndContent(string $code): void
}

/**
* @Given there is a block with :code code and textarea content element
* @Given there is a block with :code code and :contentElement content element
*/
public function thereIsABlockWithCodeAndTextareaContentElement(string $code): void
public function thereIsABlockWithCodeAndContentElement(string $code, string $contentElement): void
{
$block = $this->createBlockWithTextareaContentElement($code);
$block = $this->createBlockWithContentElement($code, $contentElement);

$this->saveBlock($block);
}
Expand All @@ -91,13 +92,13 @@ private function createBlock(
return $block;
}

private function createBlockWithTextareaContentElement(string $code): BlockInterface
private function createBlockWithContentElement(string $code, string $contentElement): BlockInterface
{
$block = $this->createBlock($code);

$contentConfiguration = new ContentConfiguration();
$contentConfiguration->setType('textarea');
$contentConfiguration->setConfiguration(['textarea' => 'Content']);
$contentConfiguration->setType($contentElement);
$contentConfiguration->setConfiguration(ContentElementHelper::getExampleConfigurationByContentElement($contentElement));
$contentConfiguration->setBlock($block);

$block->addContentElement($contentConfiguration);
Expand Down
13 changes: 7 additions & 6 deletions tests/Behat/Context/Setup/PageContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
use Sylius\Component\Resource\Factory\FactoryInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Tests\BitBag\SyliusCmsPlugin\Behat\Helpers\ContentElementHelper;
use Tests\BitBag\SyliusCmsPlugin\Behat\Service\RandomStringGeneratorInterface;

final class PageContext implements Context
Expand Down Expand Up @@ -53,11 +54,11 @@ public function thereIsAPageInTheStore(): void
}

/**
* @Given there is a page in the store with textarea content element
* @Given there is a page in the store with :contentElement content element
*/
public function thereIsAPageInTheStoreWithTextareaContentElement(): void
public function thereIsAPageInTheStoreWithTextareaContentElement(string $contentElement): void
{
$page = $this->createPageWithTextareaContentElement();
$page = $this->createPageWithContentElement($contentElement);

$this->savePage($page);
}
Expand Down Expand Up @@ -203,14 +204,14 @@ private function createPage(
return $page;
}

private function createPageWithTextareaContentElement(): PageInterface
private function createPageWithContentElement(string $contentElement): PageInterface
{
$page = $this->createPage();

/** @var ContentConfigurationInterface $contentConfiguration */
$contentConfiguration = new ContentConfiguration();
$contentConfiguration->setType('textarea');
$contentConfiguration->setConfiguration(['textarea' => 'Content']);
$contentConfiguration->setType($contentElement);
$contentConfiguration->setConfiguration(ContentElementHelper::getExampleConfigurationByContentElement($contentElement));
$contentConfiguration->setPage($page);

$page->addContentElement($contentConfiguration);
Expand Down
16 changes: 16 additions & 0 deletions tests/Behat/Context/Ui/Admin/BlockContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,22 @@ public function iShouldSeeNewContentInTheTextareaContentElement(string $content)
$this->resolveCurrentPage()->containsTextareaContentElementWithValue($content);
}

/**
* @When I delete the content element
*/
public function iDeleteTheContentElement(): void
{
$this->resolveCurrentPage()->deleteContentElement();
}

/**
* @Then I should not see :contentElement content element in the Content elements section
*/
public function iShouldNotSeeContentElementInTheContentElementsSection(string $contentElement): void
{
Assert::false($this->resolveCurrentPage()->containsContentElement($contentElement));
}

/**
* @When I fill the link with :link
*/
Expand Down
16 changes: 16 additions & 0 deletions tests/Behat/Context/Ui/Admin/PageContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,22 @@ public function iShouldSeeNewlyCreatedContentElementInContentElementsSection(str
Assert::true($this->resolveCurrentPage()->containsContentElement($contentElement));
}

/**
* @When I delete the content element
*/
public function iDeleteTheContentElement(): void
{
$this->resolveCurrentPage()->deleteContentElement();
}

/**
* @Then I should not see :contentElement content element in the Content elements section
*/
public function iShouldNotSeeContentElementInTheContentElementsSection(string $contentElement): void
{
Assert::false($this->resolveCurrentPage()->containsContentElement($contentElement));
}

/**
* @When I add it
* @When I try to add it
Expand Down
24 changes: 24 additions & 0 deletions tests/Behat/Helpers/ContentElementHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,28 @@ public static function getDefinedElementThatShouldAppearAfterSelectContentElemen
default => throw new \InvalidArgumentException(sprintf('Content element with name "%s" does not exist.', $contentElement)),
};
}

public static function getExampleConfigurationByContentElement(string $contentElement): array
{
return match ($contentElement) {
'Textarea' => ['textarea' => 'Content'],
'Single media' => ['single_media' => 'homepage_header_image'],
'Multiple media' => ['multiple_media' => ['homepage_header_image', 'homepage_pdf']],
'Heading' => ['heading_type' => 'h1', 'heading' => 'Heading content'],
'Products carousel' => ["products_carousel" => [
"products" => [
"Everyday_white_basic_T_Shirt",
"Loose_white_designer_T_Shirt"
],
]],
'Products carousel by Taxon' => ['products_carousel_by_taxon' => 'MENU_CATEGORY'],
'Taxons list' => ["taxons_list" => [
"taxons" => [
"MENU_CATEGORY",
"t_shirts"
],
]],
default => throw new \InvalidArgumentException(sprintf('Content element with name "%s" does not exist.', $contentElement)),
};
}
}
5 changes: 5 additions & 0 deletions tests/Behat/Page/Admin/Block/UpdatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,9 @@ public function containsTextareaContentElementWithValue(string $value): bool
{
return $this->getDocument()->findField('Textarea')->getValue() === $value;
}

public function deleteContentElement(): void
{
$this->getDocument()->find('css', '.bb-collection-item-delete')->click();
}
}
2 changes: 2 additions & 0 deletions tests/Behat/Page/Admin/Block/UpdatePageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ public function isBlockDisabled(): bool;
public function changeTextareaContentElementValue(string $value): void;

public function containsTextareaContentElementWithValue(string $value): bool;

public function deleteContentElement(): void;
}
5 changes: 5 additions & 0 deletions tests/Behat/Page/Admin/Page/UpdatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,9 @@ public function containsTextareaContentElementWithValue(string $value): bool
{
return $this->getDocument()->findField('Textarea')->getValue() === $value;
}

public function deleteContentElement(): void
{
$this->getDocument()->find('css', '.bb-collection-item-delete')->click();
}
}
2 changes: 2 additions & 0 deletions tests/Behat/Page/Admin/Page/UpdatePageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ public function chooseImage(string $code): void;
public function changeTextareaContentElementValue(string $value): void;

public function containsTextareaContentElementWithValue(string $value): bool;

public function deleteContentElement(): void;
}

0 comments on commit 391330d

Please sign in to comment.