Skip to content

Commit c6e590c

Browse files
Fix after review
1 parent e697883 commit c6e590c

File tree

4 files changed

+96
-103
lines changed

4 files changed

+96
-103
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,5 @@ services:
6464

6565
Ibexa\AdminUi\Behat\Page\UserProfilePage: ~
6666

67-
Ibexa\AdminUi\Behat\Page\NotificationsPage: ~
67+
Ibexa\AdminUi\Behat\Page\NotificationsViewAllPage: ~
68+

src/lib/Behat/BrowserContext/UserNotificationContext.php

Lines changed: 30 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Behat\Gherkin\Node\TableNode;
1313
use Ibexa\AdminUi\Behat\Component\UpperMenu;
1414
use Ibexa\AdminUi\Behat\Component\UserNotificationPopup;
15-
use Ibexa\AdminUi\Behat\Page\NotificationsPage;
15+
use Ibexa\AdminUi\Behat\Page\NotificationsViewAllPage;
1616
use PHPUnit\Framework\Assert;
1717

1818
class UserNotificationContext implements Context
@@ -23,15 +23,13 @@ class UserNotificationContext implements Context
2323
/** @var \Ibexa\AdminUi\Behat\Component\UserNotificationPopup */
2424
private $userNotificationPopup;
2525

26-
private NotificationsPage $notificationsPage;
26+
private NotificationsViewAllPage $notificationsViewAllPage;
2727

28-
private int $previousCount;
29-
30-
public function __construct(UpperMenu $upperMenu, UserNotificationPopup $userNotificationPopup, NotificationsPage $notificationsPage)
28+
public function __construct(UpperMenu $upperMenu, UserNotificationPopup $userNotificationPopup, NotificationsViewAllPage $notificationsViewAllPage)
3129
{
3230
$this->upperMenu = $upperMenu;
3331
$this->userNotificationPopup = $userNotificationPopup;
34-
$this->notificationsPage = $notificationsPage;
32+
$this->notificationsViewAllPage = $notificationsViewAllPage;
3533
}
3634

3735
/**
@@ -68,25 +66,12 @@ public function thereIsNotificationAppearsWithDetails(TableNode $notificationDet
6866
$this->userNotificationPopup->verifyNotification($type, $author, $description, $date, true);
6967
}
7068

71-
/**
72-
* @Then no notification appears with details:
73-
*/
74-
public function noNotificationAppearsWithDetails(TableNode $notificationDetails): void
75-
{
76-
$type = $notificationDetails->getHash()[0]['Type'];
77-
$author = $notificationDetails->getHash()[0]['Author'];
78-
$description = $notificationDetails->getHash()[0]['Description'];
79-
$date = $notificationDetails->getHash()[0]['Date'];
80-
81-
$this->userNotificationPopup->verifyIsLoaded();
82-
$this->userNotificationPopup->verifyNotification($type, $author, $description, $date, false);
83-
}
84-
8569
/**
8670
* @When I open notification menu with description :description
8771
*/
8872
public function iOpenNotificationMenu(string $description): void
8973
{
74+
$this->userNotificationPopup->verifyIsLoaded();
9075
$this->userNotificationPopup->openNotificationMenu($description);
9176
}
9277

@@ -99,20 +84,11 @@ public function iClickActionButton(string $action): void
9984
}
10085

10186
/**
102-
* @When I store current notification count
103-
*/
104-
public function storeNotificationCount(): void
105-
{
106-
$this->userNotificationPopup->verifyIsLoaded();
107-
$this->previousCount = $this->userNotificationPopup->getNotificationCount();
108-
}
109-
110-
/**
111-
* @Then the notification count should change in :direction direction
87+
* @Then the notification action should be :expectedAction
11288
*/
113-
public function verifyNotificationCountChanged(string $direction): void
89+
public function verifyNotificationAction(string $expectedAction): void
11490
{
115-
$this->userNotificationPopup->verifyNotificationCountChanged($this->previousCount, $direction);
91+
$this->userNotificationPopup->getActionButton($expectedAction);
11692
}
11793

