Group the main menu into role-aware popover groups

Replace the flat link row with disclosure groups (Työt, Oma kirjaus,
Asiakkaat ja myynti, Hallinto, Ylläpito) built by App\View\MainMenu from
Gate abilities, and add menu links for new job, quick sales list and
workflow templates.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-24 19:14:11 +02:00
co-authored by Claude Sonnet 5.5
parent 18598cc08e
commit 48030e7689
10 changed files with 283 additions and 64 deletions
+54
View File
@@ -0,0 +1,54 @@
<?php
use App\Models\User;
use App\View\MainMenu;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
function menuGroupKeys(User $user): array
{
return array_column(app(MainMenu::class)->groups($user), 'key');
}
function menuLabels(User $user): array
{
return collect(app(MainMenu::class)->groups($user))->flatMap(fn ($group) => array_column($group['items'], 'label'))->all();
}
it('gives a subcontractor only work and own entries without creating jobs', function () {
$user = User::factory()->subcontractor()->create();
expect(menuGroupKeys($user))->toBe(['work', 'own'])
->and(menuLabels($user))->not->toContain('Uusi työ', 'Pikavastaanotto');
});
it('gives an employee work, own entries and customers and sales but no management groups', function () {
$user = User::factory()->create();
expect(menuGroupKeys($user))->toBe(['work', 'own', 'sales'])
->and(menuLabels($user))->toContain('Uusi työ', 'Pikamyynti', 'Hinnasto');
});
it('gives management the admin and maintenance groups but not user or company settings', function () {
$user = User::factory()->management()->create();
expect(menuGroupKeys($user))->toBe(['work', 'own', 'sales', 'admin', 'maintenance'])
->and(menuLabels($user))->toContain('Laskutus', 'Pohjatiedot', 'Työnkulkupohjat')
->and(menuLabels($user))->not->toContain('Käyttäjät', 'Yritystiedot');
});
it('gives an admin everything', function () {
$user = User::factory()->admin()->create();
expect(menuLabels($user))->toContain('Käyttäjät', 'Yritystiedot', 'Arkipyhät', 'Hinnaston ylläpito');
});
it('marks the group of the current page as current', function () {
$this->actingAs(User::factory()->admin()->create());
$this->get(route('users.index'))
->assertOk()
->assertSee('nykyinen osio')
->assertSee('aria-current="page"', false);
});