F
Filament12mo ago
Hugo

[Testing] How to mount a table header action and make sure that the event was dispatched?

Im testing my application and currently testing a relation manager, but I'm having problems testing a table header action that creates a new record for that relation manager. It says that the event wasn't fired.
it('shows the create form for a new contract', function(): void {
$client = Client::query()->first();

livewire(ContractsRelationManager::class, [
'ownerRecord' => $client,
'pageClass' => EditClient::class,
])->assertSuccessful()
->assertTableHeaderActionsExistInOrder(['create'])
->mountAction('create')
->assertDispatched('open-modal');
});
it('shows the create form for a new contract', function(): void {
$client = Client::query()->first();

livewire(ContractsRelationManager::class, [
'ownerRecord' => $client,
'pageClass' => EditClient::class,
])->assertSuccessful()
->assertTableHeaderActionsExistInOrder(['create'])
->mountAction('create')
->assertDispatched('open-modal');
});
until the mountAction('create') the test run's fine but it then says it failed to assert that the event 'open-modal' was fired. Is there a way to test table header actions?
1 Reply
tim_vdv
tim_vdv12mo ago
Can't you just test if you can create a record through the relation manager?
it('can create contract', function(): void {
$client = Client::query()->first();

livewire(ContractsRelationManager::class, [
'ownerRecord' => $client,
'pageClass' => EditClient::class,
])->callTableAction(CreateAction::class, data: [
'name' => 'John',
])->assertHasNoTableActionErrors();;
});
it('can create contract', function(): void {
$client = Client::query()->first();

livewire(ContractsRelationManager::class, [
'ownerRecord' => $client,
'pageClass' => EditClient::class,
])->callTableAction(CreateAction::class, data: [
'name' => 'John',
])->assertHasNoTableActionErrors();;
});
Want results from more Discord servers?
Add your server