FilamentF
Filament2y ago
Jo

Testing relation managers

I have followed the info at https://filamentphp.com/docs/3.x/panels/resources/relation-managers#conditionally-showing-relation-managers to conditionally show a relation manager. However, I am facing a problem where testing always passes even when the relation manager is not rendered.

As an extreme example, consider this code on the relation manager:

public static function canViewForRecord(Model $ownerRecord, string $pageClass): bool
{
    return false;
}


But this test passes:

use App\Filament\Resources\CategoryResource\Pages\EditCategory;
use function Pest\Livewire\livewire;
 
it('can render relation manager', function () {
    $category = Category::factory()
        ->has(Post::factory()->count(10))
        ->create();
 
    livewire(CategoryResource\RelationManagers\PostsRelationManager::class, [
        'ownerRecord' => $category,
        'pageClass' => EditCategory::class,
    ])
        ->assertSuccessful();
});


In fact, to be even more extreme, I went into the CategoryResource class and removed the getRelations() function entirely so now I definitely don't have any relation manager displaying but that test is still passing. The only way I can get the test to fail is by deleting the PostsRelationManager entirely.
Was this page helpful?