assertTableActionDataSet() on a form with FileUpload field

I got this form:
public static function form(Form $form): Form
{
return $form
->schema([
static::getNameFormField(),
Forms\Components\FileUpload::make('file')
->label(___('signeditor.files', 1))
->required()
->disk('fonts')
->getUploadedFileNameForStorageUsing(
fn (TemporaryUploadedFile $file): string => (string) str($file->getClientOriginalName())
->prepend(Str::random(40))->replace(' ', '_')
),
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
static::getNameFormField(),
Forms\Components\FileUpload::make('file')
->label(___('signeditor.files', 1))
->required()
->disk('fonts')
->getUploadedFileNameForStorageUsing(
fn (TemporaryUploadedFile $file): string => (string) str($file->getClientOriginalName())
->prepend(Str::random(40))->replace(' ', '_')
),
]);
}
and this test:
it('can save', function () {
Storage::disk('fonts')->put($this->name, file_get_contents('storage/app/tests/' . $this->name));
Storage::disk('thumbnails')->put($this->thumbnail, file_get_contents('storage/app/tests/' . $this->thumbnail));
$record = $this->modelClass::factory()->create(['file' => $this->name]);
expect(Storage::disk('fonts')->path($record->file))->toBeReadableFile();
expect(Storage::disk('thumbnails')->path($record->thumbnail))->toBeReadableFile();

livewire($this->indexClass)
->mountTableAction(EditAction::class, $record)
->assertTableActionDataSet([
'name' => $record->name,
'file' => $record->file
])->callTableAction(EditAction::class, $record, data: ['name'=>$name = fake()->word(), 'file'=>$this->newFile])
->assertHasNoTableActionErrors();
it('can save', function () {
Storage::disk('fonts')->put($this->name, file_get_contents('storage/app/tests/' . $this->name));
Storage::disk('thumbnails')->put($this->thumbnail, file_get_contents('storage/app/tests/' . $this->thumbnail));
$record = $this->modelClass::factory()->create(['file' => $this->name]);
expect(Storage::disk('fonts')->path($record->file))->toBeReadableFile();
expect(Storage::disk('thumbnails')->path($record->thumbnail))->toBeReadableFile();

livewire($this->indexClass)
->mountTableAction(EditAction::class, $record)
->assertTableActionDataSet([
'name' => $record->name,
'file' => $record->file
])->callTableAction(EditAction::class, $record, data: ['name'=>$name = fake()->word(), 'file'=>$this->newFile])
->assertHasNoTableActionErrors();
** FAILED Tests\Feature\Resources\FontResourceTest** > it can save
** [...] does not match expected type "object".**
** FAILED Tests\Feature\Resources\FontResourceTest** > it can save
** [...] does not match expected type "object".**
Now, obviously, the
$record->file
$record->file
part is a string, while the form field is whatever object type FileUpload takes. I've tried to put an UploadedFile fake in there, but to no avail. Does anyone know how I'd test the FileUpload field?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server