Testing repeater

I have a repeater.
return TableRepeater::make('items')
->columnWidths([
'type' => '140px',
'quantity' => '100px',
'reference' => '100px',
'delivered_quantity' => '100px',
'created_at' => '120px',
'remarks' => '200px',
])
->relationship()
->schema(OrderItem::getForm())
->hideLabels()
->live(true)
->addable(fn ($record) => ! $record?->sent)
->addActionLabel('Rij toevoegen')
->columnSpan('full')
return TableRepeater::make('items')
->columnWidths([
'type' => '140px',
'quantity' => '100px',
'reference' => '100px',
'delivered_quantity' => '100px',
'created_at' => '120px',
'remarks' => '200px',
])
->relationship()
->schema(OrderItem::getForm())
->hideLabels()
->live(true)
->addable(fn ($record) => ! $record?->sent)
->addActionLabel('Rij toevoegen')
->columnSpan('full')
But when I try to test it, I get this error:
Property [$items] not found on component: [app.filament.resources.order-resource.pages.edit-order]

at vendor/livewire/livewire/src/Component.php:105
101▕
102▕ $value = $finish($value);
103▕
104▕ if ($value === 'noneset') {
➜ 105▕ throw new PropertyNotFoundException($property, $this->getName());
106▕ }
107▕
108▕ return $value;
109▕ }
Property [$items] not found on component: [app.filament.resources.order-resource.pages.edit-order]

at vendor/livewire/livewire/src/Component.php:105
101▕
102▕ $value = $finish($value);
103▕
104▕ if ($value === 'noneset') {
➜ 105▕ throw new PropertyNotFoundException($property, $this->getName());
106▕ }
107▕
108▕ return $value;
109▕ }
livewire(OrderResource\Pages\EditOrder::class,[
'record' => $order->id
])
->assertSee('Rij toevoegen')
->callFormComponentAction('items','add')
->assertFormExists()
->assertFormFieldExists('brand_id')
->set('items.0.product_id', $product->id)
->set('items.0.quantity', 5)
->set('items.0.type', OrderGoal::Stock)
->set('items.0.reference', 1000)
livewire(OrderResource\Pages\EditOrder::class,[
'record' => $order->id
])
->assertSee('Rij toevoegen')
->callFormComponentAction('items','add')
->assertFormExists()
->assertFormFieldExists('brand_id')
->set('items.0.product_id', $product->id)
->set('items.0.quantity', 5)
->set('items.0.type', OrderGoal::Stock)
->set('items.0.reference', 1000)
Any suggestions?
4 Replies
awcodes
awcodes5mo ago
Maybe the form doesn’t exist. Seems like your tests are out of order.
JJSanders
JJSanders4mo ago
So this works perfectly fine:
livewire(OrderResource\Pages\EditOrder::class,[
'record' => $order->id
])
->assertSee('Rij toevoegen')
->callFormComponentAction('items','add')
livewire(OrderResource\Pages\EditOrder::class,[
'record' => $order->id
])
->assertSee('Rij toevoegen')
->callFormComponentAction('items','add')
When I add:
->set('items.0.quantity', 5);
->set('items.0.quantity', 5);
I get an error that
Property [$items] not found on component: [app.filament.resources.order-resource.pages.edit-order
Property [$items] not found on component: [app.filament.resources.order-resource.pages.edit-order
I expect that the repeater is just part of the main form so it doesn't live on a separate form.
LeandroFerreira
LeandroFerreira4mo ago
try fillForm
->fillForm([
'items' => [
['product_id' => $product_id]
],
])
->fillForm([
'items' => [
['product_id' => $product_id]
],
])
JJSanders
JJSanders4mo ago
I tried this, The fillForm doesn't give any errors so seems to be ok but when I call the save method and then I check if there are no errors, it says there are: So
livewire(OrderResource\Pages\EditOrder::class,[
'record' => $order->id
])
->assertSee('Rij toevoegen')
->callFormComponentAction('items','add')
->fillForm([
[
'items' => [
'product_id' => $product->id,
'quantity' => 5,
'type' => OrderGoal::Stock,
'reference' => 12345
]
]
])
->call('save')
->assertHasNoFormErrors();
livewire(OrderResource\Pages\EditOrder::class,[
'record' => $order->id
])
->assertSee('Rij toevoegen')
->callFormComponentAction('items','add')
->fillForm([
[
'items' => [
'product_id' => $product->id,
'quantity' => 5,
'type' => OrderGoal::Stock,
'reference' => 12345
]
]
])
->call('save')
->assertHasNoFormErrors();
Returns:
FAILED Tests\Feature\OrderTest > it Show…
Component has errors: "data.items.2ed3d42c-427d-49cc-bfbe-bc6a47a58b8b.product_id", "data.items.2ed3d42c-427d-49cc-bfbe-bc6a47a58b8b.type", "data.items.2ed3d42c-427d-49cc-bfbe-bc6a47a58b8b.quantity", "data.items.2ed3d42c-427d-49cc-bfbe-bc6a47a58b8b.reference"
Failed asserting that false is true.

at vendor/livewire/livewire/src/Features/SupportValidation/TestsValidation.php:109
FAILED Tests\Feature\OrderTest > it Show…
Component has errors: "data.items.2ed3d42c-427d-49cc-bfbe-bc6a47a58b8b.product_id", "data.items.2ed3d42c-427d-49cc-bfbe-bc6a47a58b8b.type", "data.items.2ed3d42c-427d-49cc-bfbe-bc6a47a58b8b.quantity", "data.items.2ed3d42c-427d-49cc-bfbe-bc6a47a58b8b.reference"
Failed asserting that false is true.

at vendor/livewire/livewire/src/Features/SupportValidation/TestsValidation.php:109