Darkloony
Darkloony
FFilament
Created by Akshay Bokade on 10/27/2023 in #❓┊help
How to write tests for create, edit and delete actions of Relation managers
For anyone who want to achieve the same thing testing the CreateAction:
it('can create a user', function (): void {
Notification::fake();

$tenant = createTenant();

livewire(UsersRelationManager::class, [
'ownerRecord' => $tenant,
'pageClass' => EditTenant::class,
])
->assertTableActionExists('create')
->mountTableAction(CreateAction::class)
->setTableActionData([
'name' => fake()->name(),
'email' => $email = fake()->email(),
])
->callMountedTableAction()
->assertHasNoTableActionErrors()
->assertSuccessful();

$user = User::query()->firstWhere(compact('email'));

Notification::assertSentTo($user, WelcomeNotification::class);
});
it('can create a user', function (): void {
Notification::fake();

$tenant = createTenant();

livewire(UsersRelationManager::class, [
'ownerRecord' => $tenant,
'pageClass' => EditTenant::class,
])
->assertTableActionExists('create')
->mountTableAction(CreateAction::class)
->setTableActionData([
'name' => fake()->name(),
'email' => $email = fake()->email(),
])
->callMountedTableAction()
->assertHasNoTableActionErrors()
->assertSuccessful();

$user = User::query()->firstWhere(compact('email'));

Notification::assertSentTo($user, WelcomeNotification::class);
});
6 replies