use Inertia\Testing\AssertableInertia as Assert;
use Lunar\Core\Models\Customer;
use Lunar\Core\Models\Staff;
use Lunar\Tests\Panel\Fixtures\ExampleAddonTestCase;
uses(ExampleAddonTestCase::class);
it('renders the example add-on own page for an authenticated admin', function () {
$this->get('/panel/example-addon')->assertRedirect(route('panel.login'));
$staff = Staff::factory()->create(['admin' => true]);
$this->actingAs($staff, 'staff')
->get('/panel/example-addon')
->assertOk()
->assertInertia(fn (Assert $page) => $page
->component('example-addon::Widgets/Index', false)
->has('widgets', 3));
});
it('merges the example add-on table extension column onto the real customer index', function () {
$this->actingAs(Staff::factory()->create(['admin' => true]), 'staff');
Customer::factory()->create();
$this->get(route('panel.customers.index'))
->assertOk()
->assertInertia(fn (Assert $page) => $page
->where('columns', fn ($columns) => collect($columns)->pluck('key')->contains('id')));
});
it('shares the example add-on slot entry on the real customer edit page', function () {
$this->actingAs(Staff::factory()->create(['admin' => true]), 'staff');
$customer = Customer::factory()->create();
$this->get(route('panel.customers.edit', $customer))
->assertOk()
->assertInertia(fn (Assert $page) => $page
// The zone key contains dots ("customers.edit:main:after"), so it
// can't be reached via dot-notation where()/has() path assertions.
->where('slots', function ($slots) {
$zone = $slots->get('customers.edit:main:after');
return $zone !== null
&& collect($zone)->contains(fn ($entry) => $entry['component'] === 'example-addon::InfoBanner');
}));
});