Macro is not working when testing with Pest
Hello all I am using this plugin https://github.com/outer-web/filament-translatable-fields and when I want to write a test now I am getting the error that translatable does not exist. How to add the plugin also in the test environment?
Here is the error:
Illuminate\View\ViewException: Method Filament\Forms\Components\TextInput::translatable does not exist.
Here is the test:
GitHub
GitHub - outer-web/filament-translatable-fields
Contribute to outer-web/filament-translatable-fields development by creating an account on GitHub.
32 Replies
Do you have more than 1 panel? And is this your default panel?
Looking at the plugin, the Macro is registered during
Plugin::boot()
. So we need to figure out why the plugin is not booted.Yes I have mor than 1 panel, this is on my app panel and the other panel is the admin panel
I guess admin panel is the default one?
Ye indeed
But Plugin is registered on the AppPanelProvider
So you need to set the current panel. I found this in another thread:
https://discord.com/channels/883083792112300104/1169961796208185464/1170996029659820203
Thats already in my test
Where did you put this? Because it's not included in your code above?
Ah it is on a function i run before each test
Hm. Looks good to me. Can you make sure the code is running? And output
Filament::getCurrentPanel()
after setting it and just before your test code is running?
First log is giving admin and second one is giving app
And if you put it right before
livewire(CreateProductGroup::class)
? Is it still app?Yeah still app
Hm weird.
Let me reconstruct this quickly
When I ds in the boot function I don't get any log
Boot of the plugin? Yeah, that's what I am trying to figure out 😅
Yeah indeed 😄
What if you do it in
Filament\Panel::boot()
?
ds($this->id)
?Where to put this?
vendor/filament/filament/src/Panel.php
Ok, its logging nothing
and when going to the webpage it is logging correct
Hm. Actually I don't know where we are booting Panels. If you boot it manually that could work, but not sure whether that's the ideal solution:
Yeah thats working.
@Dan Harrin Sorry to tag you, but can you maybe shed some light on where Panels are booted and how we could test a different panel? Manual booting feels a bit hacky.
Really appreciate the help btw
I think this could be ok to use
panels are booted by middleware based on the current route
you could boot in the setUp() of the test case if you want it to apply to multiple tests
I thought so. But since we are directly testing the LW components there is no nicer way then manually setting the current panel and booting, right?
no, but as i said you can extract it
Solution
Yeah, I will just add to my setup before each test. This is working
Thanks for the help ❤️
Hi, Simon here, the developer of the package mentioned here.
I see a solution has been found. Is there anything I could change in the package itself to make this easier/better or am I registering the macro correctly in the
boot()
method of the plugin?