Skip to content

Commit b8fce92

Browse files
Add new scenarios to notification feature
1 parent a0ce797 commit b8fce92

File tree

4 files changed

+260
-6
lines changed

4 files changed

+260
-6
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,5 @@ services:
6363
Ibexa\AdminUi\Behat\Page\UserSettingsPage: ~
6464

6565
Ibexa\AdminUi\Behat\Page\UserProfilePage: ~
66+
67+
Ibexa\AdminUi\Behat\Page\NotificationsPage: ~

src/lib/Behat/BrowserContext/UserNotificationContext.php

Lines changed: 96 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +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;
1516
use PHPUnit\Framework\Assert;
1617

1718
class UserNotificationContext implements Context
@@ -22,10 +23,15 @@ class UserNotificationContext implements Context
2223
/** @var \Ibexa\AdminUi\Behat\Component\UserNotificationPopup */
2324
private $userNotificationPopup;
2425

25-
public function __construct(UpperMenu $upperMenu, UserNotificationPopup $userNotificationPopup)
26+
private NotificationsPage $notificationsPage;
27+
28+
private int $previousCount;
29+
30+
public function __construct(UpperMenu $upperMenu, UserNotificationPopup $userNotificationPopup, NotificationsPage $notificationsPage)
2631
{
2732
$this->upperMenu = $upperMenu;
2833
$this->userNotificationPopup = $userNotificationPopup;
34+
$this->notificationsPage = $notificationsPage;
2935
}
3036

3137
/**
@@ -49,9 +55,9 @@ public function iGoToUserNotificationWithDetails(TableNode $notificationDetails)
4955
}
5056

5157
/**
52-
* @Then an unread notification appears with details:
58+
* @Then the notification appears with details:
5359
*/
54-
public function thereIsUnreadNotificationAppearsWithDetails(TableNode $notificationDetails): void
60+
public function thereIsNotificationAppearsWithDetails(TableNode $notificationDetails): void
5561
{
5662
$type = $notificationDetails->getHash()[0]['Type'];
5763
$author = $notificationDetails->getHash()[0]['Author'];
@@ -87,8 +93,93 @@ public function iOpenNotificationMenuNotification(string $description): void
8793
/**
8894
* @When I click :action action
8995
*/
90-
public function iDeleteTheNotification(): void
96+
public function iClickActionButton(string $action): void
97+
{
98+
$this->userNotificationPopup->clickActionButton($action);
99+
}
100+
101+
/**
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
112+
*/
113+
public function verifyNotificationCountChanged(string $direction): void
114+
{
115+
$this->userNotificationPopup->verifyNotificationCountChanged($this->previousCount, $direction);
116+
}
117+
118+
/**
119+
* @When I click mark all as read button
120+
*/
121+
public function iClickButton(): void
122+
{
123+
$this->userNotificationPopup->verifyIsLoaded();
124+
$this->userNotificationPopup->clickOnMarkAllAsReadButton();
125+
}
126+
127+
/**
128+
* @When I click view all notifications button
129+
*/
130+
public function iClickViewAllNotificationsButton(): void
131+
{
132+
$this->userNotificationPopup->verifyIsLoaded();
133+
$this->userNotificationPopup->clickViewAllNotificationsButton();
134+
}
135+
136+
/**
137+
* @Then there is :notificationTitle notification on list
138+
*/
139+
public function thereIsNotificationOnList(string $notificationTitle): void
140+
{
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);
152+
}
153+
154+
/**
155+
* @When I marked as unread notification with title :notificationTitle
156+
*/
157+
public function iMarkedNotificationAsUnread(string $notificationTitle): void
158+
{
159+
$this->notificationsPage->markAsUnread($notificationTitle);
160+
}
161+
162+
/**
163+
* @Then the notification with title :notificationTitle has status :notificationStatus
164+
*/
165+
public function verifyNotificationStatus(string $notificationTitle, string $notificationStatus): void
166+
{
167+
Assert::assertEquals($notificationStatus, $this->notificationsPage->getStatusForNotification($notificationTitle));
168+
}
169+
170+
/**
171+
* @When I go to content of notification with title :notificationTitle
172+
*/
173+
public function iGoToContent(string $notificationTitle): void
174+
{
175+
$this->notificationsPage->goToContent($notificationTitle);
176+
}
177+
178+
/**
179+
* @When I deleted notification with title :notificationTitle
180+
*/
181+
public function iDeleteNotification(string $notificationTitle): void
91182
{
92-
$this->userNotificationPopup->clickButton('Delete');
183+
$this->notificationsPage->deleteNotification($notificationTitle);
93184
}
94185
}

src/lib/Behat/Component/UserNotificationPopup.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,43 @@ public function verifyNotification(string $expectedType, string $expectedAuthor,
8787
}
8888
}
8989

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+
90127
public function openNotificationMenu(string $expectedDescription): void
91128
{
92129
$notifications = $this->getHTMLPage()
@@ -101,7 +138,7 @@ public function openNotificationMenu(string $expectedDescription): void
101138
$menuButton->click();
102139
}
103140

104-
public function clickButton(string $buttonText): void
141+
public function clickActionButton(string $buttonText): void
105142
{
106143
$buttons = $this->getHTMLPage()
107144
->setTimeout(5)
@@ -111,6 +148,16 @@ public function clickButton(string $buttonText): void
111148
$buttons->first()->execute(new MouseOverAndClick());
112149
}
113150

