Merge pull request #11301 from creative-commoners/pulls/5/toasts-behat

MNT Support assert toasts if there are mutliple toasts
This commit is contained in:
Guy Sartorelli 2024-07-12 11:44:13 +12:00 committed by GitHub
commit 68d8cfcd4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -105,7 +105,20 @@ class CmsUiContext implements Context
// no-op - if the element doesn't exist at all, then that passes the test.
}
} else {
$this->getMainContext()->assertElementContains('.toast--' . $type, $notice);
$page = $this->getSession()->getPage();
$container = $page->find('css', '.toasts');
if (!$container) {
Assert::assertNull('Not found', 'No toast container found');
return;
}
foreach ($container->findAll('css', '.toast--' . $type) as $toast) {
$text = $toast->getText();
if (str_contains($text, $notice)) {
Assert::assertStringContainsString($notice, $text);
return;
}
}
Assert::assertNull('Not found', 'No toast container found with text: ' . $notice);
}
}