diff --git a/resources/views/livewire/device-palettes/index.blade.php b/resources/views/livewire/device-palettes/index.blade.php
index 6640545..4e96c31 100644
--- a/resources/views/livewire/device-palettes/index.blade.php
+++ b/resources/views/livewire/device-palettes/index.blade.php
@@ -1,5 +1,6 @@
devicePalettes = DevicePalette::all();
+ session()->flash('message', 'Device palettes updated from API.');
+ }
+
public function openDevicePaletteModal(?string $devicePaletteId = null, bool $viewOnly = false): void
{
if ($devicePaletteId) {
@@ -202,9 +210,17 @@ new class extends Component
-
- Add Device Palette
-
+
+
+ Add Device Palette
+
+
+
+
+ Update from API
+
+
+
@if (session()->has('message'))
diff --git a/tests/Feature/Livewire/DevicePalettesTest.php b/tests/Feature/Livewire/DevicePalettesTest.php
index 3c37934..abd4b24 100644
--- a/tests/Feature/Livewire/DevicePalettesTest.php
+++ b/tests/Feature/Livewire/DevicePalettesTest.php
@@ -4,6 +4,7 @@ declare(strict_types=1);
use App\Models\DevicePalette;
use App\Models\User;
+use Illuminate\Support\Facades\Http;
uses(Illuminate\Foundation\Testing\RefreshDatabase::class);
@@ -570,3 +571,29 @@ test('component refreshes palette list after deleting', function (): void {
expect($palettes)->toHaveCount($initialCount + 1);
expect(DevicePalette::count())->toBe($initialCount + 1);
});
+
+test('update from API runs job and refreshes device palettes', function (): void {
+ $user = User::factory()->create();
+ $this->actingAs($user);
+
+ Http::fake([
+ 'usetrmnl.com/api/palettes' => Http::response([
+ 'data' => [
+ [
+ 'id' => 'api-palette',
+ 'name' => 'API Palette',
+ 'grays' => 4,
+ 'colors' => null,
+ 'framework_class' => '',
+ ],
+ ],
+ ], 200),
+ config('services.trmnl.base_url').'/api/models' => Http::response(['data' => []], 200),
+ ]);
+
+ $component = Livewire::test('device-palettes.index')
+ ->call('updateFromApi');
+
+ $devicePalettes = $component->get('devicePalettes');
+ expect($devicePalettes->pluck('name')->toArray())->toContain('api-palette');
+});