11894
/**
@@ -138,48 +114,55 @@ public function iClickViewAllNotificationsButton(): void
138114
*/
139115
public function thereIsNotificationOnList(string $notificationTitle): void
140116
{
141-
$this->notificationsPage->verifyIsLoaded();
142-
$this->notificationsPage->verifyNotificationIsOnList($notificationTitle);
143-
}
144-
145-
/**
146-
* @Then there is no :notificationTitle notification on list
147-
*/
148-
public function thereIsNoNotificationOnList(string $notificationTitle): void
149-
{
150-
$this->notificationsPage->verifyIsLoaded();
151-
$this->notificationsPage->verifyNotificationIsNotOnList($notificationTitle);
117+
$this->notificationsViewAllPage->verifyIsLoaded();
118+
$this->notificationsViewAllPage->verifyNotificationIsOnList($notificationTitle);
152119
}
153120

154121
/**
155122
* @When I mark notification as unread with title :notificationTitle
156123
*/
157124
public function iMarkNotificationAsUnread(string $notificationTitle): void
158125
{
159-
$this->notificationsPage->markAsUnread($notificationTitle);
126+
$this->notificationsViewAllPage->markAsUnread($notificationTitle);
160127
}
161128

162129
/**
163130
* @Then the notification with title :notificationTitle has status :notificationStatus
164131
*/
165132
public function verifyNotificationStatus(string $notificationTitle, string $notificationStatus): void
166133
{
167-
Assert::assertEquals($notificationStatus, $this->notificationsPage->getStatusForNotification($notificationTitle));
134+
Assert::assertEquals($notificationStatus, $this->notificationsViewAllPage->getStatusForNotification($notificationTitle));
168135
}
169136

170137
/**
171138
* @When I go to content of notification with title :notificationTitle
172139
*/
173140
public function iGoToContent(string $notificationTitle): void
174141
{
175-
$this->notificationsPage->goToContent($notificationTitle);
142+
$this->notificationsViewAllPage->goToContent($notificationTitle);
176143
}
177144

178145
/**
179146
* @When I delete notification with title :notificationTitle
180147
*/
181148
public function iDeleteNotification(string $notificationTitle): void
182149
{
183-
$this->notificationsPage->deleteNotification($notificationTitle);
150+
$this->notificationsViewAllPage->deleteNotification($notificationTitle);
151+
}
152+
153+
/**
154+
* @Then I should see the text :text in the notifications popup
155+
*/
156+
public function iShouldSeeTextInNotificationsPopup(string $expectedMessage): void
157+
{
158+
$this->userNotificationPopup->verifyNoNotificationsMessage($expectedMessage);
159+
}
160+
161+
/**
162+
* @Then I should see the text :text in the All Notifications view
163+
*/
164+
public function iShouldSeeTextInAllNotificationsView(string $expectedMessage): void
165+
{
166+
$this->notificationsViewAllPage->verifyNoNotificationsMessage($expectedMessage);
184167
}
185168
}

src/lib/Behat/Component/UserNotificationPopup.php

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
use Exception;
1212
use Ibexa\Behat\Browser\Component\Component;
1313
use Ibexa\Behat\Browser\Element\Action\MouseOverAndClick;
14+
use Ibexa\Behat\Browser\Element\Condition\ElementExistsCondition;
1415
use Ibexa\Behat\Browser\Element\Criterion\ChildElementTextCriterion;
1516
use Ibexa\Behat\Browser\Element\Criterion\ElementTextCriterion;
17+
use Ibexa\Behat\Browser\Element\ElementInterface;
1618
use Ibexa\Behat\Browser\Locator\VisibleCSSLocator;
1719

1820
class UserNotificationPopup extends Component
@@ -87,52 +89,19 @@ public function verifyNotification(string $expectedType, string $expectedAuthor,
8789
}
8890
}
8991

