diff --git a/tests/Browser/Concerns/AuthenticatesUsers.php b/tests/Browser/Concerns/AuthenticatesUsers.php new file mode 100644 index 0000000..640fbd0 --- /dev/null +++ b/tests/Browser/Concerns/AuthenticatesUsers.php @@ -0,0 +1,38 @@ +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'); + } + + private function assertWithDebugPause(Browser $browser, callable $assertions, int $pauseMs = 10000): void + { + try { + $assertions($browser); + } catch (\Exception $e) { + $browser->pause($pauseMs); + throw $e; + } + } +} \ No newline at end of file diff --git a/tests/Browser/CreateEntryAdminTest.php b/tests/Browser/CreateEntryAdminTest.php new file mode 100644 index 0000000..25598bc --- /dev/null +++ b/tests/Browser/CreateEntryAdminTest.php @@ -0,0 +1,61 @@ +createTestUser("login-test@example.com"); + + $filePath = base_path('tests/Browser/fixtures/robot.webp'); + + $this->browse(function (Browser $browser) use ($user, $filePath) { + $this->loginUser($browser, $user); + $this->assertWithDebugPause( + $browser, + fn($b) => + $b->visit('/admin/media') + ->waitForLocation('/admin/media') + ->assertPathIs('/admin/media') + ->assertTitleContains('Media') + ->clickLink('New media') + ->waitForText('Create Media') + ->type('#form\\.name', 'test image') + ->assertVisible('.filepond--drop-label') + ->attach('.filepond--browser', $filePath) + ->pause(7000) + ->waitForText('Create') + ->waitFor('#key-bindings-1:not([disabled])') + ->click('#key-bindings-1') + ->assertSee('Collection name') + ->pause(5000) + + ->visit('/admin/entries') + ->waitForLocation('/admin/entries') + ->assertPathIs('/admin/entries') + ->assertTitleContains('Entries') + ->clickLink('New entry') + ->waitForText('Create Entry') + ->type('#form\\.title', 'TEST ENTRY') + ->keys('#form\\.title', '{tab}') + ->waitForText('Create') + + ->click('#key-bindings-1') + ->waitForText('Updated at') + ->assertSee('Updated at') + ->visit('/admin/entries/1/edit') + ->pause(10000), + 1000 // Custom pause time for this test + ); + }); + } +} diff --git a/tests/Browser/LoginTest.php b/tests/Browser/LoginTest.php deleted file mode 100644 index eecd256..0000000 --- a/tests/Browser/LoginTest.php +++ /dev/null @@ -1,98 +0,0 @@ -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; - } - }); - } -} diff --git a/tests/Browser/UploadImageAdminTest.php b/tests/Browser/UploadImageAdminTest.php index bd94b6d..915078c 100644 --- a/tests/Browser/UploadImageAdminTest.php +++ b/tests/Browser/UploadImageAdminTest.php @@ -7,7 +7,7 @@ use Laravel\Dusk\Browser; use Tests\Browser\Concerns\AuthenticatesUsers; use Tests\DuskTestCase; -class LoginTest extends DuskTestCase +class UploadImageAdminTest extends DuskTestCase { use DatabaseTruncation; use AuthenticatesUsers; @@ -31,13 +31,14 @@ class LoginTest extends DuskTestCase ->assertTitleContains('Media') ->clickLink('New media') ->waitForText('Create Media') - ->pause(1000) + ->type('#form\\.name', 'test image') ->assertVisible('.filepond--drop-label') ->attach('.filepond--browser', $filePath) - ->waitforText('Create') - ->clickLink('Create') - // ->assertSee('Upload successful') - ->pause(10000), + ->pause(7000) + ->waitForText('Create') + ->waitFor('#key-bindings-1:not([disabled])') + ->click('#key-bindings-1') + ->assertSee('Collection name'), 1000 // Custom pause time for this test ); }); diff --git a/tests/Browser/fixtures/robot.webp b/tests/Browser/fixtures/robot.webp new file mode 100644 index 0000000..3dd400b Binary files /dev/null and b/tests/Browser/fixtures/robot.webp differ