Skip to content

elliottlawson/NovaGenie

Repository files navigation

A Fluent Laravel Nova Testing Utility

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Installation

You can install the package via composer:

composer require elliottlawson/novagenie

Usage

Asserting on Lenses

it('operates on lenses', function () {
    novaGenie()
        ->verifyLens(CustomersLens::class)
        ->hasFields([
            Text::class,
            DateTime::class,
        ])
        ->hasFilters([
            NameFilter::class,
            DateFilter::class,
        ])
        ->hasActions([
            UpdateName::class,
        ])
        ->hasCards([
            TopCustomers::class,
        ])
        ->hasUriKey('customers-lens')
        ->hasName('Customers');
});

Testing Menus

it('operates on menus', function () {
    novaGenie()
        ->accessingMenu(CustomerMenu::class)
        ->as(['editor', 'admin'])
        ->and(function () {
            // custom setup here
        })
        ->isVisible()
        ->isNotVisible()
        ->availableResourcesShouldBe([
            LensResouce::make(Customer::class, NewCustomers::class),
            LensResouce::make(Customer::class, TopCustomers::class),
        ])
        ->availableResourcesShouldNotBe([
            LensResouce::make(Customer::class, HighestRevenueCustomers::class),
        ]);
});

Testing Filters

it('operates on filters', function() {
    $options = novaGenie()->getFilterOptions(CustomerNameFilter::class);

    novaGenie()
        ->usingFilter(CustomerNameFilter::class)
        ->and(function() {
            Customer::factory()->count(10)->create();
        })
        ->on(Customer::query())
        ->withOption('John Doe')
        ->resultsIn(function (Collection $results) {
            $this->assertCount(1, $results);

            $results->each(fn (Customer $customer) => assertEquals('John Doe', $customer->name));
        });
});

Testing

composer test

License

The MIT License (MIT). Please see License File for more information.

About

A fluent Laravel Nova testing utility

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages