I’m building an admin panel, where a button is only visible if the user has a type of “Reader”. For that purpose I create a custom Blade if, what is look like this
Blade::if('reader', function () {
return auth()->check() && auth()->user()->user_type === 'reader';
});
This works well in action, but I want to write a test for it, and for that purpose I use Pest
, and my test looks like this
Livewire::actingAs($user) // user has a type of reader!
->test(UtilityMeterList::class)
->assertSee('createButton')
How I render the button:
@reader
<a type="button" class="createButton hidden md:block text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800" href={{ route('utility-meter.create') }}>
{{__('common.create_a_new_one')}}
</a>
@endreader
If I remove the custom if, the test is successfull, but if I don’t than the test fails. Try to change the custom blade if to gate, or a simple if, nothing works. From the error message it’s seems that Pest doesn’t processed the if’s statemants. Any idea or suggestion how can I write a test for this feature? Any help would appreciate.