[Tests] What's the way to fill a form that has a repeater ?
Im testing a relationManager and the create form has a repeater, im trying to fill the form with data but i'm having trouble filling the repeater.
I thought the right way to fill a repeater would be with a nested array, so that's what im feeding it with.
Upon running this test im getting
Any solution?
it('can add a new client employee', function (): void {
$client = Client::query()->first();
$deliveryAddress = DeliveryAddress::query()->first();
ArticleType::factory()->createOne();
$article = ArticleType::query()->first();
expect(ClientEmployee::query()->count())->toBe(0);
$sizes = [
[
"XL",
"article_type_id" => $article->id
]
,
[
"size" => "L",
"article_type_id" => $article->id
]
];
$page = livewire(EmployeesRelationManager::class, [
'ownerRecord' => $client,
'pageClass' => EditClient::class,
])
->mountTableAction('create');
$page->fillForm([
"name" => "New Name",
"client_id" => $client->id,
"delivery_address_id" => $deliveryAddress->id,
'default_article_sizes' => $sizes,
], "mountedTableActionForm");
$page->callMountedTableAction()->assertHasNoFormErrors([], "mountedTableActionForm");
expect(ClientEmployee::query()->count())->toBe(1);
});
it('can add a new client employee', function (): void {
$client = Client::query()->first();
$deliveryAddress = DeliveryAddress::query()->first();
ArticleType::factory()->createOne();
$article = ArticleType::query()->first();
expect(ClientEmployee::query()->count())->toBe(0);
$sizes = [
[
"XL",
"article_type_id" => $article->id
]
,
[
"size" => "L",
"article_type_id" => $article->id
]
];
$page = livewire(EmployeesRelationManager::class, [
'ownerRecord' => $client,
'pageClass' => EditClient::class,
])
->mountTableAction('create');
$page->fillForm([
"name" => "New Name",
"client_id" => $client->id,
"delivery_address_id" => $deliveryAddress->id,
'default_article_sizes' => $sizes,
], "mountedTableActionForm");
$page->callMountedTableAction()->assertHasNoFormErrors([], "mountedTableActionForm");
expect(ClientEmployee::query()->count())->toBe(1);
});
Component has errors: "mountedTableActionsData.0.default_article_sizes.5f9ffbdc-8423-4daf-bc6a-68027546f90a.article_type_id", "mountedTableActionsData.0.default_article_sizes.5f9ffbdc-8423-4daf-bc6a-68027546f90a.size", "mountedTableActionsData.0.default_article_sizes.0.size"
Failed asserting that false is true.
Component has errors: "mountedTableActionsData.0.default_article_sizes.5f9ffbdc-8423-4daf-bc6a-68027546f90a.article_type_id", "mountedTableActionsData.0.default_article_sizes.5f9ffbdc-8423-4daf-bc6a-68027546f90a.size", "mountedTableActionsData.0.default_article_sizes.0.size"
Failed asserting that false is true.
1 Reply
In this way, you populate a repeater; I haven't tested whether this also works in a relation manager.
livewire(CreateEmployee::class)
->fillForm([...])
->set('data.items', [
[
'name' => fake()->name,
'quantity' => fake()->randomNumber(1)
]
])
->call('create')
->assertHasNoFormErrors();
livewire(CreateEmployee::class)
->fillForm([...])
->set('data.items', [
[
'name' => fake()->name,
'quantity' => fake()->randomNumber(1)
]
])
->call('create')
->assertHasNoFormErrors();