|
| 1 | +<?php |
| 2 | + |
| 3 | +use Filament\Forms\Components\FileUpload; |
| 4 | +use Lunar\FieldTypes\File; |
| 5 | +use Lunar\Models\Attribute; |
| 6 | +use Lunar\Tests\Admin\Unit\Livewire\TestCase; |
| 7 | + |
| 8 | +uses(TestCase::class) |
| 9 | + ->group('livewire.support.forms'); |
| 10 | + |
| 11 | +describe('file field converter', function () { |
| 12 | + beforeEach(function () { |
| 13 | + $this->asStaff(); |
| 14 | + }); |
| 15 | + |
| 16 | + test('can convert attribute to form input component', function () { |
| 17 | + $attribute = Attribute::factory()->create([ |
| 18 | + 'type' => File::class, |
| 19 | + ]); |
| 20 | + |
| 21 | + $inputComponent = Lunar\Admin\Support\FieldTypes\File::getFilamentComponent($attribute); |
| 22 | + |
| 23 | + expect($inputComponent)->toBeInstanceOf(FileUpload::class); |
| 24 | + }); |
| 25 | + |
| 26 | + test('can configure file upload disk', function () { |
| 27 | + $attribute = Attribute::factory()->create([ |
| 28 | + 'type' => File::class, |
| 29 | + 'configuration' => [ |
| 30 | + 'disk' => 'public', |
| 31 | + ], |
| 32 | + ]); |
| 33 | + |
| 34 | + $inputComponent = Lunar\Admin\Support\FieldTypes\File::getFilamentComponent($attribute); |
| 35 | + |
| 36 | + expect($inputComponent->getDiskName())->toBe('public'); |
| 37 | + }); |
| 38 | + |
| 39 | + test('can configure file upload directory', function () { |
| 40 | + $attribute = Attribute::factory()->create([ |
| 41 | + 'type' => File::class, |
| 42 | + 'configuration' => [ |
| 43 | + 'directory' => 'products/images', |
| 44 | + ], |
| 45 | + ]); |
| 46 | + |
| 47 | + $inputComponent = Lunar\Admin\Support\FieldTypes\File::getFilamentComponent($attribute); |
| 48 | + |
| 49 | + expect($inputComponent->getDirectory())->toBe('products/images'); |
| 50 | + }); |
| 51 | + |
| 52 | + test('can configure file upload disk and directory together', function () { |
| 53 | + $attribute = Attribute::factory()->create([ |
| 54 | + 'type' => File::class, |
| 55 | + 'configuration' => [ |
| 56 | + 'disk' => 's3', |
| 57 | + 'directory' => 'catalog/files', |
| 58 | + ], |
| 59 | + ]); |
| 60 | + |
| 61 | + $inputComponent = Lunar\Admin\Support\FieldTypes\File::getFilamentComponent($attribute); |
| 62 | + |
| 63 | + expect($inputComponent->getDiskName())->toBe('s3') |
| 64 | + ->and($inputComponent->getDirectory())->toBe('catalog/files'); |
| 65 | + }); |
| 66 | +}); |
0 commit comments