Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/Components/ListInput.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 ListInput extends BaseComponent | class ListInput extends BaseComponent | ||||
{ | { | ||||
protected $selector; | protected $selector; | ||||
Show All 10 Lines | class ListInput extends BaseComponent | ||||
public function selector() | public function selector() | ||||
{ | { | ||||
return $this->selector . ' + .listinput-widget'; | return $this->selector . ' + .listinput-widget'; | ||||
} | } | ||||
/** | /** | ||||
* Assert that the browser page contains the component. | * Assert that the browser page contains the component. | ||||
* | * | ||||
* @param Browser $browser | * @param \Laravel\Dusk\Browser $browser | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function assert(Browser $browser) | public function assert($browser) | ||||
{ | { | ||||
// $list = explode("\n", $browser->value($this->selector)); | // $list = explode("\n", $browser->value($this->selector)); | ||||
$browser->waitFor($this->selector()) | $browser->waitFor($this->selector()) | ||||
->assertMissing($this->selector) | ->assertMissing($this->selector) | ||||
->assertVisible('@input') | ->assertVisible('@input') | ||||
->assertVisible('@add-btn'); | ->assertVisible('@add-btn'); | ||||
// ->assertListInputValue($list); | // ->assertListInputValue($list); | ||||
Show All 10 Lines | public function elements() | ||||
'@input' => '.input-group:first-child input', | '@input' => '.input-group:first-child input', | ||||
'@add-btn' => '.input-group:first-child a.btn', | '@add-btn' => '.input-group:first-child a.btn', | ||||
]; | ]; | ||||
} | } | ||||
/** | /** | ||||
* Assert list input content | * Assert list input content | ||||
*/ | */ | ||||
public function assertListInputValue(Browser $browser, array $list) | public function assertListInputValue($browser, array $list) | ||||
{ | { | ||||
if (empty($list)) { | if (empty($list)) { | ||||
$browser->assertMissing('.input-group:not(:first-child)'); | $browser->assertMissing('.input-group:not(:first-child)'); | ||||
return; | return; | ||||
} | } | ||||
foreach ($list as $idx => $value) { | foreach ($list as $idx => $value) { | ||||
$selector = '.input-group:nth-child(' . ($idx + 2) . ') input'; | $selector = '.input-group:nth-child(' . ($idx + 2) . ') input'; | ||||
$browser->assertVisible($selector)->assertValue($selector, $value); | $browser->assertVisible($selector)->assertValue($selector, $value); | ||||
} | } | ||||
} | } | ||||
/** | /** | ||||
* Add list entry | * Add list entry | ||||
*/ | */ | ||||
public function addListEntry(Browser $browser, string $value) | public function addListEntry($browser, string $value) | ||||
{ | { | ||||
$browser->type('@input', $value) | $browser->type('@input', $value) | ||||
->click('@add-btn') | ->click('@add-btn') | ||||
->assertValue('.input-group:last-child input', $value); | ->assertValue('.input-group:last-child input', $value); | ||||
} | } | ||||
/** | /** | ||||
* Remove list entry | * Remove list entry | ||||
*/ | */ | ||||
public function removeListEntry(Browser $browser, int $num) | public function removeListEntry($browser, int $num) | ||||
{ | { | ||||
$selector = '.input-group:nth-child(' . ($num + 1) . ') a.btn'; | $selector = '.input-group:nth-child(' . ($num + 1) . ') a.btn'; | ||||
$browser->click($selector)->assertMissing($selector); | $browser->click($selector)->assertMissing($selector); | ||||
} | } | ||||
/** | /** | ||||
* Assert an error message on the widget | * Assert an error message on the widget | ||||
*/ | */ | ||||
public function assertFormError(Browser $browser, int $num, string $msg, bool $focused = false) | public function assertFormError($browser, int $num, string $msg, bool $focused = false) | ||||
{ | { | ||||
$selector = '.input-group:nth-child(' . ($num + 1) . ') input.is-invalid'; | $selector = '.input-group:nth-child(' . ($num + 1) . ') input.is-invalid'; | ||||
$browser->assertVisible($selector) | $browser->assertVisible($selector) | ||||
->assertSeeIn(' + .invalid-feedback', $msg); | ->assertSeeIn(' + .invalid-feedback', $msg); | ||||
if ($focused) { | if ($focused) { | ||||
$browser->assertFocused($selector); | $browser->assertFocused($selector); | ||||
} | } | ||||
} | } | ||||
} | } |