Test: Route not defined

How should I approach this problem? I'm testing the admin panel, and it has a view route. However, when doing livewire(ListUsers::class), it throws this route not defined. I'm thinking Filament registers the route, but it's not yet registered in the tests
19 Replies
toeknee
toekneeβ€’2y ago
Filament does register the users, you shouldn't call the list class directly It would be: UsersResource::getUrl('index')
Ricardo Sawir
Ricardo SawirOPβ€’2y ago
But, how would that looked like when assertActionExists ? Interested about this since I have a complex logic happening in this ListUsers and this logic happened in the action
toeknee
toekneeβ€’2y ago
for insertAction I am unsure tbh, as my test use is limited. But you can test inserting users with the create page? UsersResource::getUrl('create') UsersResource::getUrl('edit', $record) etc
Ricardo Sawir
Ricardo SawirOPβ€’2y ago
that is fine though it's just that I put some logic in an Action, and now Im interested to know if it can be tested.... seems we need to use laravel's dusk?
toeknee
toekneeβ€’2y ago
Cool, I believe dusk is required. But I'll wait for someone else to help as I'm not familiar along those lines
Ricardo Sawir
Ricardo SawirOPβ€’2y ago
mentioning dusk only results in 2 answers only? haha
toeknee
toekneeβ€’2y ago
No one tests properly haha I got it now
Ricardo Sawir
Ricardo SawirOPβ€’2y ago
I felt spoiled with filament haha what's this?
toeknee
toekneeβ€’2y ago
See how it mentions ->callPageAction() with using pest πŸ˜‰
toeknee
toekneeβ€’2y ago
Use that basis but with this docs for v3: https://filamentphp.com/docs/3.x/panels/testing#deleting Hopefully that helps πŸ™‚
Ricardo Sawir
Ricardo SawirOPβ€’2y ago
I want to love that, but... the issue is still like this: it can access users… ViewException
Route [filament.admin.resources.users.view] not defined I believe the page component renders fine, and also, I am testing in tenancy panel I think it's quite an issue https://discord.com/channels/883083792112300104/883083792653381695/940589107149701160
Travis
Travisβ€’2y ago
@ricardosawir I am experiencing a similar problem....if not the same. I'm testing creating a resource in v3 with Tenancy....testing for a resource in a non-default panel.
Travis
Travisβ€’2y ago
I'm following the instructions here for creating a resource: https://filamentphp.com/docs/3.x/panels/testing#creating
Travis
Travisβ€’2y ago
The Create: Routing and render test (https://filamentphp.com/docs/3.x/panels/testing#routing--render-1) works...but I have to make sure I call Filament::setTenant(), otherwise it will fail.
Travis
Travisβ€’2y ago
What is your exact error...? Mine appears to be something having to do with rendering the blade file. It's looking for the route for the right resource, but using the wrong tenant:
Route [filament.admin.resources.postings.index] not defined. (View: /var/www/html/vendor/filament/filament/resources/views/components/page/index.blade.php)
Route [filament.admin.resources.postings.index] not defined. (View: /var/www/html/vendor/filament/filament/resources/views/components/page/index.blade.php)
It must be a bug...or something's missing from the documentation....or both. πŸ˜… Just to be clear...it's looking for this route: filament.admin.resources.postings.index But it should be looking for this route: filament.other-panel-name.resources.postings.index It's weird because the first part of the test -- and other tests -- seem to work once I call Filament::setTenant(). I just drilled down a bit...inside Filament\Resources\Resource::getUrl(), which is called when building the breadcrumbs, it has the right tenant, but the wrong panel. It gets the panel right under some circumstances, but not this one, apparently. I'm not sure what I need to do, if anything. Again, I might be missing something or the docs are missing something....or there's a bug. πŸ€” Seems like Filament::setCurrentPanel() does the trick. 😳
Ricardo Sawir
Ricardo SawirOPβ€’2y ago
oh nice @travis.elkins ! Your steps to get the error is almost identical to mine i only tried setTenant, and didn't work. The same route error
Travis
Travisβ€’2y ago
Did you try Filament::setCurrentPanel(), too...?

Did you find this page helpful?