Skip to content

Commit

Permalink
add dusk tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasbacsai committed Oct 28, 2024
1 parent bb7184b commit 2eef8ee
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 64 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ yarn-error.log
.rnd
/.ssh
.ignition.json
.env.dusk.local
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ _ide_helper_models.php
/.ssh
scripts/load-test/*
.ignition.json
.env.dusk.local
21 changes: 21 additions & 0 deletions app/Providers/DuskServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class DuskServiceProvider extends ServiceProvider
{
/**
* Register Dusk's browser macros.
*/
public function boot(): void
{
\Laravel\Dusk\Browser::macro('loginWithRootUser', function () {
return $this->visit('/login')
->type('email', '[email protected]')
->type('password', 'password')
->press('Login');
});
}
}
1 change: 1 addition & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
App\Providers\HorizonServiceProvider::class,
App\Providers\RouteServiceProvider::class,
App\Providers\TelescopeServiceProvider::class,
App\Providers\DuskServiceProvider::class,

],

Expand Down
11 changes: 3 additions & 8 deletions tests/Browser/LoginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,10 @@ class LoginTest extends DuskTestCase
*/
public function testLogin()
{
$email = '[email protected]';
$password = 'password';
$this->browse(function (Browser $browser) use ($password, $email) {
$browser->visit('/login')
->type('email', $email)
->type('password', $password)
->press('Login')
$this->browse(callback: function (Browser $browser) {
$browser->loginWithRootUser()
->assertPathIs('/')
->screenshot('login');
->assertSee('Dashboard');
});
}
}
36 changes: 0 additions & 36 deletions tests/Browser/Pages/HomePage.php

This file was deleted.

20 changes: 0 additions & 20 deletions tests/Browser/Pages/Page.php

This file was deleted.

34 changes: 34 additions & 0 deletions tests/Browser/Project/ProjectAddNewTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Tests\Browser;

use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
use Throwable;

class ProjectAddNewTest extends DuskTestCase
{
/**
* A basic test for the projects page.
* Login with the test user and assert that the user is redirected to the projects page.
*
* @return void
*
* @throws Throwable
*/
public function testLogin()
{
$this->browse(function (Browser $browser) {
$browser->loginWithRootUser()
->visit('/projects')
->pressAndWaitFor('+ Add', 1)
->assertSee('New Project')
->screenshot('project-add-new-1')
->type('name', 'Test Project')
->screenshot('project-add-new-2')
->press('Continue')
->assertSee('Test Project.')
->screenshot('project-add-new-3');
});
}
}
29 changes: 29 additions & 0 deletions tests/Browser/Project/ProjectSearchTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Tests\Browser;

use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
use Throwable;

class ProjectSearchTest extends DuskTestCase
{
/**
* A basic test for the projects page.
* Login with the test user and assert that the user is redirected to the projects page.
*
* @return void
*
* @throws Throwable
*/
public function testLogin()
{
$this->browse(function (Browser $browser) {
$browser->loginWithRootUser()
->visit('/projects')
->type('[x-model="search"]', 'joi43j4oi32j4o2')
->assertSee('No project found with the search term "joi43j4oi32j4o2".')
->screenshot('project-search-not-found');
});
}
}
27 changes: 27 additions & 0 deletions tests/Browser/Project/ProjectTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Tests\Browser;

use Laravel\Dusk\Browser;
use Tests\DuskTestCase;
use Throwable;

class ProjectTest extends DuskTestCase
{
/**
* A basic test for the projects page.
* Login with the test user and assert that the user is redirected to the projects page.
*
* @return void
*
* @throws Throwable
*/
public function testLogin()
{
$this->browse(function (Browser $browser) {
$browser->loginWithRootUser()
->visit('/projects')
->assertSee('Projects');
});
}
}

0 comments on commit 2eef8ee

Please sign in to comment.