90-
public function getNotificationCount(): int
91-
{
92-
try {
93-
$counterElement = $this->getHTMLPage()->find($this->getLocator('notificationCounterDot'));
94-
$countText = $counterElement->getAttribute('data-count');
95-
96-
return (int) $countText;
97-
} catch (Exception $e) {
98-
return 0;
99-
}
100-
}
101-
102-
public function verifyNotificationCountChanged(int $previousCount, string $direction): void
103-
{
104-
$attempts = 10;
105-
$interval = 500000;
106-
$currentCount = 0;
107-
108-
for ($i = 0; $i < $attempts; ++$i) {
109-
$currentCount = $this->getNotificationCount();
110-
111-
if (($direction === 'increase' && $currentCount > $previousCount) ||
112-
($direction === 'decrease' && $currentCount < $previousCount)) {
113-
return;
114-
}
115-
116-
usleep($interval);
117-
}
118-
119-
throw new \Exception(sprintf(
120-
'Expected notification count to %s (previous: %d, current: %d)',
121-
$direction,
122-
$previousCount,
123-
$currentCount
124-
));
125-
}
126-
12792
public function openNotificationMenu(string $expectedDescription): void
12893
{
129-
$notifications = $this->getHTMLPage()
130-
->setTimeout(5)
131-
->findAll($this->getLocator('notificationItem'))
132-
->filterBy(new ChildElementTextCriterion(
133-
$this->getLocator('notificationDescriptionText'),
134-
$expectedDescription
135-
));
94+
$this->getHTMLPage()
95+
->setTimeout(10)
96+
->waitUntilCondition(
97+
new ElementExistsCondition(
98+
$this->getHTMLPage(),
99+
$this->getLocator('notificationDescriptionText')
100+
)
101+
);
102+
103+
$notifications = $this->getHTMLPage()->setTimeout(5)->findAll($this->getLocator('notificationItem'))
104+
->filterBy(new ChildElementTextCriterion($this->getLocator('notificationDescriptionText'), $expectedDescription));
136105

137106
$menuButton = $notifications->first()->find($this->getLocator('notificationMenuButton'));
138107
$menuButton->click();
@@ -141,13 +110,43 @@ public function openNotificationMenu(string $expectedDescription): void
141110
public function clickActionButton(string $buttonText): void
142111
{
143112
$buttons = $this->getHTMLPage()
144-
->setTimeout(5)
113+
->setTimeout(10)
145114
->findAll($this->getLocator('notificationMenuItemContent'))
146115
->filterBy(new ElementTextCriterion($buttonText));
147116

148117
$buttons->first()->execute(new MouseOverAndClick());
149118
}
150119

120+
public function getActionButton(string $buttonText): ?ElementInterface
121+
{
122+
$this->getHTMLPage()
123+
->setTimeout(10)
124+
->waitUntilCondition(
125+
new ElementExistsCondition(
126+
$this->getHTMLPage(),
127+
$this->getLocator('notificationMenuItemContent')
128+
)
129+
);
130+
131+
return $this->getHTMLPage()
132+
->setTimeout(10)
133+
->findAll($this->getLocator('notificationMenuItemContent'))
134+
->filterBy(new ElementTextCriterion($buttonText))
135+
->first();
136+
}
137+
138+
public function verifyNoNotificationsMessage(string $expectedMessage): void
139+
{
140+
$this->getHTMLPage()->setTimeout(20)->waitUntilCondition(
141+
new ElementExistsCondition(
142+
$this->getHTMLPage(),
143+
$this->getLocator('notificationsEmptyText')
144+
)
145+
);
146+
147+
$this->getHTMLPage()->find($this->getLocator('notificationsEmptyText'))->assert()->textEquals($expectedMessage);
148+
}
149+
151150
public function clickOnMarkAllAsReadButton(): void
152151
{
153152
$this->getHTMLPage()->setTimeout(5)->find($this->getLocator('markAllAsReadButton'))->click();
@@ -180,6 +179,8 @@ protected function specifyLocators(): array
180179
new VisibleCSSLocator('notificationCounterDot', '.ibexa-header-user-menu__notice-dot'),
181180
new VisibleCSSLocator('markAllAsReadButton', '.ibexa-notifications-modal__mark-all-read-btn'),
182181
new VisibleCSSLocator('viewAllNotificationsButton', '.ibexa-notifications-modal__view-all-btn'),
182+
new VisibleCSSLocator('popupMenuHidden', '.ibexa-notification-actions-popup-menu.ibexa-popup-menu--hidden'),
183+
new VisibleCSSLocator('notificationsEmptyText', '.ibexa-notifications-modal__empty-text'),
183184
];
184185
}
185186
}

