Files
Toiminnanohjaus/tests/Feature/MainMenuTest.php
T
petriandClaude Sonnet 5.5 64f1e7c54a Add Reports module with the hours by person report
Management's reports (spec 13) get their own module that reads the other
modules through ports. The first report sums hours by person in a period,
narrowed by service unit or customer, with breakdowns, a chart and CSV.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-25 08:39:19 +02:00

55 lines
1.9 KiB
PHP

<?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, reports and maintenance groups but not user or company settings', function () {
$user = User::factory()->management()->create();
expect(menuGroupKeys($user))->toBe(['work', 'own', 'sales', 'admin', 'reports', 'maintenance'])
->and(menuLabels($user))->toContain('Laskutus', 'Tunnit henkilöittäin', '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);
});