PepperFM
PepperFM
FFilament
Created by PepperFM on 3/10/2024 in #❓┊help
Unit tests: fill multiselect manually
Hi everyone! I am trying to test the saving of a many-to-many relationship using multiple selection (common case: the user belongs to many categories), but I cannot figure out what data format this component accepts (key-value or something else)
$categories = Category::query()->inRandomOrder()->take(3)->get();
expect($this->user->categories->count())->toBe(0);
livewire(EditProfile::class)
->fillForm([
'categories' => $categories, // <--- this place i try to find out
])
->assertFormSet([
'categories' => $categories->pluck('name', 'id')->toArray(), // <--- this place i try to find out
])
->call('save');
expect($this->user->categories->count())->toBe(3);
$categories = Category::query()->inRandomOrder()->take(3)->get();
expect($this->user->categories->count())->toBe(0);
livewire(EditProfile::class)
->fillForm([
'categories' => $categories, // <--- this place i try to find out
])
->assertFormSet([
'categories' => $categories->pluck('name', 'id')->toArray(), // <--- this place i try to find out
])
->call('save');
expect($this->user->categories->count())->toBe(3);
I have tried various combinations and matching of the collection of input categories, but there is no data in the form (i dumped state via $this->form->getState() also in \Filament\Pages\Auth\EditProfile::save()) Ps: I don't have experience in Livewire
2 replies