feat: add admin email configuration to app settings
delete: remove outdated Spatie media library decision document docs: create new decision document for Spatie media library usage docs: add testing strategy document for Pest4 and Dusk test: implement login tests with Dusk for user authentication chore: add .gitignore files for console, screenshots, and source directories
This commit is contained in:
parent
aa39707e10
commit
ff5ab3aa58
14 changed files with 189 additions and 1491 deletions
98
tests/Browser/LoginTest.php
Normal file
98
tests/Browser/LoginTest.php
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Browser;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\DatabaseTruncation;
|
||||
use Laravel\Dusk\Browser;
|
||||
use Tests\DuskTestCase;
|
||||
|
||||
class LoginTest extends DuskTestCase
|
||||
{
|
||||
use DatabaseTruncation;
|
||||
|
||||
/**
|
||||
* Dusk test panel.
|
||||
*/
|
||||
private function createTestUser(string $email): User
|
||||
{
|
||||
return User::factory()->create([
|
||||
'email' => $email,
|
||||
'password' => bcrypt('password'),
|
||||
'two_factor_secret' => null,
|
||||
'two_factor_recovery_codes' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
private function loginUser(Browser $browser, User $user): void
|
||||
{
|
||||
$browser->visit('/login')
|
||||
->type('email', $user->email)
|
||||
->type('password', 'password')
|
||||
->press('Log in')
|
||||
->waitForLocation('/dashboard');
|
||||
}
|
||||
|
||||
public function test_login(): void
|
||||
{
|
||||
$user = $this->createTestUser("login-test@example.com");
|
||||
|
||||
$this->browse(function (Browser $browser) use ($user) {
|
||||
$this->loginUser($browser, $user);
|
||||
try {
|
||||
$browser->assertPathIs('/dashboard'); // Or wherever successful login redirects
|
||||
} catch (\Exception $e) {
|
||||
$browser->pause(10000); // Pause for 10 seconds on failure to debug
|
||||
throw $e;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
public function test_invalid_login(): void
|
||||
{
|
||||
$user = $this->createTestUser("invalid-email@example.com");
|
||||
|
||||
|
||||
$this->browse(function (Browser $browser) use ($user) {
|
||||
$this->loginUser($browser, $user);
|
||||
try {
|
||||
$browser->visit('/admin')
|
||||
->waitForLocation('/admin')
|
||||
->assertPathIs('/admin')
|
||||
->assertTitleContains('Dashboard')
|
||||
->assertDontSee('Forbidden')
|
||||
->pause(1000);
|
||||
} catch (\Exception $e) {
|
||||
$browser->pause(1000); // Pause for 1 second on failure to debug
|
||||
throw $e;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
public function test_access_admin_panel(): void
|
||||
{
|
||||
|
||||
$user = $this->createTestUser("login-test@example.com");
|
||||
|
||||
$this->browse(function (Browser $browser) use ($user) {
|
||||
$this->loginUser($browser, $user);
|
||||
try {
|
||||
$browser->visit('/admin')
|
||||
->waitForLocation('/admin')
|
||||
->assertPathIs('/admin')
|
||||
->assertTitleContains('Dashboard')
|
||||
->assertDontSee('Forbidden')
|
||||
->pause(1000);
|
||||
} catch (\Exception $e) {
|
||||
$browser->pause(1000); // Pause for 1 second on failure to debug
|
||||
throw $e;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue