diff --git a/app/Models/DeviceModel.php b/app/Models/DeviceModel.php index 7142829..bdc4b98 100644 --- a/app/Models/DeviceModel.php +++ b/app/Models/DeviceModel.php @@ -11,6 +11,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; /** * @property-read array $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 + */ + protected function cssName(): Attribute + { + /** @var Attribute */ + 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'); diff --git a/app/Models/Plugin.php b/app/Models/Plugin.php index 31a08ad..3f84bc5 100644 --- a/app/Models/Plugin.php +++ b/app/Models/Plugin.php @@ -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; diff --git a/tests/Unit/Models/DeviceModelTest.php b/tests/Unit/Models/DeviceModelTest.php index 8c2b6e9..f2ef29d 100644 --- a/tests/Unit/Models/DeviceModelTest.php +++ b/tests/Unit/Models/DeviceModelTest.php @@ -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(); +}); diff --git a/tests/Unit/Models/PluginTest.php b/tests/Unit/Models/PluginTest.php index 82813d9..1e2cda2 100644 --- a/tests/Unit/Models/PluginTest.php +++ b/tests/Unit/Models/PluginTest.php @@ -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 {