F
Filament11mo ago
caglar

Testing copyableState() method in infolist

TextEntry::make('password')
->label('Password')
->getStateUsing(function ($record) {
$credential = $record->credentials()->where('loginunpw', 1)->first();

return $credential ? $credential->pass : 'No Password Found';
})
->formatStateUsing(fn ($state): string => Str::mask('secret', '*', 0))
->copyable()
->copyableState(fn (string $state): string => $state)
->copyMessage('Copied!'),
TextEntry::make('password')
->label('Password')
->getStateUsing(function ($record) {
$credential = $record->credentials()->where('loginunpw', 1)->first();

return $credential ? $credential->pass : 'No Password Found';
})
->formatStateUsing(fn ($state): string => Str::mask('secret', '*', 0))
->copyable()
->copyableState(fn (string $state): string => $state)
->copyMessage('Copied!'),
For above code I have a test
it('shows login credentials of an assets object', function () {
/** @var AssetsObject $object */
$object = AssetsObject::factory()
->has(IPv4::factory()
->state(['mainip' => 1]),
'ipv4Addresses'
)
->hasAttached(
Credential::factory(),
['loginunpw' => 1]
)
->create();

livewire(ViewObject::class, [
'record' => $object->getKey(),
])
->assertSuccessful()
->assertSeeText('Main IP')
->assertSeeText(long2ip($object->ipv4Addresses()->where('mainip', 1)->first()->startip))
->assertSeeText('User')
->assertSeeText($object->credentials()->where('loginunpw', 1)->first()->user)
->assertSeeText('Type')
->assertSeeText($object->credentials()->where('loginunpw', 1)->first()->credentialsType->name)
->assertSeeText('Password')
->assertSeeText('******');
});
it('shows login credentials of an assets object', function () {
/** @var AssetsObject $object */
$object = AssetsObject::factory()
->has(IPv4::factory()
->state(['mainip' => 1]),
'ipv4Addresses'
)
->hasAttached(
Credential::factory(),
['loginunpw' => 1]
)
->create();

livewire(ViewObject::class, [
'record' => $object->getKey(),
])
->assertSuccessful()
->assertSeeText('Main IP')
->assertSeeText(long2ip($object->ipv4Addresses()->where('mainip', 1)->first()->startip))
->assertSeeText('User')
->assertSeeText($object->credentials()->where('loginunpw', 1)->first()->user)
->assertSeeText('Type')
->assertSeeText($object->credentials()->where('loginunpw', 1)->first()->credentialsType->name)
->assertSeeText('Password')
->assertSeeText('******');
});
and I'd like to test
->copyableState(fn (string $state): string => $state)
->copyableState(fn (string $state): string => $state)
It copies password value to clipboard.
1 Reply
caglar
caglarOP11mo ago
Want results from more Discord servers?
Add your server