Skip to content

Commit

Permalink
bug #14301 [Behat][Fix] Check notification expectation in JavaScriptT…
Browse files Browse the repository at this point in the history
…estHelper (Rafikooo)

This PR was merged into the 1.11 branch.

Discussion
----------

| Q               | A                                                            |
|-----------------|--------------------------------------------------------------|
| Branch?         | 1.11 <!-- see the comment below -->                  |
| Bug fix?        | yes                                                       |
| New feature?    | no                                                       |
| BC breaks?      | no                                                       |
| Deprecations?   | no <!-- don't forget to update the UPGRADE-*.md file --> |
| License         | MIT                                                          |

Fixes:
<img width="853" alt="image" src="https://user-images.githubusercontent.com/40125720/190143519-a8030a24-3fa5-4075-8fe2-ab74c0c0409a.png">

Before:
<img width="714" alt="image" src="https://user-images.githubusercontent.com/40125720/190143668-e7ebd093-623c-48cc-8cbd-d55d0365bd87.png">

After:
<img width="1431" alt="image" src="https://user-images.githubusercontent.com/40125720/190143782-b4e07141-61f7-4e07-95a4-6bfe9fd6c041.png">



Mentioned here: #14291 (comment)

Commits
-------

4769726 [Behat][Fix] Check notification expectation in JavaScriptTestHelper
  • Loading branch information
GSadee committed Sep 15, 2022
2 parents 4b6706c + 4769726 commit dce55b8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/Sylius/Behat/Context/Ui/Admin/NotificationContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ public function iShouldBeNotifiedThatItHasBeenSuccessfullyEdited(): void
}

/**
* @Then I should be notified that it has been successfully deleted
* @Then I should be notified that they have been successfully deleted
* @Then I should be notified that it :has been successfully deleted
* @Then I should be notified that they :have been successfully deleted
*/
public function iShouldBeNotifiedThatItHasBeenSuccessfullyDeleted(): void
public function iShouldBeNotifiedThatItHasBeenSuccessfullyDeleted(string $hasHave): void
{
$this->testHelper->waitUntilNotificationPopups(
$this->notificationChecker,
NotificationType::success(),
'has been successfully deleted.',
sprintf('%s been successfully deleted.', $hasHave),
);
}

Expand Down
17 changes: 15 additions & 2 deletions src/Sylius/Behat/Service/Helper/JavaScriptTestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Behat\Mink\Exception\ElementNotFoundException;
use FriendsOfBehat\PageObjectExtension\Page\PageInterface;
use FriendsOfBehat\PageObjectExtension\Page\UnexpectedPageException;
use Sylius\Behat\Exception\NotificationExpectationMismatchException;
use Sylius\Behat\NotificationType;
use Sylius\Behat\Service\NotificationCheckerInterface;

Expand All @@ -42,7 +43,12 @@ public function waitUntilNotificationPopups(
$notificationChecker->checkNotification($message, $type);
};

$this->waitUntilExceptionDisappears($callable, ElementNotFoundException::class, $timeout);
$this->waitUntilExceptionDisappears(
$callable,
ElementNotFoundException::class,
$timeout,
$type,
);
}

public function waitUntilPageOpens(PageInterface $page, ?array $options = [], ?int $timeout = null): void
Expand All @@ -54,7 +60,12 @@ public function waitUntilPageOpens(PageInterface $page, ?array $options = [], ?i
$this->waitUntilExceptionDisappears($callable, UnexpectedPageException::class, $timeout);
}

private function waitUntilExceptionDisappears(callable $callable, string $exceptionClass, ?int $timeout = null): void
private function waitUntilExceptionDisappears(
callable $callable,
string $exceptionClass,
?int $timeout = null,
NotificationType $type = null,
): void
{
$start = microtime(true);
$timeout ??= $this->defaultTimeout;
Expand All @@ -63,6 +74,8 @@ private function waitUntilExceptionDisappears(callable $callable, string $except
do {
try {
$callable();
} catch (NotificationExpectationMismatchException $exception) {
throw new NotificationExpectationMismatchException($type, $exception->getMessage());
} catch (\Exception $exception) {
if ($exception instanceof $exceptionClass) {
usleep($this->microsecondsInterval);
Expand Down

0 comments on commit dce55b8

Please sign in to comment.