Skip to content

Commit

Permalink
OP-326: Behat - make sure content element exists after create page/block
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Jul 9, 2024
1 parent e0ce8eb commit 9dfa8d0
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 2 deletions.
6 changes: 6 additions & 0 deletions features/admin/adding_block.feature
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Feature: Adding blocks
And I add a textarea content element with "Welcome to our store" content
And I add it
Then I should be notified that the block has been created
And I should see newly created "Textarea" content element in Content elements section

@ui @javascript
Scenario: Adding block with single media content element
Expand All @@ -48,6 +49,7 @@ Feature: Adding blocks
And I add a single media content element with name "Image 1"
And I add it
Then I should be notified that the block has been created
And I should see newly created "Single media" content element in Content elements section

@ui @javascript
Scenario: Adding block with heading content element
Expand All @@ -59,6 +61,7 @@ Feature: Adding blocks
And I add a heading content element with type "H3" and "Welcome to our store" content
And I add it
Then I should be notified that the block has been created
And I should see newly created "Heading" content element in Content elements section

@ui @javascript
Scenario: Adding block with products carousel content element
Expand All @@ -71,6 +74,7 @@ Feature: Adding blocks
And I add a products carousel content element with "iPhone 8" and "iPhone X" products
And I add it
Then I should be notified that the block has been created
And I should see newly created "Products carousel" content element in Content elements section

@ui @javascript
Scenario: Adding block with products carousel by taxon content element
Expand All @@ -83,6 +87,7 @@ Feature: Adding blocks
And I add a products carousel by taxon content element with "Smartphones" taxonomy
And I add it
Then I should be notified that the block has been created
And I should see newly created "Products carousel by Taxon" content element in Content elements section

@ui @javascript
Scenario: Adding block with taxons list content element
Expand All @@ -95,6 +100,7 @@ Feature: Adding blocks
And I add a taxons list content element with "Smartphones" and "Laptops" taxonomy
And I add it
Then I should be notified that the block has been created
And I should see newly created "Taxons list" content element in Content elements section

@ui
Scenario: Trying to add block with existing code
Expand Down
7 changes: 7 additions & 0 deletions features/admin/adding_page.feature
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Feature: Adding new page
And I add a textarea content element with "Welcome to our store" content
And I add it
Then I should be notified that the page has been created
And I should see newly created "Textarea" content element in Content elements section

@ui @javascript
Scenario: Adding page with single media content element
Expand All @@ -91,6 +92,7 @@ Feature: Adding new page
And I add a single media content element with name "Image 1"
And I add it
Then I should be notified that the page has been created
And I should see newly created "Single media" content element in Content elements section

@ui @javascript
Scenario: Adding page with multiple media content element
Expand All @@ -104,6 +106,7 @@ Feature: Adding new page
And I add a multiple media content element with names "Image 1" and "Image 2"
And I add it
Then I should be notified that the page has been created
And I should see newly created "Multiple media" content element in Content elements section

@ui @javascript
Scenario: Adding page with heading content element
Expand All @@ -116,6 +119,7 @@ Feature: Adding new page
And I add a heading content element with type "H3" and "Welcome to our store" content
And I add it
Then I should be notified that the page has been created
And I should see newly created "Heading" content element in Content elements section

@ui @javascript
Scenario: Adding page with products carousel content element
Expand All @@ -129,6 +133,7 @@ Feature: Adding new page
And I add a products carousel content element with "iPhone 8" and "iPhone X" products
And I add it
Then I should be notified that the page has been created
And I should see newly created "Products carousel" content element in Content elements section

@ui @javascript
Scenario: Adding page with products carousel by taxon content element
Expand All @@ -142,6 +147,7 @@ Feature: Adding new page
And I add a products carousel by taxon content element with "Smartphones" taxonomy
And I add it
Then I should be notified that the page has been created
And I should see newly created "Products carousel by Taxon" content element in Content elements section

