55 lines
1.9 KiB
PHP
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 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', '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);
|
|
});
|