Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/Components/Toast.php
<?php | <?php | ||||
namespace Tests\Browser\Components; | namespace Tests\Browser\Components; | ||||
use Facebook\WebDriver\WebDriverBy; | |||||
use Laravel\Dusk\Component as BaseComponent; | use Laravel\Dusk\Component as BaseComponent; | ||||
use PHPUnit\Framework\Assert as PHPUnit; | use PHPUnit\Framework\Assert as PHPUnit; | ||||
class Toast extends BaseComponent | class Toast extends BaseComponent | ||||
{ | { | ||||
public const TYPE_ERROR = 'error'; | public const TYPE_ERROR = 'error'; | ||||
public const TYPE_SUCCESS = 'success'; | public const TYPE_SUCCESS = 'success'; | ||||
public const TYPE_WARNING = 'warning'; | public const TYPE_WARNING = 'warning'; | ||||
Show All 34 Lines | class Toast extends BaseComponent | ||||
/** | /** | ||||
* Get the element shortcuts for the component. | * Get the element shortcuts for the component. | ||||
* | * | ||||
* @return array | * @return array | ||||
*/ | */ | ||||
public function elements() | public function elements() | ||||
{ | { | ||||
return [ | return [ | ||||
'@title' => ".toast-title", | '@title' => ".toast-header > strong", | ||||
'@message' => ".toast-message", | '@message' => ".toast-body", | ||||
]; | ]; | ||||
} | } | ||||
/** | /** | ||||
* Assert title of the toast element | * Assert title of the toast element | ||||
*/ | */ | ||||
public function assertToastTitle($browser, string $title) | public function assertToastTitle($browser, string $title = null) | ||||
{ | { | ||||
if (empty($title)) { | if (empty($title)) { | ||||
$browser->assertMissing('@title'); | switch ($this->type) { | ||||
} else { | case self::TYPE_ERROR: | ||||
$browser->assertSeeIn('@title', $title); | $title = 'Error'; | ||||
break; | |||||
case self::TYPE_SUCCESS: | |||||
$title = 'Success'; | |||||
break; | |||||
case self::TYPE_WARNING: | |||||
$title = 'Warning'; | |||||
break; | |||||
case self::TYPE_INFO: | |||||
$title = 'Information'; | |||||
break; | |||||
} | |||||
} | } | ||||
$browser->assertSeeIn('@title', $title); | |||||
} | } | ||||
/** | /** | ||||
* Assert message of the toast element | * Assert message of the toast element | ||||
*/ | */ | ||||
public function assertToastMessage($browser, string $message) | public function assertToastMessage($browser, string $message) | ||||
{ | { | ||||
$browser->assertSeeIn('@message', $message); | $browser->assertSeeIn('@message', $message); | ||||
} | } | ||||
/** | /** | ||||
* Close the toast with a click | * Close the toast with a click | ||||
*/ | */ | ||||
public function closeToast($browser) | public function closeToast($browser) | ||||
{ | { | ||||
$this->element->click(); | $this->element->findElements(WebDriverBy::cssSelector('button.close'))[0]->click(); | ||||
} | } | ||||
} | } |