mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-03-14 12:23:33 +00:00
feat: add update functionality for device models in UI
This commit is contained in:
parent
06e6fb0e84
commit
e71d79190a
2 changed files with 57 additions and 3 deletions
|
|
@ -1,5 +1,6 @@
|
|||
<?php
|
||||
|
||||
use App\Jobs\FetchDeviceModelsJob;
|
||||
use App\Models\DeviceModel;
|
||||
use App\Models\DevicePalette;
|
||||
use Livewire\Component;
|
||||
|
|
@ -66,6 +67,14 @@ new class extends Component
|
|||
|
||||
public $viewingDeviceModelId;
|
||||
|
||||
public function updateFromApi(): void
|
||||
{
|
||||
FetchDeviceModelsJob::dispatchSync();
|
||||
$this->deviceModels = DeviceModel::all();
|
||||
$this->devicePalettes = DevicePalette::all();
|
||||
session()->flash('message', 'Device models updated from API.');
|
||||
}
|
||||
|
||||
public function openDeviceModelModal(?string $deviceModelId = null, bool $viewOnly = false): void
|
||||
{
|
||||
if ($deviceModelId) {
|
||||
|
|
@ -229,9 +238,17 @@ new class extends Component
|
|||
</flux:menu>
|
||||
</flux:dropdown>
|
||||
</div>
|
||||
<flux:button.group>
|
||||
<flux:modal.trigger name="device-model-modal">
|
||||
<flux:button wire:click="openDeviceModelModal()" icon="plus" variant="primary">Add Device Model</flux:button>
|
||||
</flux:modal.trigger>
|
||||
<flux:dropdown>
|
||||
<flux:button icon="chevron-down" variant="primary"></flux:button>
|
||||
<flux:menu>
|
||||
<flux:menu.item icon="arrow-path" wire:click="updateFromApi">Update from Models API</flux:menu.item>
|
||||
</flux:menu>
|
||||
</flux:dropdown>
|
||||
</flux:button.group>
|
||||
</div>
|
||||
@if (session()->has('message'))
|
||||
<div class="mb-4">
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ declare(strict_types=1);
|
|||
|
||||
use App\Models\DeviceModel;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Livewire\Livewire;
|
||||
|
||||
it('allows a user to view the device models page', function (): void {
|
||||
$user = User::factory()->create();
|
||||
|
|
@ -87,3 +89,38 @@ it('redirects unauthenticated users from the device models page', function (): v
|
|||
|
||||
$response->assertRedirect('/login');
|
||||
});
|
||||
|
||||
it('update from API runs job and refreshes device models', function (): void {
|
||||
$user = User::factory()->create();
|
||||
$this->actingAs($user);
|
||||
|
||||
Http::fake([
|
||||
'usetrmnl.com/api/palettes' => Http::response(['data' => []], 200),
|
||||
config('services.trmnl.base_url').'/api/models' => Http::response([
|
||||
'data' => [
|
||||
[
|
||||
'name' => 'api-model',
|
||||
'label' => 'API Model',
|
||||
'description' => 'From API',
|
||||
'width' => 800,
|
||||
'height' => 480,
|
||||
'colors' => 4,
|
||||
'bit_depth' => 2,
|
||||
'scale_factor' => 1.0,
|
||||
'rotation' => 0,
|
||||
'mime_type' => 'image/png',
|
||||
'offset_x' => 0,
|
||||
'offset_y' => 0,
|
||||
'kind' => 'trmnl',
|
||||
'published_at' => '2023-01-01T00:00:00Z',
|
||||
],
|
||||
],
|
||||
], 200),
|
||||
]);
|
||||
|
||||
$component = Livewire::test('device-models.index')
|
||||
->call('updateFromApi');
|
||||
|
||||
$deviceModels = $component->get('deviceModels');
|
||||
expect($deviceModels->pluck('name')->toArray())->toContain('api-model');
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue