Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

add dusk tests

Andras Bacsai2eef8ee4338e
diff --git a/.dockerignore b/.dockerignore
index 3a0ec49f78..2eba3cb465 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -23,3 +23,4 @@ yarn-error.log
.rnd
/.ssh
.ignition.json
+.env.dusk.local
diff --git a/.gitignore b/.gitignore
index 09504afeeb..1a021ab3e6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,3 +33,4 @@ _ide_helper_models.php
/.ssh
scripts/load-test/*
.ignition.json
+.env.dusk.local
diff --git a/app/Providers/DuskServiceProvider.php b/app/Providers/DuskServiceProvider.php
new file mode 100644
index 0000000000..07e0e8709f
--- /dev/null
+++ b/app/Providers/DuskServiceProvider.php
@@ -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');
+ });
+ }
+}
diff --git a/config/app.php b/config/app.php
index 34484fe410..07a883019f 100644
--- a/config/app.php
+++ b/config/app.php
@@ -200,6 +200,7 @@ return [
App\Providers\HorizonServiceProvider::class,
App\Providers\RouteServiceProvider::class,
App\Providers\TelescopeServiceProvider::class,
+ App\Providers\DuskServiceProvider::class,
],
diff --git a/tests/Browser/LoginTest.php b/tests/Browser/LoginTest.php
index cac9a65fe6..5e8d5c53eb 100644
--- a/tests/Browser/LoginTest.php
+++ b/tests/Browser/LoginTest.php
@@ -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');
});
}
}
diff --git a/tests/Browser/Pages/HomePage.php b/tests/Browser/Pages/HomePage.php
deleted file mode 100644
index 45d9283f37..0000000000
--- a/tests/Browser/Pages/HomePage.php
+++ /dev/null
@@ -1,36 +0,0 @@
-<?php
-
-namespace Tests\Browser\Pages;
-
-use Laravel\Dusk\Browser;
-
-class HomePage extends Page
-{
- /**
- * Get the URL for the page.
- */
- public function url(): string
- {
- return '/';
- }
-
- /**
- * Assert that the browser is on the page.
- */
- public function assert(Browser $browser): void
- {
- //
- }
-
- /**
- * Get the element shortcuts for the page.
- *
- * @return array<string, string>
- */
- public function elements(): array
- {
- return [
- '@element' => '#selector',
- ];
- }
-}
diff --git a/tests/Browser/Pages/Page.php b/tests/Browser/Pages/Page.php
deleted file mode 100644
index eb9a2ded25..0000000000
--- a/tests/Browser/Pages/Page.php
+++ /dev/null
@@ -1,20 +0,0 @@
-<?php
-
-namespace Tests\Browser\Pages;
-
-use Laravel\Dusk\Page as BasePage;
-
-abstract class Page extends BasePage
-{
- /**
- * Get the global element shortcuts for the site.
- *
- * @return array<string, string>
- */
- public static function siteElements(): array
- {
- return [
- '@element' => '#selector',
- ];
- }
-}
diff --git a/tests/Browser/Project/ProjectAddNewTest.php b/tests/Browser/Project/ProjectAddNewTest.php
new file mode 100644
index 0000000000..0dae7603ea
--- /dev/null
+++ b/tests/Browser/Project/ProjectAddNewTest.php
@@ -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');
+ });
+ }
+}
diff --git a/tests/Browser/Project/ProjectSearchTest.php b/tests/Browser/Project/ProjectSearchTest.php
new file mode 100644
index 0000000000..aedf17183e
--- /dev/null
+++ b/tests/Browser/Project/ProjectSearchTest.php
@@ -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');
+ });
+ }
+}
diff --git a/tests/Browser/Project/ProjectTest.php b/tests/Browser/Project/ProjectTest.php
new file mode 100644
index 0000000000..e4707da8ae
--- /dev/null
+++ b/tests/Browser/Project/ProjectTest.php
@@ -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');
+ });
+ }
+}