From 61e75688a5adbbec2a232d6e36533fa823fca88f Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 2 Jul 2024 11:23:08 +0200 Subject: [PATCH] OP-322: Behat adding page with content element --- features/admin/adding_page.feature | 10 +++++++++ tests/Behat/Context/Ui/Admin/PageContext.php | 8 +++++++ tests/Behat/Page/Admin/Page/CreatePage.php | 21 +++++++++++++++++++ .../Page/Admin/Page/CreatePageInterface.php | 2 ++ 4 files changed, 41 insertions(+) diff --git a/features/admin/adding_page.feature b/features/admin/adding_page.feature index 1c32ec4f2..3624fc93c 100644 --- a/features/admin/adding_page.feature +++ b/features/admin/adding_page.feature @@ -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 diff --git a/tests/Behat/Context/Ui/Admin/PageContext.php b/tests/Behat/Context/Ui/Admin/PageContext.php index ccfe8cff2..4f59eb9fc 100755 --- a/tests/Behat/Context/Ui/Admin/PageContext.php +++ b/tests/Behat/Context/Ui/Admin/PageContext.php @@ -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 diff --git a/tests/Behat/Page/Admin/Page/CreatePage.php b/tests/Behat/Page/Admin/Page/CreatePage.php index eedea8b91..8855be581 100755 --- a/tests/Behat/Page/Admin/Page/CreatePage.php +++ b/tests/Behat/Page/Admin/Page/CreatePage.php @@ -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; @@ -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', ]); } } diff --git a/tests/Behat/Page/Admin/Page/CreatePageInterface.php b/tests/Behat/Page/Admin/Page/CreatePageInterface.php index f907729ae..0750ba454 100755 --- a/tests/Behat/Page/Admin/Page/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Page/CreatePageInterface.php @@ -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; }