src/lib/Behat/Page/NotificationsPage.php renamed to src/lib/Behat/Page/NotificationsViewAllPage.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@
99
namespace Ibexa\AdminUi\Behat\Page;
1010

1111
use Behat\Mink\Session;
12+
use Exception;
1213
use Ibexa\AdminUi\Behat\Component\Dialog;
1314
use Ibexa\AdminUi\Behat\Component\Table\TableBuilder;
1415
use Ibexa\AdminUi\Behat\Component\Table\TableInterface;
16+
use Ibexa\Behat\Browser\Element\Condition\ElementExistsCondition;
1517
use Ibexa\Behat\Browser\Element\Criterion\ChildElementTextCriterion;
1618
use Ibexa\Behat\Browser\Locator\VisibleCSSLocator;
1719
use Ibexa\Behat\Browser\Page\Page;
1820
use Ibexa\Behat\Browser\Routing\Router;
1921

20-
final class NotificationsPage extends Page
22+
final class NotificationsViewAllPage extends Page
2123
{
2224
private TableInterface $table;
2325

@@ -38,20 +40,13 @@ public function __construct(
3840
public function verifyNotificationIsOnList(string $notificationTitle): void
3941
{
4042
if (!$this->table->hasElement(['Title' => $notificationTitle])) {
41-
throw new \Exception(sprintf('Notification "%s" not found on list.', $notificationTitle));
42-
}
43-
}
44-
45-
public function verifyNotificationIsNotOnList(string $notificationTitle): void
46-
{
47-
if ($this->table->hasElement(['Title' => $notificationTitle])) {
48-
throw new \Exception(sprintf('Notification "%s" is still present on list.', $notificationTitle));
43+
throw new Exception(sprintf('Notification "%s" not found on list.', $notificationTitle));
4944
}
5045
}
5146

5247
public function markAsUnread(string $notificationTitle): void
5348
{
54-
$this->getHTMLPage()->setTimeout(5);
49+
$this->getHTMLPage()->setTimeout(10);
5550
$this->table->getTableRow(['Title' => $notificationTitle])->click($this->getLocator('markAsUnreadButton'));
5651
}
5752

@@ -77,6 +72,18 @@ public function getStatusForNotification(string $notificationTitle): string
7772
->find($this->getLocator('rowStatus'))->getText();
7873
}
7974

75+
public function verifyNoNotificationsMessage(string $expectedMessage): void
76+
{
77+
$this->getHTMLPage()->setTimeout(10)->waitUntilCondition(
78+
new ElementExistsCondition(
79+
$this->getHTMLPage(),
80+
$this->getLocator('notificationsEmptyText')
81+
)
82+
);
83+
84+
$this->getHTMLPage()->find($this->getLocator('notificationsEmptyText'))->assert()->textEquals($expectedMessage);
85+
}
86+
8087
public function verifyIsLoaded(): void
8188
{
8289
$this->getHTMLPage()->setTimeout(5)->find($this->getLocator('pageTitle'))->assert()->textContains('Notifications');
@@ -103,6 +110,7 @@ protected function specifyLocators(): array
103110
new VisibleCSSLocator('goToContentButton', '[data-original-title="Go to content"]'),
104111
new VisibleCSSLocator('deleteButton', '.ibexa-notification-list__btn-delete'),
105112
new VisibleCSSLocator('notificationCheckbox', '.ibexa-notification-list__mark-row-checkbox'),
113+
new VisibleCSSLocator('notificationsEmptyText', '.ibexa-table__empty-table-info-text'),
106114
];
107115
}
108116
}

0 commit comments

Comments
 (0)