151+
public function clickOnMarkAllAsReadButton(): void
152+
{
153+
$this->getHTMLPage()->setTimeout(5)->find($this->getLocator('markAllAsReadButton'))->click();
154+
}
155+
156+
public function clickViewAllNotificationsButton(): void
157+
{
158+
$this->getHTMLPage()->setTimeout(3)->find($this->getLocator('viewAllNotificationsButton'))->click();
159+
}
160+
114161
public function verifyIsLoaded(): void
115162
{
116163
$this->getHTMLPage()
@@ -130,6 +177,9 @@ protected function specifyLocators(): array
130177
new VisibleCSSLocator('notificationDate', '.ibexa-notifications-modal__item--date'),
131178
new VisibleCSSLocator('notificationMenuButton', '.ibexa-notifications-modal__actions'),
132179
new VisibleCSSLocator('notificationMenuItemContent', '.ibexa-popup-menu__item-content.ibexa-multilevel-popup-menu__item-content'),
180+
new VisibleCSSLocator('notificationCounterDot', '.ibexa-header-user-menu__notice-dot'),
181+
new VisibleCSSLocator('markAllAsReadButton', '.ibexa-notifications-modal__mark-all-read-btn'),
182+
new VisibleCSSLocator('viewAllNotificationsButton', '.ibexa-notifications-modal__view-all-btn'),
133183
];
134184
}
135185
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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\Page;
10+
11+
use Behat\Mink\Session;
12+
use Ibexa\AdminUi\Behat\Component\Dialog;
13+
use Ibexa\AdminUi\Behat\Component\Table\TableBuilder;
14+
use Ibexa\AdminUi\Behat\Component\Table\TableInterface;
15+
use Ibexa\Behat\Browser\Element\Criterion\ChildElementTextCriterion;
16+
use Ibexa\Behat\Browser\Locator\VisibleCSSLocator;
17+
use Ibexa\Behat\Browser\Page\Page;
18+
use Ibexa\Behat\Browser\Routing\Router;
19+
20+
final class NotificationsPage extends Page
21+
{
22+
private TableInterface $table;
23+
24+
/** @var \Ibexa\AdminUi\Behat\Component\Dialog */
25+
private $dialog;
26+
27+
public function __construct(
28+
Session $session,
29+
Router $router,
30+
TableBuilder $tableBuilder,
31+
Dialog $dialog
32+
) {
33+
parent::__construct($session, $router);
34+
35+
$this->table = $tableBuilder->newTable()->build();
36+
$this->dialog = $dialog;
37+
}
38+
39+
public function verifyNotificationIsOnList(string $notificationTitle): void
40+
{
41+
if (!$this->table->hasElement(['Title' => $notificationTitle])) {
42+
throw new \Exception(sprintf('Notification "%s" not found on list.', $notificationTitle));
43+
}
44+
}
45+
46+
public function verifyNotificationIsNotOnList(string $notificationTitle): void
47+
{
48+
if ($this->table->hasElement(['Title' => $notificationTitle])) {
49+
throw new \Exception(sprintf('Notification "%s" is still present on list.', $notificationTitle));
50+
}
51+
}
52+
53+
public function markAsUnread(string $notificationTitle): void
54+
{
55+
$this->getHTMLPage()->setTimeout(5);
56+
$this->table->getTableRow(['Title' => $notificationTitle])->click($this->getLocator('markAsUnreadButton'));
57+
}
58+
59+
public function goToContent(string $notificationTitle): void
60+
{
61+
$this->getHTMLPage()->setTimeout(5);
62+
$this->table->getTableRow(['Title' => $notificationTitle])->click($this->getLocator('goToContentButton'));
63+
}
64+
65+
public function deleteNotification(string $notificationTitle): void
66+
{
67+
$this->table->getTableRow(['Title' => $notificationTitle])->click($this->getLocator('notificationCheckbox'));
68+
69+
$this->getHTMLPage()->setTimeout(3)->find($this->getLocator('deleteButton'))->click();
70+
$this->dialog->verifyIsLoaded();
71+
$this->dialog->confirm();
72+
}
73+
74+
public function getStatusForNotification(string $notificationStatus): string
75+
{
76+
return $this->getHTMLPage()
77+
->findAll($this->getLocator('tableRow'))
78+
->getByCriterion(new ChildElementTextCriterion($this->getLocator('rowName'), $notificationStatus))
79+
->find($this->getLocator('rowStatus'))
80+
->getText();
81+
}
82+
83+
public function verifyIsLoaded(): void
84+
{
85+
$this->getHTMLPage()->setTimeout(5)->find($this->getLocator('pageTitle'))->assert()->textContains('Notifications');
86+
}
87+
88+
public function getName(): string
89+
{
90+
return 'Notifications';
91+
}
92+
93+
protected function getRoute(): string
94+
{
95+
return '/notifications/render/all';
96+
}
97+
98+
protected function specifyLocators(): array
99+
{
100+
return [
101+
new VisibleCSSLocator('pageTitle', '.ibexa-page-title h1'),
102+
new VisibleCSSLocator('tableRow', 'tr'),
103+
new VisibleCSSLocator('rowName', '.ibexa-notification-view-all__details'),
104+
new VisibleCSSLocator('rowStatus', '.ibexa-notification-view-all__status'),
105+
new VisibleCSSLocator('markAsUnreadButton', '[data-original-title="Mark as unread"]'),
106+
new VisibleCSSLocator('goToContentButton', '[data-original-title="Go to content"]'),
107+
new VisibleCSSLocator('deleteButton', '.ibexa-notification-list__btn-delete'),
108+
new VisibleCSSLocator('notificationCheckbox', '.ibexa-notification-list__mark-row-checkbox'),
109+
];
110+
}
111+
}

0 commit comments

Comments
 (0)