Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Browser/Components/Menu.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 Menu extends BaseComponent | class Menu extends BaseComponent | ||||
{ | { | ||||
/** | /** | ||||
* Get the root selector for the component. | * Get the root selector for the component. | ||||
* | * | ||||
* @return string | * @return string | ||||
*/ | */ | ||||
public function selector() | public function selector() | ||||
{ | { | ||||
return '#primary-menu'; | return '#primary-menu'; | ||||
} | } | ||||
/** | /** | ||||
* 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) | ||||
{ | { | ||||
$browser->assertVisible($this->selector()); | $browser->assertVisible($this->selector()); | ||||
$browser->assertVisible('@brand'); | $browser->assertVisible('@brand'); | ||||
} | } | ||||
/** | /** | ||||
* Assert that menu contains only specified menu items. | * Assert that menu contains only specified menu items. | ||||
* | * | ||||
* @param Browser $browser | * @param \Laravel\Dusk\Browser $browser | ||||
* @param array $items List of menu items | * @param array $items List of menu items | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function assertMenuItems(Browser $browser, array $items) | public function assertMenuItems($browser, array $items) | ||||
{ | { | ||||
// TODO: On mobile the links will not be visible | // TODO: On mobile the links will not be visible | ||||
foreach ($items as $item) { | foreach ($items as $item) { | ||||
$browser->assertVisible('.link-' . $item); | $browser->assertVisible('.link-' . $item); | ||||
} | } | ||||
// Check number of items, to make sure there's no extra items | // Check number of items, to make sure there's no extra items | ||||
PHPUnit::assertCount(count($items), $browser->elements('li')); | PHPUnit::assertCount(count($items), $browser->elements('li')); | ||||
} | } | ||||
/** | /** | ||||
* Assert that specified menu item is active | * Assert that specified menu item is active | ||||
* | * | ||||
* @param Browser $browser | * @param \Laravel\Dusk\Browser $browser | ||||
* @param string $item Menu item name | * @param string $item Menu item name | ||||
* | * | ||||
* @return void | * @return void | ||||
*/ | */ | ||||
public function assertActiveItem(Browser $browser, string $item) | public function assertActiveItem($browser, string $item) | ||||
{ | { | ||||
// TODO: On mobile the links will not be visible | // TODO: On mobile the links will not be visible | ||||
$browser->assertVisible(".link-{$item}.active"); | $browser->assertVisible(".link-{$item}.active"); | ||||
} | } | ||||
/** | /** | ||||
* Get the element shortcuts for the component. | * Get the element shortcuts for the component. | ||||
Show All 14 Lines |