Skip to content

Commit 64a9ab8

Browse files
committed
Add configuration for file upload disk and directory in FileConverterTest
1 parent 223279f commit 64a9ab8

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

packages/admin/src/Support/FieldTypes/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public static function getConfigurationFields(): array
9595
)->nullable()->numeric(),
9696
Select::make('disk')
9797
->label(__('lunarpanel::fieldtypes.file.form.disk.label'))
98-
->options(array_combine($disks, $disks))
98+
->options(! empty($disks) ? array_combine($disks, $disks) : [])
9999
->nullable(),
100100
TextInput::make('directory')
101101
->label(__('lunarpanel::fieldtypes.file.form.directory.label'))
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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

Comments
 (0)