joshgaber / NovaUnit

Unit testing suite for Laravel Nova, built to extend PHPUnit
https://joshgaber.github.io/NovaUnit
MIT License
67 stars 23 forks source link

ResourceToolElement is counted in assertHasNoFields() but not returned in findField() #39

Closed dsamburskyi closed 2 years ago

dsamburskyi commented 3 years ago

We're using Devpartners\AuditableLog panel, which contains ResourceToolElements (extending Laravel\Nova\Fields\FieldElement). It's returned in $resource->component->fields() and thus being counted in assertHasNoFields()

    public function assertHasNoFields(string $message = ''): self
    {
        PHPUnit::assertCount(0, $this->component->fields(Request::createFromGlobals()), $message);

        return $this;
    }

but findField() function returns only fields extending Laravel\Nova\Fields\Field. So there's a disconnect between these two assertions. On one hand the 'field' is counted, but on the other hand it's not findable.

I may try to come up with a PR for this, but not sure what expected behavior is supposed to be, include Elements too or make assertHasNoFields() filter out non-Fields.

joshgaber commented 2 years ago

Hello, and thank you for your suggestion. I'm sorry to keep you waiting so long, but in case you are still curious about this, I wanted to take the time to answer.

When I first created this assertion, I had some components that had completely empty field sets; no fields, no field elements - just a title, some actions and filters. I don't work on that application anymore, and I'm not even sure why I insisted that the field list be just an empty array, I just remember that's why I wrote this assertion.

At this point, I don't know whether most developers would prefer that this method assert that the field list is empty, or that it just contains no Fields. However, I would be open to considering a PR if it could address both scenarios.

joshgaber commented 2 years ago

Closing due to inactivity