From 476deb93dd229de0c6a1314f8e311c9696575942 Mon Sep 17 00:00:00 2001 From: jkindly Date: Tue, 9 Jul 2024 09:23:55 +0200 Subject: [PATCH] OP-326: Behat for heading content element --- features/admin/adding_block.feature | 11 ++++++ features/admin/adding_page.feature | 25 ++++++++++++ tests/Behat/Context/Setup/MediaContext.php | 14 +++++++ tests/Behat/Context/Ui/Admin/BlockContext.php | 8 ++++ tests/Behat/Context/Ui/Admin/PageContext.php | 16 ++++++++ tests/Behat/Helpers/ContentElementHelper.php | 2 + tests/Behat/Page/Admin/Block/CreatePage.php | 14 +++++++ .../Page/Admin/Block/CreatePageInterface.php | 2 + tests/Behat/Page/Admin/Page/CreatePage.php | 39 +++++++++++++++++++ .../Page/Admin/Page/CreatePageInterface.php | 4 ++ 10 files changed, 135 insertions(+) diff --git a/features/admin/adding_block.feature b/features/admin/adding_block.feature index 3f84c33d..3b855635 100644 --- a/features/admin/adding_block.feature +++ b/features/admin/adding_block.feature @@ -49,6 +49,17 @@ Feature: Adding blocks And I add it Then I should be notified that the block has been created + @ui @javascript + Scenario: Adding block with heading content element + 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 "Heading" content element + 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 + @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 9a9f2750..0c7e79d3 100644 --- a/features/admin/adding_page.feature +++ b/features/admin/adding_page.feature @@ -91,3 +91,28 @@ 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 + + @ui @javascript + Scenario: Adding page with multiple media content element + Given there is an existing media with names "Image 1" and "Image 2" + 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 click on Add button in Content elements section + And I select "Multiple media" content element + 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 + + @ui @javascript + Scenario: Adding page with heading 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 click on Add button in Content elements section + And I select "Heading" content element + 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 diff --git a/tests/Behat/Context/Setup/MediaContext.php b/tests/Behat/Context/Setup/MediaContext.php index c70b3356..c45e2f38 100755 --- a/tests/Behat/Context/Setup/MediaContext.php +++ b/tests/Behat/Context/Setup/MediaContext.php @@ -67,6 +67,20 @@ public function thereIsAnExistingTypeMediaWithCode(string $type, string $code): $this->saveMedia($media); } + /** + * @Given there is an existing media with names :firstMediaName and :secondMediaName + */ + public function thereIsExistingMediaWithNames(string ...$mediaNames): void + { + foreach ($mediaNames as $mediaName) { + $media = $this->createMedia(null, $mediaName); + + $this->uploadFile($media, 'aston_martin_db_11.jpg'); + + $this->saveMedia($media); + } + } + private function createMedia( ?string $code = null, ?string $name = null, diff --git a/tests/Behat/Context/Ui/Admin/BlockContext.php b/tests/Behat/Context/Ui/Admin/BlockContext.php index eac6658f..ef6308fb 100755 --- a/tests/Behat/Context/Ui/Admin/BlockContext.php +++ b/tests/Behat/Context/Ui/Admin/BlockContext.php @@ -171,6 +171,14 @@ public function iAddASingleMediaContentElementWithName(string $name): void $this->resolveCurrentPage()->addSingleMediaContentElementWithName($name); } + /** + * @When I add a heading content element with type :type and :content content + */ + public function iAddAHeadingContentElementWithTypeAndContent(string $type, string $content): void + { + $this->resolveCurrentPage()->addHeadingContentElementWithTypeAndContent($type, $content); + } + /** * @Then I should see :content in the textarea content element */ diff --git a/tests/Behat/Context/Ui/Admin/PageContext.php b/tests/Behat/Context/Ui/Admin/PageContext.php index a220a837..850b3c6a 100755 --- a/tests/Behat/Context/Ui/Admin/PageContext.php +++ b/tests/Behat/Context/Ui/Admin/PageContext.php @@ -217,6 +217,22 @@ public function iAddASingleMediaContentElementWithName(string $name): void $this->resolveCurrentPage()->addSingleMediaContentElementWithName($name); } + /** + * @When I add a multiple media content element with names :firstMediaName and :secondMediaName + */ + public function iAddAMultipleMediaContentElementWithNames(string ...$mediaNames): void + { + $this->resolveCurrentPage()->addMultipleMediaContentElementWithNames($mediaNames); + } + + /** + * @When I add a heading content element with type :type and :content content + */ + public function iAddAHeadingContentElementWithTypeAndContent(string $type, string $content): void + { + $this->resolveCurrentPage()->addHeadingContentElementWithTypeAndContent($type, $content); + } + /** * @When I add it * @When I try to add it diff --git a/tests/Behat/Helpers/ContentElementHelper.php b/tests/Behat/Helpers/ContentElementHelper.php index a3381a90..9872eca9 100644 --- a/tests/Behat/Helpers/ContentElementHelper.php +++ b/tests/Behat/Helpers/ContentElementHelper.php @@ -17,6 +17,8 @@ public static function getDefinedElementThatShouldAppearAfterSelectContentElemen return match ($contentElement) { 'Textarea' => 'content_elements_textarea', 'Single media' => 'content_elements_single_media_dropdown', + 'Multiple media' => 'content_elements_multiple_media_dropdown', + 'Heading' => 'content_elements_heading', 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 fca23fec..3e8812c3 100755 --- a/tests/Behat/Page/Admin/Block/CreatePage.php +++ b/tests/Behat/Page/Admin/Block/CreatePage.php @@ -143,6 +143,18 @@ public function addSingleMediaContentElementWithName(string $name): void $item->click(); } + /** + * @throws ElementNotFoundException + */ + public function addHeadingContentElementWithTypeAndContent(string $type, string $content): void + { + $heading = $this->getElement('content_elements_heading'); + $heading->selectOption($type); + + $headingContent = $this->getElement('content_elements_heading_content'); + $headingContent->setValue($content); + } + protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ @@ -153,6 +165,8 @@ protected function getDefinedElements(): array '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%")', + 'content_elements_heading' => '.field > label:contains("Heading type") ~ select', + 'content_elements_heading_content' => '.field > label:contains("Heading") ~ input[type="text"]', ]); } } diff --git a/tests/Behat/Page/Admin/Block/CreatePageInterface.php b/tests/Behat/Page/Admin/Block/CreatePageInterface.php index 64698882..406a707b 100755 --- a/tests/Behat/Page/Admin/Block/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Block/CreatePageInterface.php @@ -37,5 +37,7 @@ public function addTextareaContentElementWithContent(string $content): void; public function addSingleMediaContentElementWithName(string $name): void; + public function addHeadingContentElementWithTypeAndContent(string $type, string $content): void; + public function disable(): void; } diff --git a/tests/Behat/Page/Admin/Page/CreatePage.php b/tests/Behat/Page/Admin/Page/CreatePage.php index 1f795561..89db3fb4 100755 --- a/tests/Behat/Page/Admin/Page/CreatePage.php +++ b/tests/Behat/Page/Admin/Page/CreatePage.php @@ -152,6 +152,41 @@ public function addSingleMediaContentElementWithName(string $name): void $item->click(); } + /** + * @throws ElementNotFoundException + */ + public function addMultipleMediaContentElementWithNames(array $mediaNames): void + { + $dropdown = $this->getElement('content_elements_multiple_media_dropdown'); + $dropdown->click(); + + foreach ($mediaNames as $mediaName) { + $dropdown->waitFor(10, function () use ($mediaName): bool { + return $this->hasElement('content_elements_multiple_media_dropdown_item', [ + '%item%' => $mediaName, + ]); + }); + + $item = $this->getElement('content_elements_multiple_media_dropdown_item', [ + '%item%' => $mediaName, + ]); + + $item->click(); + } + } + + /** + * @throws ElementNotFoundException + */ + public function addHeadingContentElementWithTypeAndContent(string $type, string $content): void + { + $heading = $this->getElement('content_elements_heading'); + $heading->selectOption($type); + + $headingContent = $this->getElement('content_elements_heading_content'); + $headingContent->setValue($content); + } + protected function getDefinedElements(): array { return array_merge(parent::getDefinedElements(), [ @@ -163,6 +198,10 @@ protected function getDefinedElements(): array '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%")', + 'content_elements_multiple_media_dropdown' => '.field > label:contains("Multiple media") ~ .bitbag-media-autocomplete', + 'content_elements_multiple_media_dropdown_item' => '.field > label:contains("Multiple media") ~ .bitbag-media-autocomplete > div.menu > div.item:contains("%item%")', + 'content_elements_heading' => '.field > label:contains("Heading type") ~ select', + 'content_elements_heading_content' => '.field > label:contains("Heading") ~ input[type="text"]', ]); } } diff --git a/tests/Behat/Page/Admin/Page/CreatePageInterface.php b/tests/Behat/Page/Admin/Page/CreatePageInterface.php index 684446a5..bb002eb8 100755 --- a/tests/Behat/Page/Admin/Page/CreatePageInterface.php +++ b/tests/Behat/Page/Admin/Page/CreatePageInterface.php @@ -42,4 +42,8 @@ public function selectContentElement(string $contentElement): void; public function addTextareaContentElementWithContent(string $content): void; public function addSingleMediaContentElementWithName(string $name): void; + + public function addMultipleMediaContentElementWithNames(array $mediaNames): void; + + public function addHeadingContentElementWithTypeAndContent(string $type, string $content): void; }