44
55namespace Tests \Webgriffe \SyliusBackInStockNotificationPlugin \Behat \Element \Product \ShowPage ;
66
7+ use Behat \Mink \Session ;
78use FriendsOfBehat \PageObjectExtension \Element \Element ;
9+ use Sylius \Behat \Page \Shop \Product \ShowPageInterface ;
10+ use Sylius \Behat \Service \DriverHelper ;
11+ use Sylius \Behat \Service \JQueryHelper ;
812
913final class SubscriptionFormElement extends Element implements SubscriptionFormElementInterface
1014{
15+ /**
16+ * @param mixed[]|\ArrayAccess<array-key, mixed> $minkParameters
17+ */
18+ public function __construct (
19+ Session $ session ,
20+ $ minkParameters ,
21+ private ShowPageInterface $ productPage ,
22+ ) {
23+ parent ::__construct ($ session , $ minkParameters );
24+ }
25+
1126 public function submitFormAsAGuest (string $ variant , string $ email ): void
1227 {
1328 $ this ->getElement ('add_email ' )->setValue ($ email );
14- $ this ->getElement ('submit_form ' )->click ();
29+ $ this ->getElement ('submit_form ' )->submit ();
30+
31+ $ this ->waitForProductPageRefresh ();
1532 }
1633
1734 public function submitFormAsALoggedCustomer (string $ variant ): void
1835 {
19- $ this ->getElement ('submit_form ' )->click ();
36+ $ this ->getElement ('submit_form ' )->submit ();
37+
38+ $ this ->waitForProductPageRefresh ();
2039 }
2140
2241 public function openOverlayForConfigurableProduct (): void
@@ -32,4 +51,12 @@ protected function getDefinedElements(): array
3251 'submit_form ' => '[data-test-subscribe-to-notifications] ' ,
3352 ]);
3453 }
54+
55+ private function waitForProductPageRefresh (): void
56+ {
57+ if (DriverHelper::isJavascript ($ this ->getDriver ())) {
58+ JQueryHelper::waitForAsynchronousActionsToFinish ($ this ->getSession ());
59+ $ this ->getDocument ()->waitFor (3 , fn (): bool => $ this ->productPage ->isOpen ());
60+ }
61+ }
3562}
0 commit comments