Skip to content

Commit 370fe43

Browse files
IBX-9630: [Behat] Added search in trash coverage (#1695)
* [Behat] Added search in trash coverage * cs & phpstan fix * Additional scenarios * fixed phpstan * updated behat yml * Added setup tag * changed oss tags in trash.feature * changed feature approach * removed migration context * switched approach to front steps * Changed OSS tag * fixed gherkin syntax * improved locators * after CR * more CR fixes * removed ununse function * removed unused function from context
1 parent 1e97389 commit 370fe43

File tree

5 files changed

+210
-2
lines changed

5 files changed

+210
-2
lines changed

features/standard/Trash.feature

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@IbexaOSS @IbexaHeadless @IbexaExperience @IbexaCommerce @javascript
1+
@IbexaHeadless @IbexaExperience @IbexaCommerce @javascript
22
Feature: Trash management
33
As an administrator
44
In order to manage content on my site
@@ -7,6 +7,7 @@ Feature: Trash management
77
Background:
88
Given I am logged as admin
99

10+
@IbexaOSS
1011
Scenario: Trash can be emptied
1112
Given a "folder" Content item named "TrashTest" exists in root
1213
| name | short_name |
@@ -20,6 +21,7 @@ Feature: Trash management
2021
When I empty the trash
2122
Then trash is empty
2223

24+
@IbexaOSS
2325
Scenario: Content can be moved to trash
2426
Given a "folder" Content item named "TrashTest" exists in root
2527
| name | short_name |
@@ -33,6 +35,7 @@ Feature: Trash management
3335
And I open "Trash" page in admin SiteAccess
3436
And there is a "Folder" "FolderToTrashManually" on Trash list
3537

38+
@IbexaOSS
3639
Scenario: Element in trash can be deleted
3740
Given a "folder" Content item named "TrashTest" exists in root
3841
| name | short_name |
@@ -49,6 +52,7 @@ Feature: Trash management
4952
Then success notification that "Deleted selected item(s) from Trash." appears
5053
And there is no "Folder" "DeleteFromTrash" on Trash list
5154

55+
@IbexaOSS
5256
Scenario: Element in trash can be restored
5357
Given a "folder" Content item named "TrashTest" exists in root
5458
| name | short_name |
@@ -66,6 +70,7 @@ Feature: Trash management
6670
And there is no "Folder" "RestoreFromTrash" on Trash list
6771
And there exists Content view Page for "TrashTest/RestoreFromTrash"
6872

73+
@IbexaOSS
6974
Scenario: Element in trash can be restored under new location
7075
Given a "folder" Content item named "TrashTest" exists in root
7176
| name | short_name |
@@ -82,3 +87,61 @@ Feature: Trash management
8287
Then success notification that "Restored content under Location 'Files'." appears
8388
And there is no "Folder" "RestoreFromTrashNewLocation" on Trash list
8489
And there exists Content view Page for "Media/Files/RestoreFromTrashNewLocation"
90+
91+
@IbexaOSS
92+
Scenario: Element in trash can be found by search
93+
Given a "folder" Content item named "TrashTest" exists in root
94+
| name | short_name |
95+
| TrashTest | TrashTest |
96+
And I create "folder" Content items in "TrashTest" in "eng-GB"
97+
| name | short_name |
98+
| TrashSearch1 | TrashSearch1 |
99+
| TrashSearch2 | TrashSearch2 |
100+
And I send "TrashTest/TrashSearch1" to the Trash
101+
And I send "TrashTest/TrashSearch2" to the Trash
102+
And I open "Trash" page in admin SiteAccess
103+
When I search for a "TrashSearch1" content item in Trash
104+
Then there is a "Folder" "TrashSearch1" on Trash list
105+
106+
@IbexaOSS
107+
Scenario: Element in trash can be found by search and filtered by content type
108+
Given a "folder" Content item named "TrashTest" exists in root
109+
| name | short_name |
110+
| TrashTest | TrashTest |
111+
And I create "article" Content items in "TrashTest" in "eng-GB"
112+
| title | short_title |
113+
| TrashSearch3 | TrashSearch3 |
114+
And I send "TrashTest/TrashSearch3" to the Trash
115+
And I open "Trash" page in admin SiteAccess
116+
When I filter search by "Article" content type
117+
Then there is a "Article" "TrashSearch3" on Trash list
118+
119+
@IbexaOSS
120+
Scenario: Element in trash can be found by search and filtered by section
121+
Given I create "folder" Content items in "Media/Files" in "eng-GB"
122+
| name | short_name |
123+
| TrashSearch4 | TrashSearch4 |
124+
And I send "Media/Files/TrashSearch4" to the Trash
125+
And I open "Trash" page in admin SiteAccess
126+
When I filter search by "Media" section
127+
Then there is a "Folder" "TrashSearch4" on Trash list
128+
129+
Scenario: Element in trash can be found by search and filtered by content item creator
130+
Given I create a user "TrashAdmin" with last name "Admin" in group "Administrator users"
131+
And a "folder" Content item named "TrashTest" exists in root
132+
| name | short_name |
133+
| TrashTest | TrashTest |
134+
And I open Login page in admin SiteAccess
135+
And I log in as "TrashAdmin" with password "Passw0rd-42"
136+
And I'm on Content view Page for TrashTest
137+
And I start creating a new content "Folder"
138+
And I set content fields
139+
| label | value |
140+
| Name | TrashSearch5 |
141+
| Description | TrashSearch5 |
142+
And I perform the "Publish" action
143+
And I'm on Content view Page for root
144+
And I send "TrashTest/TrashSearch5" to the Trash
145+
And I open "Trash" page in admin SiteAccess
146+
When I filter search by "TrashAdmin Admin" content item creator
147+
Then there is a "Folder" "TrashSearch5" on Trash list

src/bundle/Resources/config/services/test/components.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,5 @@ services:
5959
Ibexa\AdminUi\Behat\Component\FullView: ~
6060

6161
Ibexa\AdminUi\Behat\Component\DeleteContentDialog: ~
62+
63+
Ibexa\AdminUi\Behat\Component\TrashSearch: ~

src/lib/Behat/BrowserContext/TrashContext.php

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,36 @@ public function thereIsNoItemOnTrashList(string $itemType, string $itemName): vo
104104
{
105105
Assert::assertFalse($this->trashPage->hasElement($itemType, $itemName));
106106
}
107+
108+
/**
109+
* @When I search for a :contentItem content item in Trash
110+
*/
111+
public function iSearchForContentInTrash(string $contentItem): void
112+
{
113+
$this->trashPage->searchByText($contentItem);
114+
}
115+
116+
/**
117+
* @When I filter search by :contentType content type
118+
*/
119+
public function iFilterSearchByContentType(string $contentType): void
120+
{
121+
$this->trashPage->filterByContentType($contentType);
122+
}
123+
124+
/**
125+
* @When I filter search by :section section
126+
*/
127+
public function iFilterSearchBySection(string $section): void
128+
{
129+
$this->trashPage->filterBySection($section);
130+
}
131+
132+
/**
133+
* @When I filter search by :contentItemCreator content item creator
134+
*/
135+
public function iFilterSearchByContentItemCreator(string $contentItemCreator): void
136+
{
137+
$this->trashPage->filterByContentItemCreator($contentItemCreator);
138+
}
107139
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (C) Ibexa AS. All rights reserved.
5+
* @license For full copyright and license information view LICENSE file distributed with this source code.
6+
*/
7+
declare(strict_types=1);
8+
9+
namespace Ibexa\AdminUi\Behat\Component;
10+
11+
use Behat\Mink\Session;
12+
use Ibexa\Behat\Browser\Component\Component;
13+
use Ibexa\Behat\Browser\Element\Condition\ElementExistsCondition;
14+
use Ibexa\Behat\Browser\Element\Criterion\ElementTextCriterion;
15+
use Ibexa\Behat\Browser\Locator\VisibleCSSLocator;
16+
17+
class TrashSearch extends Component
18+
{
19+
private IbexaDropdown $ibexaDropdown;
20+
21+
public function __construct(Session $session, IbexaDropdown $ibexaDropdown)
22+
{
23+
parent::__construct($session);
24+
$this->ibexaDropdown = $ibexaDropdown;
25+
}
26+
27+
public function submitSearchText(string $searchQuery): void
28+
{
29+
$this->getHTMLPage()->setTimeout(3)->find($this->getLocator('mainSearchBoxInput'))->setValue($searchQuery);
30+
}
31+
32+
public function confirmSearch(): void
33+
{
34+
$this->getHTMLPage()->setTimeout(3)->find($this->getLocator('mainSearchBoxConfirmButton'))->click();
35+
}
36+
37+
public function filterByContentType(string $contentType): void
38+
{
39+
$this->getHTMLPage()->setTimeout(3)->find($this->getLocator('contentTypeFilterDropdown'))->click();
40+
41+
$this->ibexaDropdown->verifyIsLoaded();
42+
$this->ibexaDropdown->selectOption($contentType);
43+
}
44+
45+
public function filterBySection(string $section): void
46+
{
47+
$this->getHTMLPage()->setTimeout(3)->find($this->getLocator('sectionFilterDropdown'))->click();
48+
49+
$this->ibexaDropdown->verifyIsLoaded();
50+
$this->ibexaDropdown->selectOption($section);
51+
}
52+
53+
public function filterByContentItemCreator(string $contentItemCreator): void
54+
{
55+
$this->getHTMLPage()->setTimeout(3)->find($this->getLocator('creatorSearchBoxInput'))->setValue($contentItemCreator);
56+
57+
$creatorsDropdownItemLocator = $this->getLocator('creatorFilterDropdown');
58+
$this->getHTMLPage()
59+
->setTimeout(5)
60+
->waitUntilCondition(new ElementExistsCondition($this->getHTMLPage(), $creatorsDropdownItemLocator))
61+
->findAll($creatorsDropdownItemLocator)
62+
->getByCriterion(new ElementTextCriterion($contentItemCreator))
63+
->click();
64+
}
65+
66+
public function verifyIsLoaded(): void
67+
{
68+
$this->getHTMLPage()->setTimeout(5)->find($this->getLocator('mainSearchBox'))->isVisible();
69+
}
70+
71+
protected function specifyLocators(): array
72+
{
73+
return
74+
[
75+
new VisibleCSSLocator('mainSearchBox', '.ibexa-adaptive-filters--inside-container'),
76+
new VisibleCSSLocator('mainSearchBoxInput', '#trash_search_content_name'),
77+
new VisibleCSSLocator('creatorSearchBoxInput', '.ibexa-trash-search-form__item--creator .ibexa-input--text'),
78+
new VisibleCSSLocator('mainSearchBoxConfirmButton', '.ibexa-adaptive-filters__static-left .ibexa-input-text-wrapper--type-text .ibexa-input-text-wrapper__action-btn--search'),
79+
new VisibleCSSLocator('contentTypeFilterDropdown', 'label[for="trash_search_content_type"] ~ .ibexa-dropdown'),
80+
new VisibleCSSLocator('sectionFilterDropdown', 'label[for="trash_search_section"] ~ .ibexa-dropdown'),
81+
new VisibleCSSLocator('creatorFilterDropdown', '.ibexa-trash-search-form__user-list li'),
82+
];
83+
}
84+
}

src/lib/Behat/Page/TrashPage.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Ibexa\AdminUi\Behat\Component\ContentActionsMenu;
1313
use Ibexa\AdminUi\Behat\Component\Dialog;
1414
use Ibexa\AdminUi\Behat\Component\Table\TableBuilder;
15+
use Ibexa\AdminUi\Behat\Component\TrashSearch;
1516
use Ibexa\AdminUi\Behat\Component\UniversalDiscoveryWidget;
1617
use Ibexa\Behat\Browser\Locator\VisibleCSSLocator;
1718
use Ibexa\Behat\Browser\Page\Page;
@@ -32,19 +33,24 @@ class TrashPage extends Page
3233
/** @var \Ibexa\AdminUi\Behat\Component\Table\Table */
3334
private $table;
3435

36+
/** @var \Ibexa\AdminUi\Behat\Component\TrashSearch */
37+
private TrashSearch $trashSearch;
38+
3539
public function __construct(
3640
Session $session,
3741
Router $router,
3842
UniversalDiscoveryWidget $universalDiscoveryWidget,
3943
Dialog $dialog,
4044
ContentActionsMenu $contentActionsMenu,
41-
TableBuilder $tableBuilder
45+
TableBuilder $tableBuilder,
46+
TrashSearch $trashSearch
4247
) {
4348
parent::__construct($session, $router);
4449
$this->universalDiscoveryWidget = $universalDiscoveryWidget;
4550
$this->dialog = $dialog;
4651
$this->contentActionsMenu = $contentActionsMenu;
4752
$this->table = $tableBuilder->newTable()->build();
53+
$this->trashSearch = $trashSearch;
4854
}
4955

5056
public function hasElement(string $itemType, string $itemName): bool
@@ -84,6 +90,27 @@ public function select(array $parameters)
8490
$this->table->getTableRow($parameters)->select();
8591
}
8692

93+
public function searchByText(string $searchQuery): void
94+
{
95+
$this->trashSearch->submitSearchText($searchQuery);
96+
$this->trashSearch->confirmSearch();
97+
}
98+
99+
public function filterByContentType(string $contentType): void
100+
{
101+
$this->trashSearch->filterByContentType($contentType);
102+
}
103+
104+
public function filterBySection(string $section): void
105+
{
106+
$this->trashSearch->filterBySection($section);
107+
}
108+
109+
public function filterByContentItemCreator(string $contentItemCreator): void
110+
{
111+
$this->trashSearch->filterByContentItemCreator($contentItemCreator);
112+
}
113+
87114
public function restoreSelectedItems()
88115
{
89116
$this->getHTMLPage()->find($this->getLocator('restoreButton'))->click();

0 commit comments

Comments
 (0)