1010
1111use Exception ;
1212use Ibexa \Behat \Browser \Component \Component ;
13+ use Ibexa \Behat \Browser \Element \Action \MouseOverAndClick ;
14+ use Ibexa \Behat \Browser \Element \Condition \ElementExistsCondition ;
15+ use Ibexa \Behat \Browser \Element \Condition \ElementNotExistsCondition ;
16+ use Ibexa \Behat \Browser \Element \Criterion \ChildElementTextCriterion ;
17+ use Ibexa \Behat \Browser \Element \Criterion \ElementTextCriterion ;
18+ use Ibexa \Behat \Browser \Element \ElementInterface ;
1319use Ibexa \Behat \Browser \Locator \VisibleCSSLocator ;
1420
1521class UserNotificationPopup extends Component
@@ -41,6 +47,120 @@ public function clickNotification(string $expectedType, string $expectedDescript
4147 throw new Exception (sprintf ('Notification of type: %s with description: %d not found ' , $ expectedType , $ expectedDescription ));
4248 }
4349
50+ public function verifyNotification (string $ expectedType , string $ expectedAuthor , string $ expectedDescription , ?string $ expectedDate = null , bool $ shouldExist = true ): void
51+ {
52+ $ notifications = $ this ->getHTMLPage ()->setTimeout (5 )->findAll ($ this ->getLocator ('notificationItem ' ));
53+
54+ foreach ($ notifications as $ notification ) {
55+ $ criteria = [
56+ new ChildElementTextCriterion ($ this ->getLocator ('notificationType ' ), $ expectedType ),
57+ new ChildElementTextCriterion ($ this ->getLocator ('notificationDescriptionTitle ' ), $ expectedAuthor ),
58+ new ChildElementTextCriterion ($ this ->getLocator ('notificationDescriptionText ' ), $ expectedDescription ),
59+ ];
60+
61+ if ($ expectedDate !== null && $ expectedDate !== 'XXXX-XX-XX ' ) {
62+ $ criteria [] = new ChildElementTextCriterion ($ this ->getLocator ('notificationDate ' ), $ expectedDate );
63+ }
64+
65+ foreach ($ criteria as $ criterion ) {
66+ if (!$ criterion ->matches ($ notification )) {
67+ continue 2 ;
68+ }
69+ }
70+
71+ if ($ shouldExist ) {
72+ return ;
73+ } else {
74+ throw new \Exception (sprintf (
75+ 'Notification of type "%s" with author "%s" and description "%s" should not exist, but was found. ' ,
76+ $ expectedType ,
77+ $ expectedAuthor ,
78+ $ expectedDescription
79+ ));
80+ }
81+ }
82+
83+ if ($ shouldExist ) {
84+ throw new \Exception (sprintf (
85+ 'Notification of type "%s" with author "%s" and description "%s" was not found. ' ,
86+ $ expectedType ,
87+ $ expectedAuthor ,
88+ $ expectedDescription
89+ ));
90+ }
91+ }
92+
93+ public function openNotificationMenu (string $ expectedDescription ): void
94+ {
95+ $ this ->getHTMLPage ()->setTimeout (5 )->findAll ($ this ->getLocator ('notificationItem ' ))
96+ ->filterBy (new ChildElementTextCriterion ($ this ->getLocator ('notificationDescriptionText ' ), $ expectedDescription ))
97+ ->first ()->find ($ this ->getLocator ('notificationMenuButton ' ))->click ();
98+
99+ $ this ->getHTMLPage ()
100+ ->setTimeout (10 )
101+ ->waitUntilCondition (
102+ new ElementExistsCondition (
103+ $ this ->getHTMLPage (),
104+ $ this ->getLocator ('notificationActionsPopup ' ),
105+ )
106+ );
107+ }
108+
109+ public function clickActionButton (string $ buttonText ): void
110+ {
111+ $ this ->getHTMLPage ()
112+ ->setTimeout (10 )
113+ ->findAll ($ this ->getLocator ('notificationMenuItemContent ' ))
114+ ->filterBy (new ElementTextCriterion ($ buttonText ))->first ()->execute (new MouseOverAndClick ());
115+
116+ $ this ->getHTMLPage ()
117+ ->setTimeout (10 )
118+ ->waitUntilCondition (
119+ new ElementNotExistsCondition (
120+ $ this ->getHTMLPage (),
121+ $ this ->getLocator ('notificationActionsPopup ' )
122+ )
123+ );
124+ }
125+
126+ public function findActionButton (string $ buttonText ): ?ElementInterface
127+ {
128+ $ this ->getHTMLPage ()
129+ ->setTimeout (10 )
130+ ->waitUntilCondition (
131+ new ElementExistsCondition (
132+ $ this ->getHTMLPage (),
133+ $ this ->getLocator ('notificationMenuItemContent ' )
134+ )
135+ );
136+
137+ return $ this ->getHTMLPage ()
138+ ->setTimeout (10 )
139+ ->findAll ($ this ->getLocator ('notificationMenuItemContent ' ))
140+ ->filterBy (new ElementTextCriterion ($ buttonText ))
141+ ->first ();
142+ }
143+
144+ public function assertEmptyStateVisible (): void
145+ {
146+ $ this ->getHTMLPage ()->setTimeout (5 )->find ($ this ->getLocator ('notificationsEmptyText ' ))->assert ()->isVisible ();
147+ }
148+
149+ public function clickOnMarkAllAsReadButton (): void
150+ {
151+ $ this ->getHTMLPage ()->setTimeout (5 )->find ($ this ->getLocator ('markAllAsReadButton ' ))->click ();
152+ }
153+
154+ public function clickViewAllNotificationsButton (): void
155+ {
156+ $ this ->getHTMLPage ()->setTimeout (3 )->find ($ this ->getLocator ('viewAllNotificationsButton ' ))->click ();
157+ }
158+
159+ public function verifyNotificationsCount (int $ expectedCount ): void
160+ {
161+ $ this ->getHTMLPage ()->setTimeout (10 )->find ($ this ->getLocator ('notificationsCount ' ))->assert ()->textEquals ('( ' . $ expectedCount . ') ' );
162+ }
163+
44164 public function verifyIsLoaded (): void
45165 {
46166 $ this ->getHTMLPage ()
@@ -57,6 +177,14 @@ protected function specifyLocators(): array
57177 new VisibleCSSLocator ('notificationType ' , '.ibexa-notifications-modal__type-content .type__text ' ),
58178 new VisibleCSSLocator ('notificationDescriptionTitle ' , '.ibexa-notifications-modal__description .description__title ' ),
59179 new VisibleCSSLocator ('notificationDescriptionText ' , '.ibexa-notifications-modal__type-content .description__text ' ),
180+ new VisibleCSSLocator ('notificationDate ' , '.ibexa-notifications-modal__item--date ' ),
181+ new VisibleCSSLocator ('notificationMenuButton ' , '.ibexa-notifications-modal__actions ' ),
182+ new VisibleCSSLocator ('notificationMenuItemContent ' , '.ibexa-popup-menu__item-content.ibexa-multilevel-popup-menu__item-content ' ),
183+ new VisibleCSSLocator ('markAllAsReadButton ' , '.ibexa-notifications-modal__mark-all-read-btn ' ),
184+ new VisibleCSSLocator ('viewAllNotificationsButton ' , '.ibexa-notifications-modal__view-all-btn ' ),
185+ new VisibleCSSLocator ('notificationActionsPopup ' , '.ibexa-notification-actions-popup-menu:not(.ibexa-popup-menu--hidden) ' ),
186+ new VisibleCSSLocator ('notificationsEmptyText ' , '.ibexa-notifications-modal__empty-text ' ),
187+ new VisibleCSSLocator ('notificationsCount ' , '.ibexa-notifications-modal__count ' ),
60188 ];
61189 }
62190}
0 commit comments