Skip to content

Commit

Permalink
OP-322: Behat adding page with content element
Browse files Browse the repository at this point in the history
  • Loading branch information
jkindly committed Jul 2, 2024
1 parent 68d4841 commit 61e7568
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
10 changes: 10 additions & 0 deletions features/admin/adding_page.feature
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,13 @@ Feature: Adding new page
And I fill the name with "Best day ever"
And I add it
Then I should be notified that the page has been created

@ui @javascript
Scenario: Adding page with content element
When I go to the create page page
And I fill the code with "my_page"
And I fill the slug with "my_page"
And I fill the name with "My 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
8 changes: 8 additions & 0 deletions tests/Behat/Context/Ui/Admin/PageContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ public function iAddAndCollectionsToIt(string ...$collectionsNames): void
$this->resolveCurrentPage()->associateCollections($collectionsNames);
}

/**
* @When I add a textarea content element with :content content
*/
public function iAddATextareaContentElementWithContent(string $content): void
{
$this->resolveCurrentPage()->addTextareaContentElementWithContent($content);
}

/**
* @When I add it
* @When I try to add it
Expand Down
21 changes: 21 additions & 0 deletions tests/Behat/Page/Admin/Page/CreatePage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Tests\BitBag\SyliusCmsPlugin\Behat\Page\Admin\Page;

use Behat\Mink\Exception\ElementNotFoundException;
use DMore\ChromeDriver\ChromeDriver;
use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage;
use Sylius\Behat\Service\SlugGenerationHelper;
Expand Down Expand Up @@ -87,12 +88,32 @@ public function associateCollections(array $collectionsNames): void
}
}

/**
* @throws ElementNotFoundException
*/
public function addTextareaContentElementWithContent(string $content): void
{
Assert::isInstanceOf($this->getDriver(), ChromeDriver::class);

$addButton = $this->getElement('content_elements_add_button');
$addButton->click();

$addButton->waitFor(3, function (): bool {
return $this->hasElement('content_elements_textarea');
});

$textarea = $this->getElement('content_elements_textarea');
$textarea->setValue($content);
}

protected function getDefinedElements(): array
{
return array_merge(parent::getDefinedElements(), [
'slug' => '#bitbag_sylius_cms_plugin_page_translations_en_US_slug',
'association_dropdown_collection' => '.field > label:contains("Collections") ~ .sylius-autocomplete',
'association_dropdown_collection_item' => '.field > label:contains("Collections") ~ .sylius-autocomplete > div.menu > div.item:contains("%item%")',
'content_elements_add_button' => '#bitbag_sylius_cms_plugin_block_contentElements a[data-form-collection="add"]',
'content_elements_textarea' => '.field > label:contains("Textarea") ~ textarea',
]);
}
}
2 changes: 2 additions & 0 deletions tests/Behat/Page/Admin/Page/CreatePageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ public function fillMetaDescription(string $metaDescription): void;
public function fillContent(string $content): void;

public function associateCollections(array $collectionsNames): void;

public function addTextareaContentElementWithContent(string $content): void;
}

0 comments on commit 61e7568

Please sign in to comment.