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 Laravel\Dusk\Browser; | |||||
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 16 Lines | class Toast extends BaseComponent | ||||
public function selector() | public function selector() | ||||
{ | { | ||||
return '.toast-container > .toast.toast-' . $this->type; | return '.toast-container > .toast.toast-' . $this->type; | ||||
} | } | ||||
/** | /** | ||||
* Assert that the browser page contains the component. | * Assert that the browser page contains the component. | ||||
* | * | ||||
* @param Browser $browser | * @param \Laravel\Dusk\Browser $browser The browser object | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function assert(Browser $browser) | public function assert($browser) | ||||
{ | { | ||||
$browser->waitFor($this->selector()); | $browser->waitFor($this->selector()); | ||||
$this->element = $browser->element($this->selector()); | $this->element = $browser->element($this->selector()); | ||||
} | } | ||||
/** | /** | ||||
* 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-title", | ||||
'@message' => ".toast-message", | '@message' => ".toast-message", | ||||
]; | ]; | ||||
} | } | ||||
/** | /** | ||||
* Assert title of the toast element | * Assert title of the toast element | ||||
*/ | */ | ||||
public function assertToastTitle(Browser $browser, string $title) | public function assertToastTitle($browser, string $title) | ||||
{ | { | ||||
if (empty($title)) { | if (empty($title)) { | ||||
$browser->assertMissing('@title'); | $browser->assertMissing('@title'); | ||||
} else { | } else { | ||||
$browser->assertSeeIn('@title', $title); | $browser->assertSeeIn('@title', $title); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Assert message of the toast element | * Assert message of the toast element | ||||
*/ | */ | ||||
public function assertToastMessage(Browser $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 $browser) | public function closeToast($browser) | ||||
{ | { | ||||
$this->element->click(); | $this->element->click(); | ||||
} | } | ||||
} | } |