From 460b087bb35b4dc304470e7ef54ea8f9e23f1ff0 Mon Sep 17 00:00:00 2001 From: juskora Date: Tue, 19 Aug 2025 14:46:44 +0200 Subject: [PATCH 01/13] Added Behat content tree coverage --- behat_suites.yml | 1 + features/standard/ContentTree.feature | 32 +++++++++++++++++ .../config/services/test/components.yaml | 2 ++ .../services/test/feature_contexts.yaml | 2 ++ .../BrowserContext/ContentTreeContext.php | 33 +++++++++++++++++ src/lib/Behat/Component/ContentTree.php | 35 +++++++++++++++++++ 6 files changed, 105 insertions(+) create mode 100644 features/standard/ContentTree.feature create mode 100644 src/lib/Behat/BrowserContext/ContentTreeContext.php create mode 100644 src/lib/Behat/Component/ContentTree.php diff --git a/behat_suites.yml b/behat_suites.yml index 6ea1d692be..c551486b32 100644 --- a/behat_suites.yml +++ b/behat_suites.yml @@ -24,6 +24,7 @@ browser: - Ibexa\AdminUi\Behat\BrowserContext\AdminUpdateContext - Ibexa\AdminUi\Behat\BrowserContext\BookmarkContext - Ibexa\AdminUi\Behat\BrowserContext\ContentPreviewContext + - Ibexa\AdminUi\Behat\BrowserContext\ContentTreeContext - Ibexa\AdminUi\Behat\BrowserContext\ContentTypeContext - Ibexa\AdminUi\Behat\BrowserContext\ContentUpdateContext - Ibexa\AdminUi\Behat\BrowserContext\ContentViewContext diff --git a/features/standard/ContentTree.feature b/features/standard/ContentTree.feature new file mode 100644 index 0000000000..189e8f1913 --- /dev/null +++ b/features/standard/ContentTree.feature @@ -0,0 +1,32 @@ +@IbexaOSS @IbexaHeadless @IbexaCommerce @IbexaExperience @javascript + +@tree +Feature: Content tree basic operations + Scenario: Content tree can be displayed +# Given I am logged as admin + Given I open Login page in admin SiteAccess + And I log in as admin with password publish + And I should be on Dashboard page + When I go to "Content structure" in Content tab + Then I verify Content tree visibility + + Scenario: It is possible to display items on Content tree + Given I create "article" Content items + | title | short_title | parentPath | language | + | Article1 | art1 | root | eng-GB | + | Article2 | art2 | root | eng-GB | + | Article3 | art3 | root | eng-GB | + And I am logged as admin + And I'm on Content view Page for "root/art1" + + Scenario: New Content item can be created under chosen nested node + Given I am logged as admin + And I'm on Content view Page for "root/art1" + When I start creating a new content "Article" + And I set content fields + | label | value | + | Title | Arttest | + | Short title | arttest | + | Intro | TestArticleIntro | + And I perform the "Publish" action + And I should be on Content view Page for "root/art1/arttest" \ No newline at end of file diff --git a/src/bundle/Resources/config/services/test/components.yaml b/src/bundle/Resources/config/services/test/components.yaml index c87348d52d..8a6774ece0 100644 --- a/src/bundle/Resources/config/services/test/components.yaml +++ b/src/bundle/Resources/config/services/test/components.yaml @@ -33,6 +33,8 @@ services: Ibexa\AdminUi\Behat\Component\UserNotificationPopup: ~ + Ibexa\AdminUi\Behat\Component\ContentTree: ~ + Ibexa\AdminUi\Behat\Component\ContentTypePicker: ~ Ibexa\AdminUi\Behat\Component\LanguagePicker: ~ diff --git a/src/bundle/Resources/config/services/test/feature_contexts.yaml b/src/bundle/Resources/config/services/test/feature_contexts.yaml index 82ee1eaeb5..8696229ce3 100644 --- a/src/bundle/Resources/config/services/test/feature_contexts.yaml +++ b/src/bundle/Resources/config/services/test/feature_contexts.yaml @@ -26,6 +26,8 @@ services: Ibexa\AdminUi\Behat\BrowserContext\UDWContext: ~ + Ibexa\AdminUi\Behat\BrowserContext\ContentTreeContext: ~ + Ibexa\AdminUi\Behat\BrowserContext\ContentTypeContext: ~ Ibexa\AdminUi\Behat\BrowserContext\NavigationContext: ~ diff --git a/src/lib/Behat/BrowserContext/ContentTreeContext.php b/src/lib/Behat/BrowserContext/ContentTreeContext.php new file mode 100644 index 0000000000..578bbfca6c --- /dev/null +++ b/src/lib/Behat/BrowserContext/ContentTreeContext.php @@ -0,0 +1,33 @@ +contentTree = $contentTree; + } + + /** + * @Then I verify Content tree visibility + */ + public function iAmOnContentTree(): void + { + $this->contentTree->verifyIsLoaded(); + } + +} diff --git a/src/lib/Behat/Component/ContentTree.php b/src/lib/Behat/Component/ContentTree.php new file mode 100644 index 0000000000..fcfd845991 --- /dev/null +++ b/src/lib/Behat/Component/ContentTree.php @@ -0,0 +1,35 @@ +getHTMLPage()->find($this->getLocator('header'))->assert()->textEquals('Content tree'); +// $this->getHTMLPage()->setTimeout(10)->find($this->getLocator('item'))->assert()->isVisible(); + + } + + protected function specifyLocators(): array + { + return [ + new VisibleCSSLocator('header','.ibexa-content-tree-container .c-tb-header__name-content,.c-header .c-header__name'), +// new VisibleCSSLocator('optionsButton', '.c-tb-contextual-menu__toggler'), +// new VisibleCSSLocator('menuOption', '.c-tb-action-list__item'), +// new VisibleCSSLocator('item', '.c-tb-list-item-single__element .c-tb-list-item-single__element--main') + ]; +} + +} \ No newline at end of file From f04b7bc6f87e9d8c82bbf31544ac686a2f409ae6 Mon Sep 17 00:00:00 2001 From: juskora Date: Wed, 20 Aug 2025 10:19:00 +0200 Subject: [PATCH 02/13] Code fixes --- src/lib/Behat/BrowserContext/ContentTreeContext.php | 6 ++---- src/lib/Behat/Component/ContentTree.php | 8 ++------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/lib/Behat/BrowserContext/ContentTreeContext.php b/src/lib/Behat/BrowserContext/ContentTreeContext.php index 578bbfca6c..3f7b7d6b9b 100644 --- a/src/lib/Behat/BrowserContext/ContentTreeContext.php +++ b/src/lib/Behat/BrowserContext/ContentTreeContext.php @@ -15,10 +15,9 @@ final class ContentTreeContext implements Context { private ContentTree $contentTree; - public function __construct ( + public function __construct( ContentTree $contentTree - ) - { + ) { $this->contentTree = $contentTree; } @@ -29,5 +28,4 @@ public function iAmOnContentTree(): void { $this->contentTree->verifyIsLoaded(); } - } diff --git a/src/lib/Behat/Component/ContentTree.php b/src/lib/Behat/Component/ContentTree.php index fcfd845991..9cd8822d3e 100644 --- a/src/lib/Behat/Component/ContentTree.php +++ b/src/lib/Behat/Component/ContentTree.php @@ -4,13 +4,11 @@ * @copyright Copyright (C) Ibexa AS. All rights reserved. * @license For full copyright and license information view LICENSE file distributed with this source code. */ - declare(strict_types=1); namespace Ibexa\AdminUi\Behat\Component; use Ibexa\Behat\Browser\Component\Component; - use Ibexa\Behat\Browser\Locator\VisibleCSSLocator; class ContentTree extends Component @@ -19,17 +17,15 @@ public function verifyIsLoaded(): void { $this->getHTMLPage()->find($this->getLocator('header'))->assert()->textEquals('Content tree'); // $this->getHTMLPage()->setTimeout(10)->find($this->getLocator('item'))->assert()->isVisible(); - } protected function specifyLocators(): array { return [ - new VisibleCSSLocator('header','.ibexa-content-tree-container .c-tb-header__name-content,.c-header .c-header__name'), + new VisibleCSSLocator('header', '.ibexa-content-tree-container .c-tb-header__name-content,.c-header .c-header__name'), // new VisibleCSSLocator('optionsButton', '.c-tb-contextual-menu__toggler'), // new VisibleCSSLocator('menuOption', '.c-tb-action-list__item'), // new VisibleCSSLocator('item', '.c-tb-list-item-single__element .c-tb-list-item-single__element--main') ]; + } } - -} \ No newline at end of file From 04374033dd6b672dc99f4c86d9219ffc02a33c39 Mon Sep 17 00:00:00 2001 From: juskora Date: Wed, 20 Aug 2025 14:51:21 +0200 Subject: [PATCH 03/13] Fixes --- features/standard/ContentTree.feature | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/features/standard/ContentTree.feature b/features/standard/ContentTree.feature index 189e8f1913..6c65446b1c 100644 --- a/features/standard/ContentTree.feature +++ b/features/standard/ContentTree.feature @@ -3,9 +3,7 @@ @tree Feature: Content tree basic operations Scenario: Content tree can be displayed -# Given I am logged as admin - Given I open Login page in admin SiteAccess - And I log in as admin with password publish + Given I am logged as admin And I should be on Dashboard page When I go to "Content structure" in Content tab Then I verify Content tree visibility From e1fc2da4d4ea78bae8f662f0e2c6ce8f6d0eff2c Mon Sep 17 00:00:00 2001 From: juskora Date: Thu, 21 Aug 2025 13:56:38 +0200 Subject: [PATCH 04/13] Added dependencies.json --- composer.json | 4 ++-- dependencies.json | 11 +++++++++++ features/standard/ContentTree.feature | 5 +++-- 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 dependencies.json diff --git a/composer.json b/composer.json index 5b7cf12e7c..f55cdf33e3 100644 --- a/composer.json +++ b/composer.json @@ -69,7 +69,7 @@ "dama/doctrine-test-bundle": "^v6.7", "ibexa/ci-scripts": "^0.2@dev", "ibexa/behat": "~4.6.0@dev", - "friendsofphp/php-cs-fixer": "^3.0", + "friendsofphp/php-cs-fixer": "^3.30", "phpunit/phpunit": "^9.5", "matthiasnoback/symfony-dependency-injection-test": "^4.0", "ibexa/doctrine-schema": "~4.6.0@dev", @@ -79,7 +79,7 @@ "ibexa/phpstan": "~4.6.x-dev", "ibexa/test-rest": "^0.1.x-dev", "ibexa/test-core": "^0.1.x-dev", - "phpstan/phpstan": "^2.0", + "phpstan/phpstan": "^2.1", "phpstan/phpstan-phpunit": "^2.0", "phpstan/phpstan-symfony": "^2.0" }, diff --git a/dependencies.json b/dependencies.json new file mode 100644 index 0000000000..f0908d67bd --- /dev/null +++ b/dependencies.json @@ -0,0 +1,11 @@ +{ + "recipesEndpoint": "", + "packages": [ + { + "requirement": "dev-ibx-9519-behat-coverage-contenttree as 4.6.x-dev", + "repositoryUrl": "https://github.com/ibexa/behat", + "package": "ibexa/behat", + "shouldBeAddedAsVCS": false + } + ] +} \ No newline at end of file diff --git a/features/standard/ContentTree.feature b/features/standard/ContentTree.feature index 6c65446b1c..60022543da 100644 --- a/features/standard/ContentTree.feature +++ b/features/standard/ContentTree.feature @@ -1,9 +1,10 @@ @IbexaOSS @IbexaHeadless @IbexaCommerce @IbexaExperience @javascript -@tree Feature: Content tree basic operations Scenario: Content tree can be displayed - Given I am logged as admin +# Given I am logged as admin + Given I open Login page in admin SiteAccess + And I log in as admin with password publish And I should be on Dashboard page When I go to "Content structure" in Content tab Then I verify Content tree visibility From f367b028d261cd92e0b6e018f34629d15682748f Mon Sep 17 00:00:00 2001 From: juskora Date: Thu, 21 Aug 2025 14:43:29 +0200 Subject: [PATCH 05/13] Added composer.json --- composer.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index f55cdf33e3..5b7cf12e7c 100644 --- a/composer.json +++ b/composer.json @@ -69,7 +69,7 @@ "dama/doctrine-test-bundle": "^v6.7", "ibexa/ci-scripts": "^0.2@dev", "ibexa/behat": "~4.6.0@dev", - "friendsofphp/php-cs-fixer": "^3.30", + "friendsofphp/php-cs-fixer": "^3.0", "phpunit/phpunit": "^9.5", "matthiasnoback/symfony-dependency-injection-test": "^4.0", "ibexa/doctrine-schema": "~4.6.0@dev", @@ -79,7 +79,7 @@ "ibexa/phpstan": "~4.6.x-dev", "ibexa/test-rest": "^0.1.x-dev", "ibexa/test-core": "^0.1.x-dev", - "phpstan/phpstan": "^2.1", + "phpstan/phpstan": "^2.0", "phpstan/phpstan-phpunit": "^2.0", "phpstan/phpstan-symfony": "^2.0" }, From 1cbff5331be40642ad88fcff479f52045ca44e54 Mon Sep 17 00:00:00 2001 From: juskora Date: Thu, 21 Aug 2025 14:56:14 +0200 Subject: [PATCH 06/13] Fixed branch name --- dependencies.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies.json b/dependencies.json index f0908d67bd..af99aad510 100644 --- a/dependencies.json +++ b/dependencies.json @@ -2,7 +2,7 @@ "recipesEndpoint": "", "packages": [ { - "requirement": "dev-ibx-9519-behat-coverage-contenttree as 4.6.x-dev", + "requirement": "dev-IBX-9519-behat-coverage-contenttree as 4.6.x-dev", "repositoryUrl": "https://github.com/ibexa/behat", "package": "ibexa/behat", "shouldBeAddedAsVCS": false From b8e4e981883bc71d04c9d76fcc33390c656db4c3 Mon Sep 17 00:00:00 2001 From: juskora Date: Wed, 3 Sep 2025 13:00:31 +0200 Subject: [PATCH 07/13] Updated steps --- features/standard/ContentTree.feature | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/features/standard/ContentTree.feature b/features/standard/ContentTree.feature index 60022543da..f6020f92f8 100644 --- a/features/standard/ContentTree.feature +++ b/features/standard/ContentTree.feature @@ -2,11 +2,8 @@ Feature: Content tree basic operations Scenario: Content tree can be displayed -# Given I am logged as admin - Given I open Login page in admin SiteAccess - And I log in as admin with password publish - And I should be on Dashboard page - When I go to "Content structure" in Content tab + Given I am logged as admin + When I'm on Content view Page for "root" Then I verify Content tree visibility Scenario: It is possible to display items on Content tree From 9b59924691a993c155f07ea072d7ce77ed3dd5c3 Mon Sep 17 00:00:00 2001 From: juskora Date: Thu, 4 Sep 2025 11:53:08 +0200 Subject: [PATCH 08/13] Added context to admin-ui-full --- behat_suites.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/behat_suites.yml b/behat_suites.yml index c551486b32..5210b1fb31 100644 --- a/behat_suites.yml +++ b/behat_suites.yml @@ -76,6 +76,7 @@ browser: - Ibexa\AdminUi\Behat\BrowserContext\ContentActionsMenuContext - Ibexa\AdminUi\Behat\BrowserContext\BookmarkContext - Ibexa\AdminUi\Behat\BrowserContext\ContentPreviewContext + - Ibexa\AdminUi\Behat\BrowserContext\ContentTreeContext - Ibexa\AdminUi\Behat\BrowserContext\ContentTypeContext - Ibexa\AdminUi\Behat\BrowserContext\ContentUpdateContext - Ibexa\AdminUi\Behat\BrowserContext\ContentViewContext From c74bc6d209e62fc0b3e02ca54b56b2828b688edf Mon Sep 17 00:00:00 2001 From: Justyna Koralewicz <79849375+juskora@users.noreply.github.com> Date: Tue, 16 Sep 2025 10:44:12 +0200 Subject: [PATCH 09/13] Apply suggestions from code review Co-authored-by: tomaszszopinski <59650405+tomaszszopinski@users.noreply.github.com> --- features/standard/ContentTree.feature | 3 +++ 1 file changed, 3 insertions(+) diff --git a/features/standard/ContentTree.feature b/features/standard/ContentTree.feature index f6020f92f8..59f8273952 100644 --- a/features/standard/ContentTree.feature +++ b/features/standard/ContentTree.feature @@ -1,4 +1,7 @@ @IbexaOSS @IbexaHeadless @IbexaCommerce @IbexaExperience @javascript + Feature: Content tree basic operations + + Scenario: Content tree can be displayed Feature: Content tree basic operations Scenario: Content tree can be displayed From 18147b59bed452661c8fadcec5c05d204ee58647 Mon Sep 17 00:00:00 2001 From: juskora Date: Mon, 6 Oct 2025 14:11:52 +0200 Subject: [PATCH 10/13] Added fixes --- features/standard/ContentTree.feature | 15 ++-- .../BrowserContext/ContentTreeContext.php | 12 ++- src/lib/Behat/Component/ContentTree.php | 75 +++++++++++++++++-- 3 files changed, 90 insertions(+), 12 deletions(-) diff --git a/features/standard/ContentTree.feature b/features/standard/ContentTree.feature index 59f8273952..47c313c37a 100644 --- a/features/standard/ContentTree.feature +++ b/features/standard/ContentTree.feature @@ -1,5 +1,6 @@ @IbexaOSS @IbexaHeadless @IbexaCommerce @IbexaExperience @javascript - Feature: Content tree basic operations + @tree + Feature: Content tree basic operations Scenario: Content tree can be displayed @@ -17,15 +18,17 @@ Feature: Content tree basic operations | Article3 | art3 | root | eng-GB | And I am logged as admin And I'm on Content view Page for "root/art1" + Then Content item "root/art1" exists in Content tree Scenario: New Content item can be created under chosen nested node Given I am logged as admin And I'm on Content view Page for "root/art1" When I start creating a new content "Article" And I set content fields - | label | value | - | Title | Arttest | - | Short title | arttest | - | Intro | TestArticleIntro | + | label | value | + | Title | Arttest | + | Short title | arttest | + | Intro | TestArticleIntro| And I perform the "Publish" action - And I should be on Content view Page for "root/art1/arttest" \ No newline at end of file + And I should be on Content view Page for "root/art1/arttest" + Then Content item "root/art1" exists in Content tree \ No newline at end of file diff --git a/src/lib/Behat/BrowserContext/ContentTreeContext.php b/src/lib/Behat/BrowserContext/ContentTreeContext.php index 3f7b7d6b9b..779cb3d33f 100644 --- a/src/lib/Behat/BrowserContext/ContentTreeContext.php +++ b/src/lib/Behat/BrowserContext/ContentTreeContext.php @@ -17,7 +17,8 @@ final class ContentTreeContext implements Context public function __construct( ContentTree $contentTree - ) { + ) + { $this->contentTree = $contentTree; } @@ -28,4 +29,13 @@ public function iAmOnContentTree(): void { $this->contentTree->verifyIsLoaded(); } + + /** + * @Then Content item :itemPath exists in Content tree + */ + public function contentItemExistsInContentTree(string $itemPath): void + { + $this->contentTree->verifyIsLoaded(); + $this->contentTree->verifyItemExists($itemPath); + } } diff --git a/src/lib/Behat/Component/ContentTree.php b/src/lib/Behat/Component/ContentTree.php index 9cd8822d3e..e8cc9b7258 100644 --- a/src/lib/Behat/Component/ContentTree.php +++ b/src/lib/Behat/Component/ContentTree.php @@ -8,24 +8,89 @@ namespace Ibexa\AdminUi\Behat\Component; +use Couchbase\TimeoutException; use Ibexa\Behat\Browser\Component\Component; +use Ibexa\Behat\Browser\Element\BaseElementInterface; +use Ibexa\Behat\Browser\Element\Condition\ElementExistsCondition; +use Ibexa\Behat\Browser\Element\ElementInterface; +use Ibexa\Behat\Browser\Exception\ElementNotFoundException; +use Ibexa\Behat\Browser\Locator\CSSLocator; use Ibexa\Behat\Browser\Locator\VisibleCSSLocator; +use PHPUnit\Framework\Assert; class ContentTree extends Component { public function verifyIsLoaded(): void { $this->getHTMLPage()->find($this->getLocator('header'))->assert()->textEquals('Content tree'); -// $this->getHTMLPage()->setTimeout(10)->find($this->getLocator('item'))->assert()->isVisible(); + } + public function verifyItemExists(string $itemPath): void + { + Assert::assertTrue($this->itemExists($itemPath)); + } + + private function itemExists(string $itemPath): bool + { + + $pathParts = explode('/', $itemPath); + + try { + $this->getHTMLPage() + ->setTimeout(5) + ->waitUntilCondition(new ElementExistsCondition($this->getHTMLPage(), + $this->getLocator('treeItem'))); + } catch (TimeoutException $e) { + return false; + } + $searchedNode = $this->getHTMLPage()->find($itemPath); + + try { + $this->searchForItem(end($itemPath)); + } catch (TimeoutException $e) { + return false; + } + foreach ($pathParts as $indent => $itemPath) { + try { + $searchedNode = $this->findNestedTreeElement($searchedNode, $itemPath, $indent); + } catch (ElementNotFoundException $e) { + return false; + } catch (TimeoutException $e) { + return false; + } + + if ($itemPath !== end($itemPath)) { + $searchedNode = $searchedNode->find(new VisibleCSSLocator('', '.c-tb-list')); + } + } + + $this->getHTMLPage() + ->setTimeout(5) + ->waitUntilCondition(new ElementExistsCondition($this->getHTMLPage(), $this->getLocator('treeItem'))); + + return true; + } + private function findNestedTreeElement(BaseElementInterface $baseElement, string $searchedElementName, int $indent): ElementInterface + { + return $baseElement->findAll($this->getLocator('treeItem')) + ->filter(static function (ElementInterface $element) use ($indent): bool { + return $element->findAll( + new CSSLocator('', sprintf('[style*="--indent: %d;"]', $indent)) + )->any(); + }) + ->filter(static function (ElementInterface $element) use ($searchedElementName): bool { + return str_replace(' ', '', $element->find( + new VisibleCSSLocator('', '.c-tb-list-item-single__element') + )->getText()) === $searchedElementName; + }) + ->first(); } protected function specifyLocators(): array { return [ new VisibleCSSLocator('header', '.ibexa-content-tree-container .c-tb-header__name-content,.c-header .c-header__name'), -// new VisibleCSSLocator('optionsButton', '.c-tb-contextual-menu__toggler'), -// new VisibleCSSLocator('menuOption', '.c-tb-action-list__item'), -// new VisibleCSSLocator('item', '.c-tb-list-item-single__element .c-tb-list-item-single__element--main') - ]; + new VisibleCSSLocator('treeItem', '.c-tb-list-item-single__label'), + new VisibleCSSLocator('treeElement', '.ibexa-content-tree-container__root .c-tb-list-item-single__element'), + ]; } } From c47650ce78eae91273a453290fb64f8142ddf708 Mon Sep 17 00:00:00 2001 From: juskora Date: Thu, 9 Oct 2025 09:15:40 +0200 Subject: [PATCH 11/13] Code after fixes --- features/standard/ContentTree.feature | 4 +- .../BrowserContext/ContentTreeContext.php | 9 +++ src/lib/Behat/Component/ContentTree.php | 64 ++----------------- 3 files changed, 17 insertions(+), 60 deletions(-) diff --git a/features/standard/ContentTree.feature b/features/standard/ContentTree.feature index 47c313c37a..ae861b77ff 100644 --- a/features/standard/ContentTree.feature +++ b/features/standard/ContentTree.feature @@ -30,5 +30,5 @@ Feature: Content tree basic operations | Short title | arttest | | Intro | TestArticleIntro| And I perform the "Publish" action - And I should be on Content view Page for "root/art1/arttest" - Then Content item "root/art1" exists in Content tree \ No newline at end of file + And I'm on Content view Page for "root/art1/arttest" + Then Content item "root/art1/arttest" exists in Content tree diff --git a/src/lib/Behat/BrowserContext/ContentTreeContext.php b/src/lib/Behat/BrowserContext/ContentTreeContext.php index 779cb3d33f..cf880106eb 100644 --- a/src/lib/Behat/BrowserContext/ContentTreeContext.php +++ b/src/lib/Behat/BrowserContext/ContentTreeContext.php @@ -10,6 +10,7 @@ use Behat\Behat\Context\Context; use Ibexa\AdminUi\Behat\Component\ContentTree; +use Symfony\Component\Stopwatch\Stopwatch; final class ContentTreeContext implements Context { @@ -38,4 +39,12 @@ public function contentItemExistsInContentTree(string $itemPath): void $this->contentTree->verifyIsLoaded(); $this->contentTree->verifyItemExists($itemPath); } + /** + * @Given I wait :number seconds + */ + public function iWait(string $number): void + { + $number = (int) $number; + sleep($number); + } } diff --git a/src/lib/Behat/Component/ContentTree.php b/src/lib/Behat/Component/ContentTree.php index e8cc9b7258..5086bab23c 100644 --- a/src/lib/Behat/Component/ContentTree.php +++ b/src/lib/Behat/Component/ContentTree.php @@ -8,13 +8,8 @@ namespace Ibexa\AdminUi\Behat\Component; -use Couchbase\TimeoutException; use Ibexa\Behat\Browser\Component\Component; -use Ibexa\Behat\Browser\Element\BaseElementInterface; -use Ibexa\Behat\Browser\Element\Condition\ElementExistsCondition; -use Ibexa\Behat\Browser\Element\ElementInterface; -use Ibexa\Behat\Browser\Exception\ElementNotFoundException; -use Ibexa\Behat\Browser\Locator\CSSLocator; +use Ibexa\Behat\Browser\Element\Criterion\ElementTextCriterion; use Ibexa\Behat\Browser\Locator\VisibleCSSLocator; use PHPUnit\Framework\Assert; @@ -28,61 +23,12 @@ public function verifyItemExists(string $itemPath): void { Assert::assertTrue($this->itemExists($itemPath)); } - private function itemExists(string $itemPath): bool { $pathParts = explode('/', $itemPath); - - try { - $this->getHTMLPage() - ->setTimeout(5) - ->waitUntilCondition(new ElementExistsCondition($this->getHTMLPage(), - $this->getLocator('treeItem'))); - } catch (TimeoutException $e) { - return false; - } - $searchedNode = $this->getHTMLPage()->find($itemPath); - - try { - $this->searchForItem(end($itemPath)); - } catch (TimeoutException $e) { - return false; - } - foreach ($pathParts as $indent => $itemPath) { - try { - $searchedNode = $this->findNestedTreeElement($searchedNode, $itemPath, $indent); - } catch (ElementNotFoundException $e) { - return false; - } catch (TimeoutException $e) { - return false; - } - - if ($itemPath !== end($itemPath)) { - $searchedNode = $searchedNode->find(new VisibleCSSLocator('', '.c-tb-list')); - } - } - - $this->getHTMLPage() - ->setTimeout(5) - ->waitUntilCondition(new ElementExistsCondition($this->getHTMLPage(), $this->getLocator('treeItem'))); - - return true; - } - private function findNestedTreeElement(BaseElementInterface $baseElement, string $searchedElementName, int $indent): ElementInterface - { - return $baseElement->findAll($this->getLocator('treeItem')) - ->filter(static function (ElementInterface $element) use ($indent): bool { - return $element->findAll( - new CSSLocator('', sprintf('[style*="--indent: %d;"]', $indent)) - )->any(); - }) - ->filter(static function (ElementInterface $element) use ($searchedElementName): bool { - return str_replace(' ', '', $element->find( - new VisibleCSSLocator('', '.c-tb-list-item-single__element') - )->getText()) === $searchedElementName; - }) - ->first(); + $searchedElement = $this->getHTMLPage()->findAll($this->getLocator('contextInTree'))->getByCriterion(new ElementTextCriterion(end($pathParts))); + return $searchedElement !== null; } protected function specifyLocators(): array @@ -91,6 +37,8 @@ protected function specifyLocators(): array new VisibleCSSLocator('header', '.ibexa-content-tree-container .c-tb-header__name-content,.c-header .c-header__name'), new VisibleCSSLocator('treeItem', '.c-tb-list-item-single__label'), new VisibleCSSLocator('treeElement', '.ibexa-content-tree-container__root .c-tb-list-item-single__element'), - ]; + new VisibleCSSLocator('search', '.c-tb-search .ibexa-input'), + new VisibleCSSLocator('contextInTree', '.c-tb-list-item-single__link'), + ]; } } From 21302316aceb8554feb00f307c39e06a45a74a0e Mon Sep 17 00:00:00 2001 From: juskora Date: Thu, 9 Oct 2025 09:21:03 +0200 Subject: [PATCH 12/13] Fixes --- features/standard/ContentTree.feature | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/features/standard/ContentTree.feature b/features/standard/ContentTree.feature index ae861b77ff..3b26768a55 100644 --- a/features/standard/ContentTree.feature +++ b/features/standard/ContentTree.feature @@ -1,10 +1,6 @@ @IbexaOSS @IbexaHeadless @IbexaCommerce @IbexaExperience @javascript - @tree - Feature: Content tree basic operations - - Scenario: Content tree can be displayed - Feature: Content tree basic operations + Scenario: Content tree can be displayed Given I am logged as admin When I'm on Content view Page for "root" From 2836713154930d796d47bfbe7d2c5a4d78663e12 Mon Sep 17 00:00:00 2001 From: Justyna Koralewicz <79849375+juskora@users.noreply.github.com> Date: Fri, 10 Oct 2025 12:32:46 +0200 Subject: [PATCH 13/13] Apply suggestions from code review Co-authored-by: katarzynazawada <42930265+katarzynazawada@users.noreply.github.com> Co-authored-by: Adrian Pawlak --- features/standard/ContentTree.feature | 2 +- src/lib/Behat/BrowserContext/ContentTreeContext.php | 2 +- src/lib/Behat/Component/ContentTree.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/features/standard/ContentTree.feature b/features/standard/ContentTree.feature index 3b26768a55..69e45c3fff 100644 --- a/features/standard/ContentTree.feature +++ b/features/standard/ContentTree.feature @@ -13,7 +13,7 @@ Feature: Content tree basic operations | Article2 | art2 | root | eng-GB | | Article3 | art3 | root | eng-GB | And I am logged as admin - And I'm on Content view Page for "root/art1" + When I'm on Content view Page for "root/art1" Then Content item "root/art1" exists in Content tree Scenario: New Content item can be created under chosen nested node diff --git a/src/lib/Behat/BrowserContext/ContentTreeContext.php b/src/lib/Behat/BrowserContext/ContentTreeContext.php index cf880106eb..d4a04f01a0 100644 --- a/src/lib/Behat/BrowserContext/ContentTreeContext.php +++ b/src/lib/Behat/BrowserContext/ContentTreeContext.php @@ -16,7 +16,7 @@ final class ContentTreeContext implements Context { private ContentTree $contentTree; - public function __construct( + public function __construct(ContentTree $contentTree) ContentTree $contentTree ) { diff --git a/src/lib/Behat/Component/ContentTree.php b/src/lib/Behat/Component/ContentTree.php index 5086bab23c..9937a962e3 100644 --- a/src/lib/Behat/Component/ContentTree.php +++ b/src/lib/Behat/Component/ContentTree.php @@ -13,7 +13,7 @@ use Ibexa\Behat\Browser\Locator\VisibleCSSLocator; use PHPUnit\Framework\Assert; -class ContentTree extends Component +final class ContentTree extends Component { public function verifyIsLoaded(): void { @@ -38,7 +38,7 @@ protected function specifyLocators(): array new VisibleCSSLocator('treeItem', '.c-tb-list-item-single__label'), new VisibleCSSLocator('treeElement', '.ibexa-content-tree-container__root .c-tb-list-item-single__element'), new VisibleCSSLocator('search', '.c-tb-search .ibexa-input'), - new VisibleCSSLocator('contextInTree', '.c-tb-list-item-single__link'), + new VisibleCSSLocator('contentItemInTree', '.c-tb-list-item-single__link'), ]; } }