Skip to content

Commit

Permalink
OP-322: Behat update block textarea element with new content
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Jul 2, 2024
1 parent 9abe52c commit d4759d0
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 0 deletions.
10 changes: 10 additions & 0 deletions features/admin/managing_blocks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ Feature: Managing cms blocks
And I update it
Then I should be notified that the block has been successfully updated

@ui @javascript
Scenario: Updating block content element
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 fill the name with "Store phone number" if the name field is empty
And I change textarea content element value to "New content"
And I update it
Then I should be notified that the block has been successfully updated
And I should see "New content" in the textarea content element

@ui
Scenario: Disabling block
Given there is an existing block with "bitbag_quote" code
Expand Down
27 changes: 27 additions & 0 deletions tests/Behat/Context/Setup/BlockContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Behat\Behat\Context\Context;
use BitBag\SyliusCmsPlugin\Entity\BlockInterface;
use BitBag\SyliusCmsPlugin\Entity\ContentConfigurationInterface;
use BitBag\SyliusCmsPlugin\Repository\BlockRepositoryInterface;
use Sylius\Behat\Service\SharedStorageInterface;
use Sylius\Component\Core\Model\ChannelInterface;
Expand All @@ -24,6 +25,7 @@ public function __construct(
private SharedStorageInterface $sharedStorage,
private RandomStringGeneratorInterface $randomStringGenerator,
private FactoryInterface $blockFactory,
private FactoryInterface $contentConfigurationFactory,
private BlockRepositoryInterface $blockRepository,
) {
}
Expand Down Expand Up @@ -59,6 +61,16 @@ public function thereIsABlockWithCodeAndContent(string $code): void
$this->saveBlock($block);
}

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

$this->saveBlock($block);
}

private function createBlock(
?string $code = null,
ChannelInterface $channel = null,
Expand All @@ -80,6 +92,21 @@ private function createBlock(
return $block;
}

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

/** @var ContentConfigurationInterface $contentConfiguration */
$contentConfiguration = $this->contentConfigurationFactory->createNew();
$contentConfiguration->setType('textarea');
$contentConfiguration->setConfiguration(['textarea' => 'Content']);
$contentConfiguration->setBlock($block);

$block->addContentElement($contentConfiguration);

return $block;
}

private function saveBlock(BlockInterface $block): void
{
$this->blockRepository->add($block);
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 @@ -131,6 +131,22 @@ public function iFillTheNameIfItIsEmpty(string $name): void
$this->resolveCurrentPage()->fillNameIfItIsEmpty($name);
}

/**
* @When I change textarea content element value to :value
*/
public function iChangeTextareaContentElementValueTo(string $value): void
{
$this->resolveCurrentPage()->changeTextareaContentElementValue($value);
}

/**
* @Then I should see :content in the textarea content element
*/
public function iShouldSeeNewContentInTheTextareaContentElement(string $content): void
{
$this->resolveCurrentPage()->containsTextareaContentElementWithValue($content);
}

/**
* @When I fill the link with :link
*/
Expand Down
10 changes: 10 additions & 0 deletions tests/Behat/Page/Admin/Block/UpdatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,14 @@ public function isBlockDisabled(): bool
{
return $this->getDocument()->findField('Enabled')->isChecked();
}

public function changeTextareaContentElementValue(string $value): void
{
$this->getDocument()->fillField('Textarea', $value);
}

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

public function isBlockDisabled(): bool;

public function changeTextareaContentElementValue(string $value): void;

public function containsTextareaContentElementWithValue(string $value): bool;
}
1 change: 1 addition & 0 deletions tests/Behat/Resources/services/contexts/setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<argument type="service" id="sylius.behat.shared_storage" />
<argument type="service" id="bitbag_sylius_cms_plugin.behat.random_string_generator" />
<argument type="service" id="bitbag_sylius_cms_plugin.factory.block" />
<argument type="service" id="bitbag_sylius_cms_plugin.factory.content_configuration" />
<argument type="service" id="bitbag_sylius_cms_plugin.repository.block" />
</service>

Expand Down

0 comments on commit d4759d0

Please sign in to comment.