@ui @javascript
Scenario: Adding page with taxons list content element
Expand All @@ -155,3 +161,4 @@ Feature: Adding new page
And I add a taxons list content element with "Smartphones" and "Laptops" taxonomy
And I add it
Then I should be notified that the page has been created
And I should see newly created "Taxons list" content element in Content elements section
16 changes: 16 additions & 0 deletions tests/Behat/Behaviour/ContainsContentElementInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour;

interface ContainsContentElementInterface
{
public function containsContentElement(string $contentElement): bool;
}
37 changes: 37 additions & 0 deletions tests/Behat/Behaviour/ContainsContentElementTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/*
* This file was created by developers working at BitBag
* Do you need more information about us and what we do? Visit our https://bitbag.io website!
* We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
*/

declare(strict_types=1);

namespace Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour;

use Sylius\Behat\Behaviour\DocumentAccessor;

trait ContainsContentElementTrait
{
use DocumentAccessor;

public function containsContentElement(string $contentElement): bool
{
$fieldName = match ($contentElement) {
'Products carousel' => 'Products',
'Products carousel by taxon' => 'Taxon',
'Taxons list' => 'Taxons',
default => $contentElement,
};

$contentElements = $this->getDocument()->findById('bitbag_sylius_cms_plugin_block_contentElements')
?? $this->getDocument()->findById('bitbag_sylius_cms_plugin_page_contentElements');

if (null === $contentElements) {
throw new \InvalidArgumentException('Content elements container not found');
}

return $contentElements->hasField($fieldName);
}
}
10 changes: 9 additions & 1 deletion tests/Behat/Context/Ui/Admin/PageContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function iChangeTextareaContentElementValueTo(string $value): void
*/
public function iShouldSeeNewContentInTheTextareaContentElement(string $content): void
{
$this->resolveCurrentPage()->containsTextareaContentElementWithValue($content);
Assert::true($this->resolveCurrentPage()->containsTextareaContentElementWithValue($content));
}

/**
Expand Down Expand Up @@ -257,6 +257,14 @@ public function iAddATaxonsListContentElementWithTaxons(string ...$taxons): void
$this->resolveCurrentPage()->addTaxonsListContentElementWithTaxons($taxons);
}

/**
* @Then I should see newly created :contentElement content element in Content elements section
*/
public function iShouldSeeNewlyCreatedContentElementInContentElementsSection(string $contentElement): void
{
Assert::true($this->resolveCurrentPage()->containsContentElement($contentElement));
}

/**
* @When I add it
* @When I try to add it
Expand Down
2 changes: 2 additions & 0 deletions tests/Behat/Page/Admin/Page/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use DMore\ChromeDriver\ChromeDriver;
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
use Sylius\Behat\Service\SlugGenerationHelper;
use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsContentElementTrait;
use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsErrorTrait;
use Tests\BitBag\SyliusCmsPlugin\Behat\Helpers\ContentElementHelper;
use Tests\BitBag\SyliusCmsPlugin\Behat\Service\FormHelper;
Expand All @@ -22,6 +23,7 @@
class CreatePage extends BaseCreatePage implements CreatePageInterface
{
use ContainsErrorTrait;
use ContainsContentElementTrait;

public function fillField(string $field, string $value): void
{
Expand Down
6 changes: 5 additions & 1 deletion tests/Behat/Page/Admin/Page/CreatePageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@
namespace Tests\BitBag\SyliusCmsPlugin\Behat\Page\Admin\Page;

use Sylius\Behat\Page\Admin\Crud\CreatePageInterface as BaseCreatePageInterface;
use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsContentElementInterface;
use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsErrorInterface;

interface CreatePageInterface extends BaseCreatePageInterface, ContainsErrorInterface
interface CreatePageInterface extends
BaseCreatePageInterface,
ContainsErrorInterface,
ContainsContentElementInterface
{
public const IMAGE_FORM_ID = 'bitbag_sylius_cms_plugin_page_translations_en_US_image';

Expand Down

0 comments on commit 9dfa8d0

Please sign in to comment.