mirror of
https://github.com/tiennm99/coolify.git
synced 2026-10-14 22:17:19 +00:00
feat(livewire): add selectedActions parameter and error handling to delete methods
- Add `$selectedActions = []` parameter to delete/remove methods in multiple Livewire components to support optional deletion actions - Return error message string when password verification fails instead of silent return - Return `true` on successful deletion to indicate completion - Handle selectedActions to set component properties for cascading deletions (delete_volumes, delete_networks, delete_configurations, docker_cleanup) - Add test coverage for Danger component delete functionality with password validation and selected actions handling
This commit is contained in:
1 parent
b926f23824
commit
8366e150b1
12 files changed
+130
-26
No files matched your search
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
use App\Livewire\Project\Shared\Danger;
|
||||
use App\Models\Application;
|
||||
use App\Models\Environment;
|
||||
use App\Models\InstanceSettings;
|
||||
use App\Models\Project;
|
||||
use App\Models\Server;
|
||||
use App\Models\StandaloneDocker;
|
||||
use App\Models\Team;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Queue;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Livewire\Livewire;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
InstanceSettings::create(['id' => 0]);
|
||||
Queue::fake();
|
||||
|
||||
$this->user = User::factory()->create([
|
||||
'password' => Hash::make('test-password'),
|
||||
]);
|
||||
$this->team = Team::factory()->create();
|
||||
$this->user->teams()->attach($this->team, ['role' => 'owner']);
|
||||
|
||||
$this->server = Server::factory()->create(['team_id' => $this->team->id]);
|
||||
$this->destination = StandaloneDocker::factory()->create([
|
||||
'server_id' => $this->server->id,
|
||||
'network' => 'test-network-'.fake()->unique()->word(),
|
||||
]);
|
||||
$this->project = Project::factory()->create(['team_id' => $this->team->id]);
|
||||
$this->environment = Environment::factory()->create(['project_id' => $this->project->id]);
|
||||
|
||||
$this->application = Application::factory()->create([
|
||||
'environment_id' => $this->environment->id,
|
||||
'destination_id' => $this->destination->id,
|
||||
'destination_type' => $this->destination->getMorphClass(),
|
||||
]);
|
||||
|
||||
$this->actingAs($this->user);
|
||||
session(['currentTeam' => $this->team]);
|
||||
|
||||
// Bind route parameters so get_route_parameters() works in the Danger component
|
||||
$route = Route::get('/test/{project_uuid}/{environment_uuid}', fn () => '')->name('test.danger');
|
||||
$request = Request::create("/test/{$this->project->uuid}/{$this->environment->uuid}");
|
||||
$route->bind($request);
|
||||
app('router')->setRoutes(app('router')->getRoutes());
|
||||
Route::dispatch($request);
|
||||
});
|
||||
|
||||
test('delete returns error string when password is incorrect', function () {
|
||||
Livewire::test(Danger::class, ['resource' => $this->application])
|
||||
->call('delete', 'wrong-password')
|
||||
->assertReturned('The provided password is incorrect.');
|
||||
|
||||
// Resource should NOT be deleted
|
||||
expect(Application::find($this->application->id))->not->toBeNull();
|
||||
});
|
||||
|
||||
test('delete succeeds with correct password and redirects', function () {
|
||||
Livewire::test(Danger::class, ['resource' => $this->application])
|
||||
->call('delete', 'test-password')
|
||||
->assertHasNoErrors();
|
||||
|
||||
// Resource should be soft-deleted
|
||||
expect(Application::find($this->application->id))->toBeNull();
|
||||
});
|
||||
|
||||
test('delete applies selectedActions from checkbox state', function () {
|
||||
$component = Livewire::test(Danger::class, ['resource' => $this->application])
|
||||
->call('delete', 'test-password', ['delete_configurations', 'docker_cleanup']);
|
||||
|
||||
expect($component->get('delete_volumes'))->toBeFalse();
|
||||
expect($component->get('delete_connected_networks'))->toBeFalse();
|
||||
expect($component->get('delete_configurations'))->toBeTrue();
|
||||
expect($component->get('docker_cleanup'))->toBeTrue();
|
||||
});
|
||||
Reference in new issue
Block a user