v4 testing RichEditor inside form
Is there a simpler way of populating the editor inside fillForm?
Without the array you get error from the
Without the array you get error from the
beforeStateDehydratedbeforeStateDehydratedTypeError: Filament\Forms\Components\RichEditor::{closure:Filament\Forms\Components\RichEditor::setUp():303}(): Argument #2 ($rawState) must be of type ?array, string given
<?php
use Filament\Forms\Components\RichEditor;
use Filament\Schemas\Schema;
use Filament\Tests\Fixtures\Livewire\Livewire;
use Filament\Tests\TestCase;
use Illuminate\Support\Str;
use function Filament\Tests\livewire;
uses(TestCase::class);
it('tests rich editor', function (): void {
$text = Str::random();
livewire(TestComponentWithRichEditor::class)
->fillForm([
'content' => ['type' => 'doc', 'content' => [['type' => 'paragraph', 'content' => [['type' => 'text', 'text' => $text]]]]]
])
->call('save')
->assertSet('data', [
'content' => '<p>' . $text . '</p>',
]);
});
class TestComponentWithRichEditor extends Livewire
{
public $data = [];
public function form(Schema $form): Schema
{
return $form
->schema([
RichEditor::make('content')
->required(),
])
->statePath('data');
}
public function save(): void
{
$this->data = $this->form->getState();
}
}<?php
use Filament\Forms\Components\RichEditor;
use Filament\Schemas\Schema;
use Filament\Tests\Fixtures\Livewire\Livewire;
use Filament\Tests\TestCase;
use Illuminate\Support\Str;
use function Filament\Tests\livewire;
uses(TestCase::class);
it('tests rich editor', function (): void {
$text = Str::random();
livewire(TestComponentWithRichEditor::class)
->fillForm([
'content' => ['type' => 'doc', 'content' => [['type' => 'paragraph', 'content' => [['type' => 'text', 'text' => $text]]]]]
])
->call('save')
->assertSet('data', [
'content' => '<p>' . $text . '</p>',
]);
});
class TestComponentWithRichEditor extends Livewire
{
public $data = [];
public function form(Schema $form): Schema
{
return $form
->schema([
RichEditor::make('content')
->required(),
])
->statePath('data');
}
public function save(): void
{
$this->data = $this->form->getState();
}
}