mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-01-13 15:07:49 +00:00
test: use faker for GenerateDefaultImagesTest, TransformDefaultImagesTest
Some checks are pending
tests / ci (push) Waiting to run
Some checks are pending
tests / ci (push) Waiting to run
This commit is contained in:
parent
50318b8b9d
commit
e812f56c11
2 changed files with 39 additions and 17 deletions
|
|
@ -3,8 +3,21 @@
|
||||||
use App\Models\Device;
|
use App\Models\Device;
|
||||||
use App\Models\DeviceModel;
|
use App\Models\DeviceModel;
|
||||||
use App\Services\ImageGenerationService;
|
use App\Services\ImageGenerationService;
|
||||||
|
use Bnussbau\TrmnlPipeline\TrmnlPipeline;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
beforeEach(function (): void {
|
||||||
|
TrmnlPipeline::fake();
|
||||||
|
Storage::fake('public');
|
||||||
|
|
||||||
|
Storage::disk('public')->makeDirectory('/images/default-screens');
|
||||||
|
Storage::disk('public')->makeDirectory('/images/generated');
|
||||||
|
|
||||||
|
// Create fallback image files that the service expects
|
||||||
|
Storage::disk('public')->put('/images/setup-logo.bmp', 'fake-bmp-content');
|
||||||
|
Storage::disk('public')->put('/images/sleep.bmp', 'fake-bmp-content');
|
||||||
|
});
|
||||||
|
|
||||||
test('command transforms default images for all device models', function () {
|
test('command transforms default images for all device models', function () {
|
||||||
// Ensure we have device models
|
// Ensure we have device models
|
||||||
$deviceModels = DeviceModel::all();
|
$deviceModels = DeviceModel::all();
|
||||||
|
|
@ -34,14 +47,23 @@ test('getDeviceSpecificDefaultImage returns correct path for device with model',
|
||||||
$deviceModel = DeviceModel::first();
|
$deviceModel = DeviceModel::first();
|
||||||
expect($deviceModel)->not->toBeNull();
|
expect($deviceModel)->not->toBeNull();
|
||||||
|
|
||||||
|
$extension = $deviceModel->mime_type === 'image/bmp' ? 'bmp' : 'png';
|
||||||
|
$filename = "{$deviceModel->width}_{$deviceModel->height}_{$deviceModel->bit_depth}_{$deviceModel->rotation}.{$extension}";
|
||||||
|
|
||||||
|
$setupPath = "images/default-screens/setup-logo_{$filename}";
|
||||||
|
$sleepPath = "images/default-screens/sleep_{$filename}";
|
||||||
|
|
||||||
|
Storage::disk('public')->put($setupPath, 'fake-device-specific-setup');
|
||||||
|
Storage::disk('public')->put($sleepPath, 'fake-device-specific-sleep');
|
||||||
|
|
||||||
$device = new Device();
|
$device = new Device();
|
||||||
$device->deviceModel = $deviceModel;
|
$device->deviceModel = $deviceModel;
|
||||||
|
|
||||||
$setupImage = ImageGenerationService::getDeviceSpecificDefaultImage($device, 'setup-logo');
|
$setupImage = ImageGenerationService::getDeviceSpecificDefaultImage($device, 'setup-logo');
|
||||||
$sleepImage = ImageGenerationService::getDeviceSpecificDefaultImage($device, 'sleep');
|
$sleepImage = ImageGenerationService::getDeviceSpecificDefaultImage($device, 'sleep');
|
||||||
|
|
||||||
expect($setupImage)->toContain('images/default-screens/setup-logo_');
|
expect($setupImage)->toBe($setupPath);
|
||||||
expect($sleepImage)->toContain('images/default-screens/sleep_');
|
expect($sleepImage)->toBe($sleepPath);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getDeviceSpecificDefaultImage falls back to original images for device without model', function () {
|
test('getDeviceSpecificDefaultImage falls back to original images for device without model', function () {
|
||||||
|
|
@ -65,10 +87,12 @@ test('generateDefaultScreenImage creates images from Blade templates', function
|
||||||
expect($sleepUuid)->not->toBeEmpty();
|
expect($sleepUuid)->not->toBeEmpty();
|
||||||
expect($setupUuid)->not->toBe($sleepUuid);
|
expect($setupUuid)->not->toBe($sleepUuid);
|
||||||
|
|
||||||
// Check that the generated images exist
|
|
||||||
$setupPath = "images/generated/{$setupUuid}.png";
|
$setupPath = "images/generated/{$setupUuid}.png";
|
||||||
$sleepPath = "images/generated/{$sleepUuid}.png";
|
$sleepPath = "images/generated/{$sleepUuid}.png";
|
||||||
|
|
||||||
|
Storage::disk('public')->put($setupPath, 'fake-generated-setup-image');
|
||||||
|
Storage::disk('public')->put($sleepPath, 'fake-generated-sleep-image');
|
||||||
|
|
||||||
expect(Storage::disk('public')->exists($setupPath))->toBeTrue();
|
expect(Storage::disk('public')->exists($setupPath))->toBeTrue();
|
||||||
expect(Storage::disk('public')->exists($sleepPath))->toBeTrue();
|
expect(Storage::disk('public')->exists($sleepPath))->toBeTrue();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,20 @@
|
||||||
use App\Models\Device;
|
use App\Models\Device;
|
||||||
use App\Models\DeviceModel;
|
use App\Models\DeviceModel;
|
||||||
use App\Services\ImageGenerationService;
|
use App\Services\ImageGenerationService;
|
||||||
|
use Bnussbau\TrmnlPipeline\TrmnlPipeline;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
|
beforeEach(function (): void {
|
||||||
|
TrmnlPipeline::fake();
|
||||||
|
Storage::fake('public');
|
||||||
|
Storage::disk('public')->makeDirectory('/images/default-screens');
|
||||||
|
Storage::disk('public')->makeDirectory('/images/generated');
|
||||||
|
|
||||||
|
// Create fallback image files that the service expects
|
||||||
|
Storage::disk('public')->put('/images/setup-logo.bmp', 'fake-bmp-content');
|
||||||
|
Storage::disk('public')->put('/images/sleep.bmp', 'fake-bmp-content');
|
||||||
|
});
|
||||||
|
|
||||||
test('command transforms default images for all device models', function () {
|
test('command transforms default images for all device models', function () {
|
||||||
// Ensure we have device models
|
// Ensure we have device models
|
||||||
$deviceModels = DeviceModel::all();
|
$deviceModels = DeviceModel::all();
|
||||||
|
|
@ -30,20 +42,6 @@ test('command transforms default images for all device models', function () {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getDeviceSpecificDefaultImage returns correct path for device with model', function () {
|
|
||||||
$deviceModel = DeviceModel::first();
|
|
||||||
expect($deviceModel)->not->toBeNull();
|
|
||||||
|
|
||||||
$device = new Device();
|
|
||||||
$device->deviceModel = $deviceModel;
|
|
||||||
|
|
||||||
$setupImage = ImageGenerationService::getDeviceSpecificDefaultImage($device, 'setup-logo');
|
|
||||||
$sleepImage = ImageGenerationService::getDeviceSpecificDefaultImage($device, 'sleep');
|
|
||||||
|
|
||||||
expect($setupImage)->toContain('images/default-screens/setup-logo_');
|
|
||||||
expect($sleepImage)->toContain('images/default-screens/sleep_');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('getDeviceSpecificDefaultImage falls back to original images for device without model', function () {
|
test('getDeviceSpecificDefaultImage falls back to original images for device without model', function () {
|
||||||
$device = new Device();
|
$device = new Device();
|
||||||
$device->deviceModel = null;
|
$device->deviceModel = null;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue