66 lines
2.5 KiB
PHP
66 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Browser;
|
|
|
|
use Laravel\Dusk\Browser;
|
|
use Tests\DuskTestCase;
|
|
use App\Models\Planner;
|
|
|
|
class LoginTest extends DuskTestCase
|
|
{
|
|
public function testSuccessfulLogin(): void
|
|
{
|
|
$this->browse(function (Browser $browser) {
|
|
$browser->driver->manage()->deleteAllCookies();
|
|
$browser->visit('http://dishplanner_app:8000/login')
|
|
->waitFor('input[id="email"]', 5)
|
|
->type('input[id="email"]', 'admin@test.com')
|
|
->type('input[id="password"]', 'password')
|
|
->press('Login')
|
|
->waitForLocation('/dashboard', 10)
|
|
->assertPathIs('/dashboard')
|
|
->assertAuthenticated()
|
|
->visit('http://dishplanner_app:8000/logout');
|
|
});
|
|
}
|
|
|
|
public function testLoginWithWrongCredentials(): void
|
|
{
|
|
$this->browse(function (Browser $browser) {
|
|
$browser->driver->manage()->deleteAllCookies();
|
|
$browser->visit('http://dishplanner_app:8000/login')
|
|
->waitFor('input[id="email"]', 5)
|
|
->type('input[id="email"]', 'admin@test.com')
|
|
->type('input[id="password"]', 'wrongpassword')
|
|
->press('Login')
|
|
->pause(2000)
|
|
->assertPathIs('/login')
|
|
->assertSee('These credentials do not match our records')
|
|
->assertGuest();
|
|
});
|
|
}
|
|
|
|
public function testLoginFormRequiredFields(): void
|
|
{
|
|
$this->browse(function (Browser $browser) {
|
|
$browser->driver->manage()->deleteAllCookies();
|
|
$browser->visit('http://dishplanner_app:8000/login')
|
|
->waitFor('input[id="email"]', 5);
|
|
|
|
// Check that both fields have the required attribute
|
|
$browser->assertAttribute('input[id="email"]', 'required', 'true');
|
|
$browser->assertAttribute('input[id="password"]', 'required', 'true');
|
|
|
|
// Verify email field is type email
|
|
$browser->assertAttribute('input[id="email"]', 'type', 'email');
|
|
|
|
// Verify password field is type password
|
|
$browser->assertAttribute('input[id="password"]', 'type', 'password');
|
|
|
|
// Test that we stay on login page if we try to submit with empty fields
|
|
$browser->press('Login')
|
|
->pause(500)
|
|
->assertPathIs('/login');
|
|
});
|
|
}
|
|
}
|