makeDirectory('/images/generated'); }); test('it generates screen images and updates device', function (): void { $device = Device::factory()->create(); $job = new GenerateScreenJob($device->id, null, view('trmnl')->render()); $job->handle(); // Assert the device was updated with a new image UUID $device->refresh(); expect($device->current_screen_image)->not->toBeNull(); // Assert both PNG and BMP files were created $uuid = $device->current_screen_image; Storage::disk('public')->assertExists("/images/generated/{$uuid}.png"); }); test('it cleans up unused images', function (): void { // Create some test devices with images $activeDevice = Device::factory()->create([ 'current_screen_image' => 'uuid-to-be-replaced', ]); // Create some test files Storage::disk('public')->put('/images/generated/uuid-to-be-replaced.png', 'test'); Storage::disk('public')->put('/images/generated/uuid-to-be-replaced.bmp', 'test'); Storage::disk('public')->put('/images/generated/inactive-uuid.png', 'test'); Storage::disk('public')->put('/images/generated/inactive-uuid.bmp', 'test'); // Run a job which will trigger cleanup $job = new GenerateScreenJob($activeDevice->id, null, '
Test
'); $job->handle(); Storage::disk('public')->assertMissing('/images/generated/uuid-to-be-replaced.png'); Storage::disk('public')->assertMissing('/images/generated/uuid-to-be-replaced.bmp'); Storage::disk('public')->assertMissing('/images/generated/inactive-uuid.png'); Storage::disk('public')->assertMissing('/images/generated/inactive-uuid.bmp'); }); test('it preserves gitignore file during cleanup', function (): void { Storage::disk('public')->put('/images/generated/.gitignore', '*'); $device = Device::factory()->create(); $job = new GenerateScreenJob($device->id, null, '
Test
'); $job->handle(); Storage::disk('public')->assertExists('/images/generated/.gitignore'); }); test('it saves current_image_metadata for recipe plugins', function (): void { $deviceModel = DeviceModel::factory()->create([ 'width' => 800, 'height' => 480, 'rotation' => 0, 'mime_type' => 'image/png', 'palette_id' => null, ]); $device = Device::factory()->create(['device_model_id' => $deviceModel->id]); $plugin = Plugin::factory()->create(['plugin_type' => 'recipe']); $job = new GenerateScreenJob($device->id, $plugin->id, '
Test
'); $job->handle(); $plugin->refresh(); expect($plugin->current_image)->not->toBeNull(); expect($plugin->current_image_metadata)->toBeArray(); expect($plugin->current_image_metadata)->toHaveKeys(['width', 'height', 'rotation', 'palette_id', 'mime_type']); expect($plugin->current_image_metadata['width'])->toBe(800); expect($plugin->current_image_metadata['height'])->toBe(480); expect($plugin->current_image_metadata['mime_type'])->toBe('image/png'); });