Testing table set activeTab and toggle all columns

Currently setting the toggle session manually but wondering if that's a way of making this dynamic?
session(['tables' => ['ListProducts_toggled_columns' => ['name' => true]]]);
session(['tables' => ['ListProducts_toggled_columns' => ['name' => true]]]);
But how would you set the active tab?
$products = Collection::factory()->count(3)->create([
'type' => 'Group'
]);

Collection::factory()->count(3)->create([
'type' => 'Another Group'
])

livewire(ListProducts::class)
->assertCountTableRecords(3)
->assertCanSeeTableRecords($products)
->sortTable('name')
$products = Collection::factory()->count(3)->create([
'type' => 'Group'
]);

Collection::factory()->count(3)->create([
'type' => 'Another Group'
])

livewire(ListProducts::class)
->assertCountTableRecords(3)
->assertCanSeeTableRecords($products)
->sortTable('name')
E.g
public function getTabs(): array
{
return [
Tab::make('Test')
->modifyQueryUsing(fn (Builder $query) => $query->where('type', 'Group'))
];
}
public function getTabs(): array
{
return [
Tab::make('Test')
->modifyQueryUsing(fn (Builder $query) => $query->where('type', 'Group'))
];
}
Solution:
Cheers I found it was actually possible to set the property and the hook event for updatedActiveTab is called very easy/cool: ```php livewire(ListProducts::class) ->assertCountTableRecords(4) ->set('activeTab', 2)...
Jump to solution
3 Replies
gizmojo
gizmojo6mo ago
Bump - primarily in need of a way of testing the activeTab which is set on the resource. So can't find a way of setting this?
DrByte
DrByte6mo ago
IIRC when a tab is made active it's reflected in the page URL. Similarly for toggles. Can that be leveraged for your tests?
Solution
gizmojo
gizmojo6mo ago
Cheers I found it was actually possible to set the property and the hook event for updatedActiveTab is called very easy/cool:
livewire(ListProducts::class)
->assertCountTableRecords(4)
->set('activeTab', 2)
->assertCountTableRecords(2)
livewire(ListProducts::class)
->assertCountTableRecords(4)
->set('activeTab', 2)
->assertCountTableRecords(2)