Added a basic login test and also added 2 small variables to dev .env file

Small test just to see if you wish to continue this way of me writing tests in this shape and form. you can run them locally with php artisan dusk:chrome-driver --detect, run it with ./vendor/laravel/dusk/bin/chromedriver-mac-arm --port=9515  then run tests with php artisan dusk
This commit is contained in:
ALsJourney
2024-09-06 14:16:40 +02:00
parent 6f5b92d322
commit cddd4b59f9
5 changed files with 42 additions and 21 deletions

View File

@@ -13,6 +13,8 @@ TELESCOPE_ENABLED=false
# Selenium Driver URL for Dusk
DUSK_DRIVER_URL=http://selenium:4444
DUSK_EMAIL=test@example.com
DUSK_PASSWORD=password
# PostgreSQL Database Configuration
DB_DATABASE=coolify

6
config/testing.php Normal file
View File

@@ -0,0 +1,6 @@
<?php
return [
'dusk_test_email' => env('DUSK_TEST_EMAIL', 'test@example.com'),
'dusk_test_password' => env('DUSK_TEST_PASSWORD', 'password'),
];

View File

@@ -1,20 +0,0 @@
<?php
namespace Tests\Browser;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
class ExampleTest extends DuskTestCase
{
/**
* A basic browser test example.
*/
public function testBasicExample(): void
{
$this->browse(function (Browser $browser) {
$browser->visit('/')
->assertSee('Laravel');
});
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Tests\Browser;
use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
use Throwable;
class LoginTest extends DuskTestCase
{
/**
* A basic test for the login page.
* Login with the test user and assert that the user is redirected to the dashboard.
*
* @return void
* @throws Throwable
*/
public function testLogin()
{
$email = config('testing.dusk_test_email');
$password = config('testing.dusk_test_password');
$this->browse(function (Browser $browser) use ($password, $email) {
$browser->visit('/login')
->type('email', $email)
->type('password', $password)
->press('Login')
->assertPathIs('/');
});
}
}

View File

@@ -67,6 +67,9 @@ abstract class DuskTestCase extends BaseTestCase
protected function baseUrl()
{
return rtrim(config('app.url'), '/');
$app_url = config('app.url');
$port = config('app.port');
return $app_url.':'.$port;
}
}