Skip to content

Commit

Permalink
API Add new behat method for interacting with toasts (#9695)
Browse files Browse the repository at this point in the history
  • Loading branch information
maxime-rainville committed Sep 17, 2020
1 parent 0746230 commit ff18dec
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion tests/behat/src/CmsUiContext.php
Expand Up @@ -77,10 +77,49 @@ public function iShouldSeeTheCms()

/**
* @Then /^I should see a "([^"]*)" notice$/
* @deprecated 4.7.0 Use `iShouldSeeAToast` instead
*/
public function iShouldSeeANotice($notice)
{
$this->getMainContext()->assertElementContains('.notice-wrap', $notice);
$this->getMainContext()->assertElementContains('.toast, .notice-wrap', $notice);
}

/**
* @Then /^I should see a "([^"]+)" (\w+) toast$/
*/
public function iShouldSeeAToast($notice, $type)
{
$this->getMainContext()->assertElementContains('.toast--' . $type, $notice);
}

/**
* @Then /^I should see a "([^"]+)" (\w+) toast with these actions: (.+)$/
*/
public function iShouldSeeAToastWithAction($notice, $type, $actions)
{
$this->iShouldSeeAToast($notice, $type);

$actions = explode(',', $actions);
foreach ($actions as $order => $action) {
$this->getMainContext()->assertElementContains(
sprintf('.toast--%s .toast__action:nth-child(%s)', $type, $order+1),
trim($action)
);
}
}

/**
* @param $action
* @When /^I click the "([^"]*)" toast action$/
*/
public function stepIClickTheToastAction($action)
{
$page = $this->getMainContext()->getSession()->getPage();
$toasts = $page->find('css', '.toasts');
assertNotNull($toasts, "We have a toast container");
$toastAction = $toasts->find('named', ['link_or_button', "'{$action}'"]);
assertNotNull($toastAction, "We have a $action toast action");
$toastAction->click();
}

/**
Expand Down

0 comments on commit ff18dec

Please sign in to comment.