1010
1111use Exception ;
1212use 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 ;
1316use Ibexa \Behat \Browser \Locator \VisibleCSSLocator ;
1417
1518class 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