feature - 8 - Fix e2e tests

This commit is contained in:
myrmidex 2025-12-29 17:38:37 +01:00
parent 8336df4551
commit 53840d5ced
5 changed files with 69 additions and 86 deletions

View file

@ -70,4 +70,22 @@ public function testCanCancelDishCreation(): void
->assertDontSee('Add New Dish');
});
}
public function testCanCreateDishSuccessfully(): void
{
$this->browse(function (Browser $browser) {
$dishName = 'Test Dish ' . uniqid();
$this->loginAndGoToDishes($browser)
->waitFor('button[wire\\:click="create"]', 5)
->click('button[wire\\:click="create"]')
->pause(1000)
->waitFor('input[wire\\:model="name"]', 5)
->type('input[wire\\:model="name"]', $dishName)
->press('Create Dish')
->pause(3000) // Wait for Livewire to process
->assertSee($dishName) // Should see the dish in the list
->assertSee('Dish created successfully'); // Flash message
});
}
}

View file

@ -8,22 +8,12 @@
class DeleteDishTest extends DuskTestCase
{
use LoginHelpers;
public function testCanAccessDeleteFeature(): void
{
$this->browse(function (Browser $browser) {
// Login first
$browser->driver->manage()->deleteAllCookies();
$browser->visit('http://dishplanner_app:8000/login')
->waitFor('input[id="email"]', 5)
->type('input[id="email"]', 'admin@test.com')
->type('input[id="password"]', 'password')
->press('Login')
->pause(2000)
->assertPathIs('/dashboard')
// Navigate to Dishes and verify delete functionality exists
->clickLink('Dishes')
->pause(2000)
$this->loginAndGoToDishes($browser)
->assertPathIs('/dishes')
->assertSee('MANAGE DISHES');
@ -36,16 +26,7 @@ public function testCanAccessDeleteFeature(): void
public function testDeleteModalComponents(): void
{
$this->browse(function (Browser $browser) {
$browser->driver->manage()->deleteAllCookies();
$browser->visit('http://dishplanner_app:8000/login')
->waitFor('input[id="email"]', 5)
->type('input[id="email"]', 'admin@test.com')
->type('input[id="password"]', 'password')
->press('Login')
->pause(2000)
->clickLink('Dishes')
->pause(2000)
$this->loginAndGoToDishes($browser)
->assertSee('MANAGE DISHES')
->assertSee('Add Dish');
});
@ -54,22 +35,18 @@ public function testDeleteModalComponents(): void
public function testDeletionSafetyFeatures(): void
{
$this->browse(function (Browser $browser) {
$browser->driver->manage()->deleteAllCookies();
$browser->visit('http://dishplanner_app:8000/login')
->waitFor('input[id="email"]', 5)
->type('input[id="email"]', 'admin@test.com')
->type('input[id="password"]', 'password')
->press('Login')
->pause(2000)
->clickLink('Dishes')
->pause(2000);
$this->loginAndGoToDishes($browser);
// Check that Livewire component includes all CRUD features
$pageSource = $browser->driver->getPageSource();
$this->assertStringContainsString('MANAGE DISHES', $pageSource);
$this->assertStringContainsString('Add Dish', $pageSource);
$this->assertStringContainsString('No dishes found', $pageSource);
// Either we have dishes with Delete button OR "No dishes found" message
if (str_contains($pageSource, 'No dishes found')) {
$this->assertStringContainsString('No dishes found', $pageSource);
} else {
$this->assertStringContainsString('Delete', $pageSource);
}
});
}
}

View file

@ -8,22 +8,12 @@
class EditDishTest extends DuskTestCase
{
use LoginHelpers;
public function testCanAccessEditFeature(): void
{
$this->browse(function (Browser $browser) {
// Login first
$browser->driver->manage()->deleteAllCookies();
$browser->visit('http://dishplanner_app:8000/login')
->waitFor('input[id="email"]', 5)
->type('input[id="email"]', 'admin@test.com')
->type('input[id="password"]', 'password')
->press('Login')
->pause(2000)
->assertPathIs('/dashboard')
// Navigate to Dishes and verify edit functionality exists
->clickLink('Dishes')
->pause(2000)
$this->loginAndGoToDishes($browser)
->assertPathIs('/dishes')
->assertSee('MANAGE DISHES');
@ -36,16 +26,7 @@ public function testCanAccessEditFeature(): void
public function testEditModalComponents(): void
{
$this->browse(function (Browser $browser) {
$browser->driver->manage()->deleteAllCookies();
$browser->visit('http://dishplanner_app:8000/login')
->waitFor('input[id="email"]', 5)
->type('input[id="email"]', 'admin@test.com')
->type('input[id="password"]', 'password')
->press('Login')
->pause(2000)
->clickLink('Dishes')
->pause(2000)
$this->loginAndGoToDishes($browser)
->assertSee('MANAGE DISHES')
->assertSee('Add Dish');
});
@ -54,24 +35,19 @@ public function testEditModalComponents(): void
public function testDishesPageStructure(): void
{
$this->browse(function (Browser $browser) {
$browser->driver->manage()->deleteAllCookies();
$browser->visit('http://dishplanner_app:8000/login')
->waitFor('input[id="email"]', 5)
->type('input[id="email"]', 'admin@test.com')
->type('input[id="password"]', 'password')
->press('Login')
->pause(2000)
->clickLink('Dishes')
->pause(2000)
$this->loginAndGoToDishes($browser)
->assertSee('MANAGE DISHES')
->assertSee('Add Dish');
// Check that the dishes CRUD structure is present
$pageSource = $browser->driver->getPageSource();
$this->assertStringContainsString('Edit', $pageSource);
$this->assertStringContainsString('Delete', $pageSource);
$this->assertStringContainsString('No dishes found', $pageSource);
// Either we have dishes with Edit/Delete buttons OR "No dishes found" message
if (str_contains($pageSource, 'No dishes found')) {
$this->assertStringContainsString('No dishes found', $pageSource);
} else {
$this->assertStringContainsString('Edit', $pageSource);
$this->assertStringContainsString('Delete', $pageSource);
}
});
}
}

View file

@ -106,14 +106,15 @@ public function testCanUpdateUser(): void
->clear('input[wire\\:model="name"]')
->type('input[wire\\:model="name"]', $updatedName)
->press('Update User')
->pause(3000); // Wait for Livewire to process
// First, verify the database was actually updated
$user = \App\Models\User::find($userId);
$this->assertEquals($updatedName, $user->name, 'User name was not updated in database');
// Then check for the success message
$browser->assertSee('User updated successfully');
// Wait for Livewire to process the update
->pause(3000) // Give plenty of time for Livewire to complete
->assertSee('User updated successfully')
// Verify the updated name is visible in the list
->assertSee($updatedName)
->assertDontSee($originalName);
} else {
$this->fail('Could not find user ID for editing');
}

View file

@ -11,12 +11,13 @@ class LoginTest extends DuskTestCase
public function testSuccessfulLogin(): void
{
$this->browse(function (Browser $browser) {
$browser->driver->manage()->deleteAllCookies();
$browser->visit('http://dishplanner_app:8000/login')
->waitFor('input[id="email"]', 5)
->type('input[id="email"]', 'admin@test.com')
->type('input[id="password"]', 'password')
->press('Login')
->pause(3000)
->waitForLocation('/dashboard', 10)
->assertPathIs('/dashboard')
->assertAuthenticated()
->visit('http://dishplanner_app:8000/logout');
@ -39,17 +40,27 @@ public function testLoginWithWrongCredentials(): void
});
}
public function testLoginWithBlankFields(): void
public function testLoginFormRequiredFields(): void
{
$this->browse(function (Browser $browser) {
$browser->driver->manage()->deleteAllCookies();
$browser->visit('http://dishplanner_app:8000/login')
->waitFor('input[id="email"]', 5)
->press('Login')
->pause(2000)
->assertPathIs('/login')
->assertSee('The email field is required')
->assertGuest();
->waitFor('input[id="email"]', 5);
// Check that both fields have the required attribute
$browser->assertAttribute('input[id="email"]', 'required', 'true');
$browser->assertAttribute('input[id="password"]', 'required', 'true');
// Verify email field is type email
$browser->assertAttribute('input[id="email"]', 'type', 'email');
// Verify password field is type password
$browser->assertAttribute('input[id="password"]', 'type', 'password');
// Test that we stay on login page if we try to submit with empty fields
$browser->press('Login')
->pause(500)
->assertPathIs('/login');
});
}
}
}