Skip to content

Commit c972535

Browse files
committed
Added fixes
1 parent 9558d09 commit c972535

File tree

3 files changed

+90
-12
lines changed

3 files changed

+90
-12
lines changed

features/standard/ContentTree.feature

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
@IbexaOSS @IbexaHeadless @IbexaCommerce @IbexaExperience @javascript
2-
Feature: Content tree basic operations
2+
@tree
3+
Feature: Content tree basic operations
34

45
Scenario: Content tree can be displayed
56

@@ -17,15 +18,17 @@ Feature: Content tree basic operations
1718
| Article3 | art3 | root | eng-GB |
1819
And I am logged as admin
1920
And I'm on Content view Page for "root/art1"
21+
Then Content item "root/art1" exists in Content tree
2022

2123
Scenario: New Content item can be created under chosen nested node
2224
Given I am logged as admin
2325
And I'm on Content view Page for "root/art1"
2426
When I start creating a new content "Article"
2527
And I set content fields
26-
| label | value |
27-
| Title | Arttest |
28-
| Short title | arttest |
29-
| Intro | TestArticleIntro |
28+
| label | value |
29+
| Title | Arttest |
30+
| Short title | arttest |
31+
| Intro | TestArticleIntro|
3032
And I perform the "Publish" action
31-
And I should be on Content view Page for "root/art1/arttest"
33+
And I should be on Content view Page for "root/art1/arttest"
34+
Then Content item "root/art1" exists in Content tree

src/lib/Behat/BrowserContext/ContentTreeContext.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ final class ContentTreeContext implements Context
1717

1818
public function __construct(
1919
ContentTree $contentTree
20-
) {
20+
)
21+
{
2122
$this->contentTree = $contentTree;
2223
}
2324

@@ -28,4 +29,13 @@ public function iAmOnContentTree(): void
2829
{
2930
$this->contentTree->verifyIsLoaded();
3031
}
32+
33+
/**
34+
* @Then Content item :itemPath exists in Content tree
35+
*/
36+
public function contentItemExistsInContentTree(string $itemPath): void
37+
{
38+
$this->contentTree->verifyIsLoaded();
39+
$this->contentTree->verifyItemExists($itemPath);
40+
}
3141
}

src/lib/Behat/Component/ContentTree.php

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,89 @@
88

99
namespace Ibexa\AdminUi\Behat\Component;
1010

11+
use Couchbase\TimeoutException;
1112
use Ibexa\Behat\Browser\Component\Component;
13+
use Ibexa\Behat\Browser\Element\BaseElementInterface;
14+
use Ibexa\Behat\Browser\Element\Condition\ElementExistsCondition;
15+
use Ibexa\Behat\Browser\Element\ElementInterface;
16+
use Ibexa\Behat\Browser\Exception\ElementNotFoundException;
17+
use Ibexa\Behat\Browser\Locator\CSSLocator;
1218
use Ibexa\Behat\Browser\Locator\VisibleCSSLocator;
19+
use PHPUnit\Framework\Assert;
1320

1421
class ContentTree extends Component
1522
{
1623
public function verifyIsLoaded(): void
1724
{
1825
$this->getHTMLPage()->find($this->getLocator('header'))->assert()->textEquals('Content tree');
19-
// $this->getHTMLPage()->setTimeout(10)->find($this->getLocator('item'))->assert()->isVisible();
26+
}
27+
public function verifyItemExists(string $itemPath): void
28+
{
29+
Assert::assertTrue($this->itemExists($itemPath));
30+
}
31+
32+
private function itemExists(string $itemPath): bool
33+
{
34+
35+
$pathParts = explode('/', $itemPath);
36+
37+
try {
38+
$this->getHTMLPage()
39+
->setTimeout(5)
40+
->waitUntilCondition(new ElementExistsCondition($this->getHTMLPage(),
41+
$this->getLocator('treeItem')));
42+
} catch (TimeoutException $e) {
43+
return false;
44+
}
45+
$searchedNode = $this->getHTMLPage()->find($itemPath);
46+
47+
try {
48+
$this->searchForItem(end($itemPath));
49+
} catch (TimeoutException $e) {
50+
return false;
51+
}
52+
foreach ($pathParts as $indent => $itemPath) {
53+
try {
54+
$searchedNode = $this->findNestedTreeElement($searchedNode, $itemPath, $indent);
55+
} catch (ElementNotFoundException $e) {
56+
return false;
57+
} catch (TimeoutException $e) {
58+
return false;
59+
}
60+
61+
if ($itemPath !== end($itemPath)) {
62+
$searchedNode = $searchedNode->find(new VisibleCSSLocator('', '.c-tb-list'));
63+
}
64+
}
65+
66+
$this->getHTMLPage()
67+
->setTimeout(5)
68+
->waitUntilCondition(new ElementExistsCondition($this->getHTMLPage(), $this->getLocator('treeItem')));
69+
70+
return true;
71+
}
72+
private function findNestedTreeElement(BaseElementInterface $baseElement, string $searchedElementName, int $indent): ElementInterface
73+
{
74+
return $baseElement->findAll($this->getLocator('treeItem'))
75+
->filter(static function (ElementInterface $element) use ($indent): bool {
76+
return $element->findAll(
77+
new CSSLocator('', sprintf('[style*="--indent: %d;"]', $indent))
78+
)->any();
79+
})
80+
->filter(static function (ElementInterface $element) use ($searchedElementName): bool {
81+
return str_replace(' ', '', $element->find(
82+
new VisibleCSSLocator('', '.c-tb-list-item-single__element')
83+
)->getText()) === $searchedElementName;
84+
})
85+
->first();
2086
}
2187

2288
protected function specifyLocators(): array
2389
{
2490
return [
2591
new VisibleCSSLocator('header', '.ibexa-content-tree-container .c-tb-header__name-content,.c-header .c-header__name'),
26-
// new VisibleCSSLocator('optionsButton', '.c-tb-contextual-menu__toggler'),
27-
// new VisibleCSSLocator('menuOption', '.c-tb-action-list__item'),
28-
// new VisibleCSSLocator('item', '.c-tb-list-item-single__element .c-tb-list-item-single__element--main')
29-
];
92+
new VisibleCSSLocator('treeItem', '.c-tb-list-item-single__label'),
93+
new VisibleCSSLocator('treeElement', '.ibexa-content-tree-container__root .c-tb-list-item-single__element'),
94+
];
3095
}
3196
}

0 commit comments

Comments
 (0)