Skip to content

Commit a0ce797

Browse files
Add notification config
1 parent c595861 commit a0ce797

File tree

2 files changed

+117
-0
lines changed

2 files changed

+117
-0
lines changed

src/lib/Behat/BrowserContext/UserNotificationContext.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,48 @@ public function iGoToUserNotificationWithDetails(TableNode $notificationDetails)
4747
$this->userNotificationPopup->verifyIsLoaded();
4848
$this->userNotificationPopup->clickNotification($type, $description);
4949
}
50+
51+
/**
52+
* @Then an unread notification appears with details:
53+
*/
54+
public function thereIsUnreadNotificationAppearsWithDetails(TableNode $notificationDetails): void
55+
{
56+
$type = $notificationDetails->getHash()[0]['Type'];
57+
$author = $notificationDetails->getHash()[0]['Author'];
58+
$description = $notificationDetails->getHash()[0]['Description'];
59+
$date = $notificationDetails->getHash()[0]['Date'];
60+
61+
$this->userNotificationPopup->verifyIsLoaded();
62+
$this->userNotificationPopup->verifyNotification($type, $author, $description, $date, true);
63+
}
64+
65+
/**
66+
* @Then no notification appears with details:
67+
*/
68+
public function noNotificationAppearsWithDetails(TableNode $notificationDetails): void
69+
{
70+
$type = $notificationDetails->getHash()[0]['Type'];
71+
$author = $notificationDetails->getHash()[0]['Author'];
72+
$description = $notificationDetails->getHash()[0]['Description'];
73+
$date = $notificationDetails->getHash()[0]['Date'];
74+
75+
$this->userNotificationPopup->verifyIsLoaded();
76+
$this->userNotificationPopup->verifyNotification($type, $author, $description, $date, false);
77+
}
78+
79+
/**
80+
* @When I open notification menu with description :description
81+
*/
82+
public function iOpenNotificationMenuNotification(string $description): void
83+
{
84+
$this->userNotificationPopup->openNotificationMenu($description);
85+
}
86+
87+
/**
88+
* @When I click :action action
89+
*/
90+
public function iDeleteTheNotification(): void
91+
{
92+
$this->userNotificationPopup->clickButton('Delete');
93+
}
5094
}

src/lib/Behat/Component/UserNotificationPopup.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
use Exception;
1212
use Ibexa\Behat\Browser\Component\Component;
13+
use Ibexa\Behat\Browser\Element\Action\MouseOverAndClick;
14+
use Ibexa\Behat\Browser\Element\Criterion\ChildElementTextCriterion;
15+
use Ibexa\Behat\Browser\Element\Criterion\ElementTextCriterion;
1316
use Ibexa\Behat\Browser\Locator\VisibleCSSLocator;
1417

1518
class UserNotificationPopup extends Component
@@ -41,6 +44,73 @@ public function clickNotification(string $expectedType, string $expectedDescript
4144
throw new Exception(sprintf('Notification of type: %s with description: %d not found', $expectedType, $expectedDescription));
4245
}
4346

47+
public function verifyNotification(string $expectedType, string $expectedAuthor, string $expectedDescription, ?string $expectedDate = null, bool $shouldExist = true): void
48+
{
49+
$notifications = $this->getHTMLPage()->setTimeout(3)->findAll($this->getLocator('notificationItem'));
50+
51+
foreach ($notifications as $notification) {
52+
$criteria = [
53+
new ChildElementTextCriterion($this->getLocator('notificationType'), $expectedType),
54+
new ChildElementTextCriterion($this->getLocator('notificationDescriptionTitle'), $expectedAuthor),
55+
new ChildElementTextCriterion($this->getLocator('notificationDescriptionText'), $expectedDescription),
56+
];
57+
58+
if ($expectedDate !== null && $expectedDate !== 'XXXX-XX-XX') {
59+
$criteria[] = new ChildElementTextCriterion($this->getLocator('notificationDate'), $expectedDate);
60+
}
61+
62+
foreach ($criteria as $criterion) {
63+
if (!$criterion->matches($notification)) {
64+
continue 2; // go to next notification
65+
}
66+
}
67+
68+
if ($shouldExist) {
69+
return; // matching notification found
70+
} else {
71+
throw new \Exception(sprintf(
72+
'Notification of type "%s" with author "%s" and description "%s" should not exist, but was found.',
73+
$expectedType,
74+
$expectedAuthor,
75+
$expectedDescription
76+
));
77+
}
78+
}
79+
80+
if ($shouldExist) {
81+
throw new \Exception(sprintf(
82+
'Notification of type "%s" with author "%s" and description "%s" was not found.',
83+
$expectedType,
84+
$expectedAuthor,
85+
$expectedDescription
86+
));
87+
}
88+
}
89+
90+
public function openNotificationMenu(string $expectedDescription): void
91+
{
92+
$notifications = $this->getHTMLPage()
93+
->setTimeout(5)
94+
->findAll($this->getLocator('notificationItem'))
95+
->filterBy(new ChildElementTextCriterion(
96+
$this->getLocator('notificationDescriptionText'),
97+
$expectedDescription
98+
));
99+
100+
$menuButton = $notifications->first()->find($this->getLocator('notificationMenuButton'));
101+
$menuButton->click();
102+
}
103+
104+
public function clickButton(string $buttonText): void
105+
{
106+
$buttons = $this->getHTMLPage()
107+
->setTimeout(5)
108+
->findAll($this->getLocator('notificationMenuItemContent'))
109+
->filterBy(new ElementTextCriterion($buttonText));
110+
111+
$buttons->first()->execute(new MouseOverAndClick());
112+
}
113+
44114
public function verifyIsLoaded(): void
45115
{
46116
$this->getHTMLPage()
@@ -57,6 +127,9 @@ protected function specifyLocators(): array
57127
new VisibleCSSLocator('notificationType', '.ibexa-notifications-modal__type-content .type__text'),
58128
new VisibleCSSLocator('notificationDescriptionTitle', '.ibexa-notifications-modal__description .description__title'),
59129
new VisibleCSSLocator('notificationDescriptionText', '.ibexa-notifications-modal__type-content .description__text'),
130+
new VisibleCSSLocator('notificationDate', '.ibexa-notifications-modal__item--date'),
131+
new VisibleCSSLocator('notificationMenuButton', '.ibexa-notifications-modal__actions'),
132+
new VisibleCSSLocator('notificationMenuItemContent', '.ibexa-popup-menu__item-content.ibexa-multilevel-popup-menu__item-content'),
60133
];
61134
}
62135
}

0 commit comments

Comments
 (0)