From 307977041fd3ce5d6af0160ac2d76327f3e29998 Mon Sep 17 00:00:00 2001 From: jkindly Date: Mon, 8 Jul 2024 13:11:31 +0200 Subject: [PATCH] OP-326: Behat single media --- features/admin/adding_block.feature | 14 +++++ features/admin/adding_page.feature | 4 ++ tests/Behat/Context/Ui/Admin/BlockContext.php | 40 +++++++++++--- tests/Behat/Context/Ui/Admin/PageContext.php | 16 ++++++ tests/Behat/Helpers/ContentElementHelper.php | 23 ++++++++ tests/Behat/Page/Admin/Block/CreatePage.php | 55 ++++++++++++++++++- .../Page/Admin/Block/CreatePageInterface.php | 6 ++ tests/Behat/Page/Admin/Page/CreatePage.php | 43 +++++++++------ .../Page/Admin/Page/CreatePageInterface.php | 4 ++ 9 files changed, 177 insertions(+), 28 deletions(-) create mode 100644 tests/Behat/Helpers/ContentElementHelper.php diff --git a/features/admin/adding_block.feature b/features/admin/adding_block.feature index c5fcead6..3f84c33d 100644 --- a/features/admin/adding_block.feature +++ b/features/admin/adding_block.feature @@ -31,10 +31,24 @@ Feature: Adding blocks When I go to the create block page And I fill the code with "intro" And I fill the name with "Intro" + And I click on Add button in Content elements section + And I select "Textarea" content element 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 + @ui @javascript + Scenario: Adding block with single media content element + Given there is an existing media with "image_1" code and name "Image 1" + When I go to the create block page + And I fill the code with "intro" + And I fill the name with "Intro" + And I click on Add button in Content elements section + And I select "Single media" content element + 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 + @ui Scenario: Trying to add block with existing code Given there is an existing block with "homepage_image" code diff --git a/features/admin/adding_page.feature b/features/admin/adding_page.feature index c063b2af..9a9f2750 100644 --- a/features/admin/adding_page.feature +++ b/features/admin/adding_page.feature @@ -73,6 +73,8 @@ Feature: Adding new 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 click on Add button in Content elements section + And I select "Textarea" content element 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 @@ -84,6 +86,8 @@ Feature: Adding new 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 click on Add button in Content elements section + And I select "Single media" content element 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 diff --git a/tests/Behat/Context/Ui/Admin/BlockContext.php b/tests/Behat/Context/Ui/Admin/BlockContext.php index 435d11b4..eac6658f 100755 --- a/tests/Behat/Context/Ui/Admin/BlockContext.php +++ b/tests/Behat/Context/Ui/Admin/BlockContext.php @@ -131,6 +131,30 @@ public function iFillTheNameIfItIsEmpty(string $name): void $this->resolveCurrentPage()->fillNameIfItIsEmpty($name); } + /** + * @When I click on Add button in Content elements section + */ + public function iClickOnAddButtonInContentElementsSection(): void + { + $this->resolveCurrentPage()->clickOnAddContentElementButton(); + } + + /** + * @When I select :option content element + */ + public function iSelectContentElement(string $option): void + { + $this->resolveCurrentPage()->selectContentElement($option); + } + + /** + * @When I add a textarea content element with :content content + */ + public function iAddATextareaContentElementWithContent(string $content): void + { + $this->resolveCurrentPage()->addTextareaContentElementWithContent($content); + } + /** * @When I change textarea content element value to :value */ @@ -139,6 +163,14 @@ public function iChangeTextareaContentElementValueTo(string $value): void $this->resolveCurrentPage()->changeTextareaContentElementValue($value); } + /** + * @When I add a single media content element with name :name + */ + public function iAddASingleMediaContentElementWithName(string $name): void + { + $this->resolveCurrentPage()->addSingleMediaContentElementWithName($name); + } + /** * @Then I should see :content in the textarea content element */ @@ -179,14 +211,6 @@ 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/Context/Ui/Admin/PageContext.php b/tests/Behat/Context/Ui/Admin/PageContext.php index 46257dc8..a220a837 100755 --- a/tests/Behat/Context/Ui/Admin/PageContext.php +++ b/tests/Behat/Context/Ui/Admin/PageContext.php @@ -185,6 +185,22 @@ public function iAddAndCollectionsToIt(string ...$collectionsNames): void $this->resolveCurrentPage()->associateCollections($collectionsNames); } + /** + * @When I click on Add button in Content elements section + */ + public function iClickOnAddButtonInContentElementsSection(): void + { + $this->resolveCurrentPage()->clickOnAddContentElementButton(); + } + + /** + * @When I select :option content element + */ + public function iSelectContentElement(string $option): void + { + $this->resolveCurrentPage()->selectContentElement($option); + } + /** * @When I add a textarea content element with :content content */ diff --git a/tests/Behat/Helpers/ContentElementHelper.php b/tests/Behat/Helpers/ContentElementHelper.php new file mode 100644 index 00000000..a3381a90 --- /dev/null +++ b/tests/Behat/Helpers/ContentElementHelper.php @@ -0,0 +1,23 @@ + 'content_elements_textarea', + 'Single media' => 'content_elements_single_media_dropdown', + default => throw new \InvalidArgumentException(sprintf('Content element with name "%s" does not exist.', $contentElement)), + }; + } +} diff --git a/tests/Behat/Page/Admin/Block/CreatePage.php b/tests/Behat/Page/Admin/Block/CreatePage.php index aa101218..e3fc2241 100755 --- a/tests/Behat/Page/Admin/Block/CreatePage.php +++ b/tests/Behat/Page/Admin/Block/CreatePage.php @@ -14,6 +14,7 @@ use DMore\ChromeDriver\ChromeDriver; use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsErrorTrait; +use Tests\BitBag\SyliusCmsPlugin\Behat\Helpers\ContentElementHelper; use Webmozart\Assert\Assert; class CreatePage extends BaseCreatePage implements CreatePageInterface @@ -82,28 +83,76 @@ public function associateCollections(array $collectionsNames): void /** * @throws ElementNotFoundException */ - public function addTextareaContentElementWithContent(string $content): void + public function clickOnAddContentElementButton(): 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'); + $addButton->waitFor(2, function (): bool { + return $this->hasElement('content_elements_select_type'); + }); + } + + /** + * @throws ElementNotFoundException + */ + public function selectContentElement(string $contentElement): void + { + Assert::isInstanceOf($this->getDriver(), ChromeDriver::class); + + $select = $this->getElement('content_elements_select_type'); + $select->selectOption($contentElement); + $select->waitFor(3, function () use ($contentElement): bool { + return $this->hasElement( + ContentElementHelper::getDefinedElementThatShouldAppearAfterSelectContentElement($contentElement) + ); }); + } + + /** + * @throws ElementNotFoundException + */ + public function addTextareaContentElementWithContent(string $content): void + { + Assert::isInstanceOf($this->getDriver(), ChromeDriver::class); $textarea = $this->getElement('content_elements_textarea'); $textarea->setValue($content); } + /** + * @throws ElementNotFoundException + */ + public function addSingleMediaContentElementWithName(string $name): void + { + $dropdown = $this->getElement('content_elements_single_media_dropdown'); + $dropdown->click(); + + $dropdown->waitFor(10, function () use ($name): bool { + return $this->hasElement('content_elements_single_media_dropdown_item', [ + '%item%' => $name, + ]); + }); + + $item = $this->getElement('content_elements_single_media_dropdown_item', [ + '%item%' => $name, + ]); + + $item->click(); + } + protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ '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_select_type' => '.field > label:contains("Type") ~ select', 'content_elements_textarea' => '.field > label:contains("Textarea") ~ textarea', + 'content_elements_single_media_dropdown' => '.field > label:contains("Single media") ~ .bitbag-media-autocomplete', + 'content_elements_single_media_dropdown_item' => '.field > label:contains("Single media") ~ .bitbag-media-autocomplete > div.menu > div.item:contains("%item%")', ]); } } diff --git a/tests/Behat/Page/Admin/Block/CreatePageInterface.php b/tests/Behat/Page/Admin/Block/CreatePageInterface.php index b96ffe4c..64698882 100755 --- a/tests/Behat/Page/Admin/Block/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Block/CreatePageInterface.php @@ -29,7 +29,13 @@ public function fillContent(string $content): void; public function associateCollections(array $collectionsNames): void; + public function clickOnAddContentElementButton(): void; + + public function selectContentElement(string $contentElement): void; + public function addTextareaContentElementWithContent(string $content): void; + public function addSingleMediaContentElementWithName(string $name): void; + public function disable(): void; } diff --git a/tests/Behat/Page/Admin/Page/CreatePage.php b/tests/Behat/Page/Admin/Page/CreatePage.php index f19b340e..62004e52 100755 --- a/tests/Behat/Page/Admin/Page/CreatePage.php +++ b/tests/Behat/Page/Admin/Page/CreatePage.php @@ -15,6 +15,7 @@ use Sylius\Behat\Page\Admin\Crud\CreatePage as BaseCreatePage; use Sylius\Behat\Service\SlugGenerationHelper; use Tests\BitBag\SyliusCmsPlugin\Behat\Behaviour\ContainsErrorTrait; +use Tests\BitBag\SyliusCmsPlugin\Behat\Helpers\ContentElementHelper; use Tests\BitBag\SyliusCmsPlugin\Behat\Service\FormHelper; use Webmozart\Assert\Assert; @@ -91,42 +92,50 @@ public function associateCollections(array $collectionsNames): void /** * @throws ElementNotFoundException */ - public function addTextareaContentElementWithContent(string $content): void + public function clickOnAddContentElementButton(): 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'); + $addButton->waitFor(2, function (): bool { + return $this->hasElement('content_elements_select_type'); }); - - $textarea = $this->getElement('content_elements_textarea'); - $textarea->setValue($content); } /** * @throws ElementNotFoundException */ - public function addSingleMediaContentElementWithName(string $name): void + public function selectContentElement(string $contentElement): 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_select_type'); + $select = $this->getElement('content_elements_select_type'); + $select->selectOption($contentElement); + $select->waitFor(3, function () use ($contentElement): bool { + return $this->hasElement( + ContentElementHelper::getDefinedElementThatShouldAppearAfterSelectContentElement($contentElement) + ); }); + } - $select = $this->getElement('content_elements_select_type'); - $select->selectOption('Single media'); + /** + * @throws ElementNotFoundException + */ + public function addTextareaContentElementWithContent(string $content): void + { + Assert::isInstanceOf($this->getDriver(), ChromeDriver::class); - $select->waitFor(3, function (): bool { - return $this->hasElement('content_elements_single_media_dropdown'); - }); + $textarea = $this->getElement('content_elements_textarea'); + $textarea->setValue($content); + } + /** + * @throws ElementNotFoundException + */ + public function addSingleMediaContentElementWithName(string $name): void + { $dropdown = $this->getElement('content_elements_single_media_dropdown'); $dropdown->click(); diff --git a/tests/Behat/Page/Admin/Page/CreatePageInterface.php b/tests/Behat/Page/Admin/Page/CreatePageInterface.php index fae16c4c..684446a5 100755 --- a/tests/Behat/Page/Admin/Page/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Page/CreatePageInterface.php @@ -35,6 +35,10 @@ public function fillContent(string $content): void; public function associateCollections(array $collectionsNames): void; + public function clickOnAddContentElementButton(): void; + + public function selectContentElement(string $contentElement): void; + public function addTextareaContentElementWithContent(string $content): void; public function addSingleMediaContentElementWithName(string $name): void;