86 lines
2 KiB
PHP
86 lines
2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Tests\Browser\Pages;
|
||
|
|
|
||
|
|
use Laravel\Dusk\Browser;
|
||
|
|
|
||
|
|
class DishesPage extends Page
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* Get the URL for the page.
|
||
|
|
*/
|
||
|
|
public function url(): string
|
||
|
|
{
|
||
|
|
return '/dishes';
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Assert that the browser is on the page.
|
||
|
|
*/
|
||
|
|
public function assert(Browser $browser): void
|
||
|
|
{
|
||
|
|
$browser->assertPathIs($this->url())
|
||
|
|
->assertSee('MANAGE DISHES');
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the element shortcuts for the page.
|
||
|
|
*
|
||
|
|
* @return array<string, string>
|
||
|
|
*/
|
||
|
|
public function elements(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'@add-button' => 'button[wire\\:click="create"]',
|
||
|
|
'@dishes-list' => '[wire\\:id]', // Livewire component
|
||
|
|
'@search' => 'input[type="search"]',
|
||
|
|
'@no-dishes' => '*[text*="No dishes found"]',
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Open the create dish modal.
|
||
|
|
*/
|
||
|
|
public function openCreateModal(Browser $browser): void
|
||
|
|
{
|
||
|
|
$browser->waitFor('@add-button')
|
||
|
|
->click('@add-button')
|
||
|
|
->pause(1000);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Click edit button for a dish.
|
||
|
|
*/
|
||
|
|
public function clickEditForDish(Browser $browser, string $dishName): void
|
||
|
|
{
|
||
|
|
$browser->within("tr:contains('{$dishName}')", function ($row) {
|
||
|
|
$row->click('button.bg-accent-blue');
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Click delete button for a dish.
|
||
|
|
*/
|
||
|
|
public function clickDeleteForDish(Browser $browser, string $dishName): void
|
||
|
|
{
|
||
|
|
$browser->within("tr:contains('{$dishName}')", function ($row) {
|
||
|
|
$row->click('button.bg-red-500');
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Assert a dish is visible in the list.
|
||
|
|
*/
|
||
|
|
public function assertDishVisible(Browser $browser, string $dishName): void
|
||
|
|
{
|
||
|
|
$browser->assertSee($dishName);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Assert no dishes message is shown.
|
||
|
|
*/
|
||
|
|
public function assertNoDishes(Browser $browser): void
|
||
|
|
{
|
||
|
|
$browser->assertSee('No dishes found');
|
||
|
|
}
|
||
|
|
}
|