F
Filament17mo ago
Mikazor

How to test that field hidden in infolist?

Test:
it('not shows empty description', function () {
$project = Project::factory()->create(['description' => null]);

livewire(ViewProject::class, [
'record' => $project->getRouteKey(),
])
->assertFormFieldIsHidden('description');
});
it('not shows empty description', function () {
$project = Project::factory()->create(['description' => null]);

livewire(ViewProject::class, [
'record' => $project->getRouteKey(),
])
->assertFormFieldIsHidden('description');
});
Resource:
public static function infolist(Infolist $infolist): Infolist
{
return $infolist->schema([
Infolists\Components\Section::make()->schema([
Infolists\Components\TextEntry::make('name'),
Infolists\Components\TextEntry::make('description')
->label(false)
->hidden(fn($record) => !$record->description)
->markdown()
->columnSpanFull(),
])
]);
}
public static function infolist(Infolist $infolist): Infolist
{
return $infolist->schema([
Infolists\Components\Section::make()->schema([
Infolists\Components\TextEntry::make('name'),
Infolists\Components\TextEntry::make('description')
->label(false)
->hidden(fn($record) => !$record->description)
->markdown()
->columnSpanFull(),
])
]);
}
Error:
Failed asserting that a field with the name [description] is hidden on the form named [form] on the [App\Filament\Resources\ProjectResource\Pages\ViewProject] component.
Failed asserting that a field with the name [description] is hidden on the form named [form] on the [App\Filament\Resources\ProjectResource\Pages\ViewProject] component.
8 Replies
Patrick Boivin
Patrick Boivin17mo ago
The infolist entry is not a form field, I'm not sure assertFormFieldIsHidden() applies here. Have you tried ->assertSee()? Or i guess ->assertDontSee() in this case...
Mikazor
MikazorOP17mo ago
As far as I know, assertSee is looking for text in HTML. My field is hidden and doesn't have a label so what do I need to assertSee or assertDontSee?
Miguel Bonifaz (Zilver)
As a last option you may want to use assertDontSeeHtml (?
Mikazor
MikazorOP17mo ago
But what HTML do I need to don't see?
Patrick Boivin
Patrick Boivin17mo ago
If you want to assert that an infolist entry is not visible, I'm thinking you can call ->assertDontSee($record->field_that_should_be_hidden) The label is not a bad idea, it depends on the context. But if the field has no label, then all you can really test is the value.
Mikazor
MikazorOP17mo ago
But the value is null. That's the point
Patrick Boivin
Patrick Boivin17mo ago
Well then, how is this test useful? You're basically testing that the hidden() method from Filament is working correctly... Filament already has a test for that.
Mikazor
MikazorOP17mo ago
hidden() has a conditional logic, I simplify an example

Did you find this page helpful?