Testing a TextInputColumn

Given I have a TextInputColumn. I want to test inputing values and other behaviour. Given I have TextInputColumn::make('amountOrdered')->label('ordered'), Now I want to write some tests around this. So I tried:
livewire(OrderItemResource\Pages\ListOrderItems::class)
->set('amountOrdered' , 1);
livewire(OrderItemResource\Pages\ListOrderItems::class)
->set('amountOrdered' , 1);
However this gives me an error:
FAILED Tests\Feature\OrderItemTest > it can propperly increase and decrease the product stock PublicPropertyNotFoundException
Unable to set component data. Public property [$amountOrdered] not found on component: [app.filament.resources.order-item-resource.pages.list-order-items]
FAILED Tests\Feature\OrderItemTest > it can propperly increase and decrease the product stock PublicPropertyNotFoundException
Unable to set component data. Public property [$amountOrdered] not found on component: [app.filament.resources.order-item-resource.pages.list-order-items]
Any suggestions?
Solution:
you can use updateTableColumnState ```php $column = 'name'; $record = 1;...
Jump to solution
6 Replies
JJSanders
JJSandersOP6mo ago
How would this work because when I do this:
livewire(OrderItemResource\Pages\ListOrderItems::class)
->assertCountTableRecords(1)
->assertTableColumnStateSet('delivered_quantity', 0, $item)
->fillForm(['amountOrdered' => 1]);
livewire(OrderItemResource\Pages\ListOrderItems::class)
->assertCountTableRecords(1)
->assertTableColumnStateSet('delivered_quantity', 0, $item)
->fillForm(['amountOrdered' => 1]);
I get FAILED Tests\Feature\OrderItemTest > it can propperly increase and decrease the product stock TypeError Filament\Resources\Pages\ListRecords::form(): Argument #1 ($form) must be of type Filament\Forms\Form, Filament\Infolists\Infolist given, called in /Users/jigalsanders/prive/weisz-watches-stock/vendor/filament/infolists/src/Concerns/InteractsWithInfolists.php on line 56 at vendor/filament/filament/src/Resources/Pages/ListRecords.php:99 95▕ default => null, 96▕ }; 97▕ } 98▕ ➜ 99▕ public function form(Form $form): Form 100▕ { 101▕ return static::getResource()::form($form); 102▕ } 103▕ Anyone?
Solution
LeandroFerreira
LeandroFerreira6mo ago
you can use updateTableColumnState
$column = 'name';
$record = 1;
$newValue = 'new value';

livewire(ListOrderItems::class)
->call('updateTableColumnState', $column, $record, $newValue);

assertDatabaseHas(OrderItem::class, [
'id' => $record,
'name' => $newValue
]);
$column = 'name';
$record = 1;
$newValue = 'new value';

livewire(ListOrderItems::class)
->call('updateTableColumnState', $column, $record, $newValue);

assertDatabaseHas(OrderItem::class, [
'id' => $record,
'name' => $newValue
]);
JJSanders
JJSandersOP6mo ago
Thanks for your reply. The column I use doesn't exist in the table but it does exist on the model. oh wait Maybe it does work
LeandroFerreira
LeandroFerreira6mo ago
what does it mean? 😅
JJSanders
JJSandersOP6mo ago
It works!!!! Thanks soo much
Want results from more Discord servers?
Add your server