diff --git a/features/admin/adding_block.feature b/features/admin/adding_block.feature index 773dbc47..c5fcead6 100644 --- a/features/admin/adding_block.feature +++ b/features/admin/adding_block.feature @@ -27,7 +27,7 @@ Feature: Adding blocks Then I should be notified that the block has been created @ui @javascript - Scenario: Adding block with content element + Scenario: Adding block with textarea content element When I go to the create block page And I fill the code with "intro" And I fill the name with "Intro" diff --git a/features/admin/adding_page.feature b/features/admin/adding_page.feature index 3624fc93..c063b2af 100644 --- a/features/admin/adding_page.feature +++ b/features/admin/adding_page.feature @@ -68,7 +68,7 @@ Feature: Adding new page Then I should be notified that the page has been created @ui @javascript - Scenario: Adding page with content element + Scenario: Adding page with textarea 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" @@ -76,3 +76,14 @@ 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 + + @ui @javascript + Scenario: Adding page 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 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 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/Setup/MediaContext.php b/tests/Behat/Context/Setup/MediaContext.php index 3de6ea4a..c70b3356 100755 --- a/tests/Behat/Context/Setup/MediaContext.php +++ b/tests/Behat/Context/Setup/MediaContext.php @@ -43,6 +43,18 @@ public function thereIsAnExistingMediaWithCode(string $code): void $this->saveMedia($media); } + /** + * @Given there is an existing media with :code code and name :name + */ + public function thereIsAnExistingMediaWithCodeAndName(string $code, string $name): void + { + $media = $this->createMedia($code, $name); + + $this->uploadFile($media, 'aston_martin_db_11.jpg'); + + $this->saveMedia($media); + } + /** * @Given there is an existing :type media with :code code */ diff --git a/tests/Behat/Context/Ui/Admin/PageContext.php b/tests/Behat/Context/Ui/Admin/PageContext.php index 3843acf4..46257dc8 100755 --- a/tests/Behat/Context/Ui/Admin/PageContext.php +++ b/tests/Behat/Context/Ui/Admin/PageContext.php @@ -193,6 +193,14 @@ public function iAddATextareaContentElementWithContent(string $content): void $this->resolveCurrentPage()->addTextareaContentElementWithContent($content); } + /** + * @When I add a single media content element with name :name + */ + public function iAddASingleMediaContentElementWithName(string $name): void + { + $this->resolveCurrentPage()->addSingleMediaContentElementWithName($name); + } + /** * @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 aca17768..f19b340e 100755 --- a/tests/Behat/Page/Admin/Page/CreatePage.php +++ b/tests/Behat/Page/Admin/Page/CreatePage.php @@ -106,6 +106,43 @@ public function addTextareaContentElementWithContent(string $content): void $textarea->setValue($content); } + /** + * @throws ElementNotFoundException + */ + public function addSingleMediaContentElementWithName(string $name): 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('Single media'); + + $select->waitFor(3, function (): bool { + return $this->hasElement('content_elements_single_media_dropdown'); + }); + + $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(), [ @@ -113,7 +150,10 @@ protected function getDefinedElements(): array '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_page_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/Page/CreatePageInterface.php b/tests/Behat/Page/Admin/Page/CreatePageInterface.php index 0750ba45..fae16c4c 100755 --- a/tests/Behat/Page/Admin/Page/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Page/CreatePageInterface.php @@ -36,4 +36,6 @@ public function fillContent(string $content): void; public function associateCollections(array $collectionsNames): void; public function addTextareaContentElementWithContent(string $content): void; + + public function addSingleMediaContentElementWithName(string $name): void; }