Tests: assertActionDoesNotExist failing for DeleteAction

I have a simple test to check if my DeleteActions are being hidden appropriately for users that don't have the permission. This works fine in the app, but in my tests the assertions don't seem to behave the same way. My test is as follows (assuming I have a user with the relevant lack of permissions):
test('delete resource hidden', function () {
Livewire::actingAs($this->user)
->test(EditThing::class, ['record' => $this->thing->getRouteKey()])
->assertActionDoesNotExist(DeleteAction::class);
});
test('delete resource hidden', function () {
Livewire::actingAs($this->user)
->test(EditThing::class, ['record' => $this->thing->getRouteKey()])
->assertActionDoesNotExist(DeleteAction::class);
});
Assuming the ThingPolicy returns false for delete/deleteAny (which it does), why does the test always fail? To prove my point, I changed it to assertActionExists and it passes. I've tried to dive in to see where DeleteAction might check the relevant model policy but I can't find it.
1 Reply
ana
ana4mo ago
i ran into this just now. I was wondering if, in my action i am "only" using the hidden method to not show it, and if i was missing an additional method for the user to not be able to click (And the test pass). looking at the source, i think this is the assertion we where looking for: Filament\Actions\Testing\TestsActions::assertActionVisible
Want results from more Discord servers?
Add your server