97 - Add auto_approve toggle to Route edit modal

This commit is contained in:
myrmidex 2026-03-18 17:51:35 +01:00
parent 9430158051
commit bab2557e85
3 changed files with 170 additions and 1 deletions

View file

@ -26,6 +26,8 @@ class Routes extends Component
// Edit form
public int $editPriority = 50;
public string $editAutoApprove = '';
// Keyword management
public string $newKeyword = '';
@ -81,6 +83,7 @@ public function openEditModal(int $feedId, int $channelId): void
$this->editingFeedId = $feedId;
$this->editingChannelId = $channelId;
$this->editPriority = $route->priority;
$this->editAutoApprove = $route->auto_approve === null ? '' : ($route->auto_approve ? '1' : '0');
$this->newKeyword = '';
$this->showKeywordInput = false;
}
@ -101,9 +104,18 @@ public function updateRoute(): void
'editPriority' => 'required|integer|min:0',
]);
$autoApprove = match ($this->editAutoApprove) {
'1' => true,
'0' => false,
default => null,
};
Route::where('feed_id', $this->editingFeedId)
->where('platform_channel_id', $this->editingChannelId)
->update(['priority' => $this->editPriority]);
->update([
'priority' => $this->editPriority,
'auto_approve' => $autoApprove,
]);
$this->closeEditModal();
}

View file

@ -50,6 +50,13 @@ class="inline-flex items-center px-4 py-2 border border-transparent text-sm font
<span>{{ $route->platformChannel?->platformInstance?->platform?->channelLabel() ?? 'Channel' }}: {{ $route->platformChannel?->display_name ?? $route->platformChannel?->name }}</span>
<span>&bull;</span>
<span>Created: {{ $route->created_at->format('M d, Y') }}</span>
@if ($route->auto_approve === true)
<span>&bull;</span>
<span class="text-green-600">Auto-approve: On</span>
@elseif ($route->auto_approve === false)
<span>&bull;</span>
<span class="text-red-600">Auto-approve: Off</span>
@endif
</div>
@if ($route->platformChannel?->description)
<p class="mt-2 text-sm text-gray-500">
@ -265,6 +272,26 @@ class="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none foc
<p class="text-sm text-gray-500 mt-1">Higher priority routes are processed first</p>
</div>
<!-- Auto-approve -->
<div>
<label class="block text-sm font-medium text-gray-700 mb-2">Auto-approve</label>
<div class="flex items-center space-x-4">
<label class="inline-flex items-center">
<input type="radio" wire:model="editAutoApprove" name="editAutoApprove" value="" class="text-blue-600 focus:ring-blue-500">
<span class="ml-2 text-sm text-gray-700">Use global setting</span>
</label>
<label class="inline-flex items-center">
<input type="radio" wire:model="editAutoApprove" name="editAutoApprove" value="1" class="text-blue-600 focus:ring-blue-500">
<span class="ml-2 text-sm text-gray-700">On</span>
</label>
<label class="inline-flex items-center">
<input type="radio" wire:model="editAutoApprove" name="editAutoApprove" value="0" class="text-blue-600 focus:ring-blue-500">
<span class="ml-2 text-sm text-gray-700">Off</span>
</label>
</div>
<p class="text-sm text-gray-500 mt-1">Override global approval setting for this route</p>
</div>
<!-- Keyword Management -->
<div class="border-t pt-4">
<div class="flex items-center space-x-2 mb-3">

View file

@ -0,0 +1,130 @@
<?php
namespace Tests\Feature\Livewire;
use App\Livewire\Routes;
use App\Models\Feed;
use App\Models\PlatformChannel;
use App\Models\Route;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;
class RoutesAutoApproveTest extends TestCase
{
use RefreshDatabase;
private function createRoute(?bool $autoApprove = null): Route
{
$feed = Feed::factory()->create();
$channel = PlatformChannel::factory()->create();
return Route::create([
'feed_id' => $feed->id,
'platform_channel_id' => $channel->id,
'is_active' => true,
'priority' => 50,
'auto_approve' => $autoApprove,
]);
}
public function test_edit_modal_loads_auto_approve_null(): void
{
$route = $this->createRoute(null);
Livewire::test(Routes::class)
->call('openEditModal', $route->feed_id, $route->platform_channel_id)
->assertSet('editAutoApprove', '');
}
public function test_edit_modal_loads_auto_approve_true(): void
{
$route = $this->createRoute(true);
Livewire::test(Routes::class)
->call('openEditModal', $route->feed_id, $route->platform_channel_id)
->assertSet('editAutoApprove', '1');
}
public function test_edit_modal_loads_auto_approve_false(): void
{
$route = $this->createRoute(false);
Livewire::test(Routes::class)
->call('openEditModal', $route->feed_id, $route->platform_channel_id)
->assertSet('editAutoApprove', '0');
}
public function test_update_route_sets_auto_approve_to_true(): void
{
$route = $this->createRoute(null);
Livewire::test(Routes::class)
->call('openEditModal', $route->feed_id, $route->platform_channel_id)
->set('editAutoApprove', '1')
->call('updateRoute');
$updated = Route::where('feed_id', $route->feed_id)
->where('platform_channel_id', $route->platform_channel_id)
->first();
$this->assertTrue($updated->auto_approve);
}
public function test_update_route_sets_auto_approve_to_false(): void
{
$route = $this->createRoute(null);
Livewire::test(Routes::class)
->call('openEditModal', $route->feed_id, $route->platform_channel_id)
->set('editAutoApprove', '0')
->call('updateRoute');
$updated = Route::where('feed_id', $route->feed_id)
->where('platform_channel_id', $route->platform_channel_id)
->first();
$this->assertFalse($updated->auto_approve);
}
public function test_update_route_sets_auto_approve_to_null(): void
{
$route = $this->createRoute(true);
Livewire::test(Routes::class)
->call('openEditModal', $route->feed_id, $route->platform_channel_id)
->set('editAutoApprove', '')
->call('updateRoute');
$updated = Route::where('feed_id', $route->feed_id)
->where('platform_channel_id', $route->platform_channel_id)
->first();
$this->assertNull($updated->auto_approve);
}
public function test_route_card_shows_auto_approve_on_badge(): void
{
$this->createRoute(true);
Livewire::test(Routes::class)
->assertSee('Auto-approve: On');
}
public function test_route_card_shows_auto_approve_off_badge(): void
{
$this->createRoute(false);
Livewire::test(Routes::class)
->assertSee('Auto-approve: Off');
}
public function test_route_card_hides_badge_when_using_global_setting(): void
{
$this->createRoute(null);
Livewire::test(Routes::class)
->assertDontSee('Auto-approve: On')
->assertDontSee('Auto-approve: Off');
}
}