mirror of
https://github.com/usetrmnl/byos_laravel.git
synced 2026-03-14 12:23:33 +00:00
fix: enable backwards compatibility v1 rendering strategy
Some checks failed
tests / ci (push) Has been cancelled
Some checks failed
tests / ci (push) Has been cancelled
This commit is contained in:
parent
5eb442d9d6
commit
b8b6caba12
4 changed files with 45 additions and 6 deletions
|
|
@ -11,6 +11,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|||
|
||||
/**
|
||||
* @property-read array<string, string> $css_variables
|
||||
* @property-read string|null $css_name
|
||||
* @property-read DevicePalette|null $palette
|
||||
*/
|
||||
final class DeviceModel extends Model
|
||||
|
|
@ -74,6 +75,19 @@ final class DeviceModel extends Model
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns css_name for v2 (per-device sizing); for v1 returns 'og' to preserve legacy single-variant behaviour.
|
||||
*
|
||||
* @return Attribute<string|null, string|null>
|
||||
*/
|
||||
protected function cssName(): Attribute
|
||||
{
|
||||
/** @var Attribute<string|null, string|null> */
|
||||
return Attribute::get(
|
||||
fn (mixed $value): ?string => config('app.puppeteer_window_size_strategy') === 'v2' ? ($value !== null ? (string) $value : null) : 'og'
|
||||
);
|
||||
}
|
||||
|
||||
public function palette(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(DevicePalette::class, 'palette_id');
|
||||
|
|
|
|||
|
|
@ -738,8 +738,8 @@ class Plugin extends Model
|
|||
}
|
||||
}
|
||||
|
||||
// Append " (Copy)" to the name
|
||||
$attributes['name'] = $this->name.' (Copy)';
|
||||
// Append "_copy" to the name
|
||||
$attributes['name'] = $this->name.'_copy';
|
||||
|
||||
// Set user_id - use provided userId or fall back to original plugin's user_id
|
||||
$attributes['user_id'] = $userId ?? $this->user_id;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
declare(strict_types=1);
|
||||
|
||||
use App\Models\DeviceModel;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
|
||||
test('device model has required attributes', function (): void {
|
||||
$deviceModel = DeviceModel::factory()->create([
|
||||
|
|
@ -117,3 +118,27 @@ test('device model factory creates valid data', function (): void {
|
|||
expect($deviceModel->offset_x)->toBeInt();
|
||||
expect($deviceModel->offset_y)->toBeInt();
|
||||
});
|
||||
|
||||
test('css_name returns og when puppeteer_window_size_strategy is v1', function (): void {
|
||||
Config::set('app.puppeteer_window_size_strategy', 'v1');
|
||||
|
||||
$deviceModel = DeviceModel::factory()->create(['css_name' => 'my_device']);
|
||||
|
||||
expect($deviceModel->css_name)->toBe('og');
|
||||
});
|
||||
|
||||
test('css_name returns db value when puppeteer_window_size_strategy is v2', function (): void {
|
||||
Config::set('app.puppeteer_window_size_strategy', 'v2');
|
||||
|
||||
$deviceModel = DeviceModel::factory()->create(['css_name' => 'my_device']);
|
||||
|
||||
expect($deviceModel->css_name)->toBe('my_device');
|
||||
});
|
||||
|
||||
test('css_name returns null when puppeteer_window_size_strategy is v2 and db value is null', function (): void {
|
||||
Config::set('app.puppeteer_window_size_strategy', 'v2');
|
||||
|
||||
$deviceModel = DeviceModel::factory()->create(['css_name' => null]);
|
||||
|
||||
expect($deviceModel->css_name)->toBeNull();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -824,7 +824,7 @@ test('plugin duplicate copies all attributes except id and uuid', function (): v
|
|||
|
||||
expect($duplicate->id)->not->toBe($original->id)
|
||||
->and($duplicate->uuid)->not->toBe($original->uuid)
|
||||
->and($duplicate->name)->toBe('Original Plugin (Copy)')
|
||||
->and($duplicate->name)->toBe('Original Plugin_copy')
|
||||
->and($duplicate->user_id)->toBe($original->user_id)
|
||||
->and($duplicate->data_stale_minutes)->toBe($original->data_stale_minutes)
|
||||
->and($duplicate->data_strategy)->toBe($original->data_strategy)
|
||||
|
|
@ -859,7 +859,7 @@ test('plugin duplicate sets trmnlp_id to null to avoid unique constraint violati
|
|||
|
||||
expect($duplicate->trmnlp_id)->toBeNull()
|
||||
->and($original->trmnlp_id)->toBe('test-trmnlp-id-123')
|
||||
->and($duplicate->name)->toBe('Plugin with trmnlp_id (Copy)');
|
||||
->and($duplicate->name)->toBe('Plugin with trmnlp_id_copy');
|
||||
});
|
||||
|
||||
test('plugin duplicate copies render_markup_view file content to render_markup', function (): void {
|
||||
|
|
@ -890,7 +890,7 @@ test('plugin duplicate copies render_markup_view file content to render_markup',
|
|||
expect($duplicate->render_markup)->toBe($testContent)
|
||||
->and($duplicate->markup_language)->toBe('blade')
|
||||
->and($duplicate->render_markup_view)->toBeNull()
|
||||
->and($duplicate->name)->toBe('View Plugin (Copy)');
|
||||
->and($duplicate->name)->toBe('View Plugin_copy');
|
||||
} finally {
|
||||
// Clean up test file
|
||||
if (file_exists($testViewPath)) {
|
||||
|
|
@ -949,7 +949,7 @@ test('plugin duplicate handles missing view file gracefully', function (): void
|
|||
$duplicate = $original->duplicate();
|
||||
|
||||
expect($duplicate->render_markup_view)->toBeNull()
|
||||
->and($duplicate->name)->toBe('Missing View Plugin (Copy)');
|
||||
->and($duplicate->name)->toBe('Missing View Plugin_copy');
|
||||
});
|
||||
|
||||
test('plugin duplicate uses provided user_id', function (): void {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue