Test Livewire on a particular resource

Hi everyone. I'm trying to test my Livewire Component who handles user shortcuts to Filament resources. Here a part of my component, where I want to keep the current resource in a computed property. How can I test my Livewire component or the value of 'currentResource' with the context of the current resource (UserResource) in mind?
class UserShortcuts extends Component
{
// ...

#[Computed]
public function currentResource(): ?string
{
$controller = request()->route()->getController();

if (! is_null($controller) && method_exists($controller, 'getResource')) {
return $controller::getResource();
}

return null;
}

// ...
}
class UserShortcuts extends Component
{
// ...

#[Computed]
public function currentResource(): ?string
{
$controller = request()->route()->getController();

if (! is_null($controller) && method_exists($controller, 'getResource')) {
return $controller::getResource();
}

return null;
}

// ...
}
class UserShortcutsTest extends TestCase
{
// ...

public function test_current_resource_property_contains_current_resource(): void
{
$user = $this->createAdminUser();

$this->actingAs($user)
->get(UserResource::getUrl())
->assertOk()
->assertSeeLivewire(UserShortcuts::class);

// How can I test my Livewire component or the value of 'currentResource' with the context of the current resource (UserResource) in mind?
Livewire::actingAs($user)
->test(UserShortcuts::class)
->assertSet('currentRessource', UserResource::class);
}

// ...
}
class UserShortcutsTest extends TestCase
{
// ...

public function test_current_resource_property_contains_current_resource(): void
{
$user = $this->createAdminUser();

$this->actingAs($user)
->get(UserResource::getUrl())
->assertOk()
->assertSeeLivewire(UserShortcuts::class);

// How can I test my Livewire component or the value of 'currentResource' with the context of the current resource (UserResource) in mind?
Livewire::actingAs($user)
->test(UserShortcuts::class)
->assertSet('currentRessource', UserResource::class);
}

// ...
}
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?