How should Laravel Nova resources be tested? Many of the examples i find online test Nova itself rather than the implementation of the developer.
1; What do i want to test?
- I don't trust myself when creating a migration, that Nova resources are being updated correctly.
- Ensuring the right rules are applied to a Nova resource.
- Ensure i'm able to persist the data ( if this isnt testing Nova itself )
- Anything else i might be forgetting, ( policies? )
2; In general, how much/far should you test nova?
3; Practical case;
Let's say i have a very simple resource called company:
class Company extends Model
{
protected $table = 'companies';
protected $fillable = [
'name',
'active'
];
}
And this is my Nova resource:
class Company extends Resource
{
public static $model = \App\Models\Company::class;
public function fields(Request $request)
{
return [
ID::make()->sortable(),
Text::make('name')
->rules('required', 'max:100'),
Boolean::make('active'),
Boolean::make('non_existing_field'),
Date::make('created_at')->readonly(),
HasMany::make('User'),
];
}
}
I can imagine i'd like to make sure that my name rule is correct, and make sure my non existing field is discovered so i can fix this.
At this point i havent really got a clue how to do this (Let alone in a best practice way). An example or/and an explanation would be very welcome and i hope this helps other people who are looking to start testing nova.
Thanks guys.