Skip to content

Commit 71896ee

Browse files
KamilSznajdrowicztomaszszopinski
authored andcommitted
Add count step to scenarios
1 parent 97d70d4 commit 71896ee

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

src/lib/Behat/BrowserContext/UserNotificationContext.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,20 @@ public function iShouldSeeTextInAllNotificationsView(string $expectedMessage): v
164164
{
165165
$this->notificationsViewAllPage->verifyNoNotificationsMessage($expectedMessage);
166166
}
167+
168+
/**
169+
* @Then there should be :expectedCount notification on the list
170+
*/
171+
public function thereShouldBeNotificationsInPopup(int $expectedCount): void
172+
{
173+
$this->userNotificationPopup->verifyNotificationsCount($expectedCount);
174+
}
175+
176+
/**
177+
* @Then there should be :expectedCount notification in the All Notifications view
178+
*/
179+
public function thereShouldBeNotificationsInAllNotificationsView(int $expectedCount): void
180+
{
181+
$this->notificationsViewAllPage->verifyNotificationsCount($expectedCount);
182+
}
167183
}

src/lib/Behat/Component/UserNotificationPopup.php

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use Exception;
1212
use Ibexa\Behat\Browser\Component\Component;
13+
use Ibexa\Behat\Browser\Element\Action\MouseOverAndClick;
1314
use Ibexa\Behat\Browser\Element\Condition\ElementExistsCondition;
1415
use Ibexa\Behat\Browser\Element\Condition\ElementNotExistsCondition;
1516
use Ibexa\Behat\Browser\Element\Criterion\ChildElementTextCriterion;
@@ -114,26 +115,16 @@ public function openNotificationMenu(string $expectedDescription): void
114115
$this->getLocator('notificationActionsPopup'),
115116
)
116117
);
117-
118-
$this->getHTMLPage()
119-
->setTimeout(10)
120-
->waitUntilCondition(
121-
new ElementExistsCondition(
122-
$this->getHTMLPage(),
123-
$this->getLocator('notificationMenuItemContent')
124-
)
125-
);
126118
}
127119

128120
public function clickActionButton(string $buttonText): void
129121
{
130-
$button = $this->getActionButton($buttonText);
131-
132-
if ($button === null) {
133-
throw new \Exception(sprintf('Action button "%s" not found.', $buttonText));
134-
}
122+
$buttons = $this->getHTMLPage()
123+
->setTimeout(10)
124+
->findAll($this->getLocator('notificationMenuItemContent'))
125+
->filterBy(new ElementTextCriterion($buttonText));
135126

136-
$button->click();
127+
$buttons->first()->execute(new MouseOverAndClick());
137128

138129
$this->getHTMLPage()
139130
->setTimeout(10)
@@ -185,6 +176,11 @@ public function clickViewAllNotificationsButton(): void
185176
$this->getHTMLPage()->setTimeout(3)->find($this->getLocator('viewAllNotificationsButton'))->click();
186177
}
187178

179+
public function verifyNotificationsCount(int $expectedCount): void
180+
{
181+
$this->getHTMLPage()->setTimeout(10)->find($this->getLocator('notificationsCount'))->assert()->textEquals('(' . $expectedCount . ')');
182+
}
183+
188184
public function verifyIsLoaded(): void
189185
{
190186
$this->getHTMLPage()
@@ -208,6 +204,7 @@ protected function specifyLocators(): array
208204
new VisibleCSSLocator('viewAllNotificationsButton', '.ibexa-notifications-modal__view-all-btn'),
209205
new VisibleCSSLocator('notificationActionsPopup', '.ibexa-notification-actions-popup-menu:not(.ibexa-popup-menu--hidden)'),
210206
new VisibleCSSLocator('notificationsEmptyText', '.ibexa-notifications-modal__empty-text'),
207+
new VisibleCSSLocator('notificationsCount', '.ibexa-notifications-modal__count'),
211208
];
212209
}
213210
}

src/lib/Behat/Page/NotificationsViewAllPage.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Ibexa\AdminUi\Behat\Component\Table\TableInterface;
1616
use Ibexa\Behat\Browser\Element\Condition\ElementExistsCondition;
1717
use Ibexa\Behat\Browser\Element\Criterion\ChildElementTextCriterion;
18+
use Ibexa\Behat\Browser\Element\Criterion\ElementAttributeCriterion;
1819
use Ibexa\Behat\Browser\Locator\VisibleCSSLocator;
1920
use Ibexa\Behat\Browser\Page\Page;
2021
use Ibexa\Behat\Browser\Routing\Router;
@@ -84,6 +85,12 @@ public function verifyNoNotificationsMessage(string $expectedMessage): void
8485
$this->getHTMLPage()->find($this->getLocator('notificationsEmptyText'))->assert()->textEquals($expectedMessage);
8586
}
8687

88+
public function verifyNotificationsCount(int $expectedCount): void
89+
{
90+
$this->getHTMLPage()->setTimeout(10)->findAll($this->getLocator('notificationsTotalCount'))
91+
->getByCriterion(new ElementAttributeCriterion('data-notifications-total', (string)$expectedCount))->assert()->isVisible();
92+
}
93+
8794
public function verifyIsLoaded(): void
8895
{
8996
$this->getHTMLPage()->setTimeout(5)->find($this->getLocator('pageTitle'))->assert()->textContains('Notifications');
@@ -111,6 +118,7 @@ protected function specifyLocators(): array
111118
new VisibleCSSLocator('deleteButton', '.ibexa-notification-list__btn-delete'),
112119
new VisibleCSSLocator('notificationCheckbox', '.ibexa-notification-list__mark-row-checkbox'),
113120
new VisibleCSSLocator('notificationsEmptyText', '.ibexa-table__empty-table-info-text'),
121+
new VisibleCSSLocator('notificationsTotalCount', 'table[data-notifications-total]'),
114122
];
115123
}
116124
}

0 commit comments

Comments
 (0)