Add menu sections, icons and order, and the simple view
This commit is contained in:
1 parent
362a5bce2e
commit
6f31a54818
23 files changed
+393
-45
No files matched your search
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
use IriksIT\Manager\Models\UserSetting;
|
||||
use IriksIT\Manager\Support\ModuleRegistry;
|
||||
use IriksIT\Manager\Tests\SimpleViewTestCase;
|
||||
|
||||
uses(SimpleViewTestCase::class);
|
||||
|
||||
function menuOf($test, $user): array
|
||||
{
|
||||
return $test->actingAs($user)->getJson('/manager')->assertOk()->json('navigation');
|
||||
}
|
||||
|
||||
it('puts sections, icons and order on the menu, and adds links of the site', function () {
|
||||
config(['manager.menu.links' => [['label' => 'Leads', 'url' => '/manager/leads', 'section' => 'Content', 'order' => 6, 'new_tab' => true]]]);
|
||||
config(['manager.menu.items' => [...config('manager.menu.items'), 'labels.index' => ['hidden' => true]]]);
|
||||
|
||||
$items = collect(app(ModuleRegistry::class)->navigation());
|
||||
|
||||
expect($items->first())->toMatchArray(['label' => 'Posts', 'section' => 'Content', 'icon' => 'file', 'order' => 5, 'simple' => true])
|
||||
->and($items->pluck('label')->slice(0, 2)->values()->all())->toBe(['Posts', 'Leads'])
|
||||
->and($items->pluck('label'))->not->toContain('Categories and tags')
|
||||
->and($items->firstWhere('label', 'Leads'))->toMatchArray(['url' => '/manager/leads', 'new_tab' => true]);
|
||||
});
|
||||
|
||||
it('keeps the old shape of a menu item working', function () {
|
||||
$item = collect(app(ModuleRegistry::class)->navigation())->firstWhere('label', 'Media');
|
||||
|
||||
expect($item)->toMatchArray(['label' => 'Media', 'permission' => 'media.view', 'simple' => false, 'order' => 100])
|
||||
->and($item['route'])->toBe('manager.media.index');
|
||||
});
|
||||
|
||||
it('shows an account with only the switch permission the simple face first, and lets it change', function () {
|
||||
$user = makeUser(['posts.view', 'media.view', 'manager.switch']);
|
||||
|
||||
expect(collect(menuOf($this, $user))->pluck('label')->all())->toBe(['Posts']);
|
||||
|
||||
$this->putJson('/manager/profile/view', ['view' => 'full'])->assertOk();
|
||||
|
||||
expect(collect(menuOf($this, $user))->pluck('label')->all())->toBe(['Posts', 'Media'])
|
||||
->and(UserSetting::query()->where('user_id', $user->id)->value('view'))->toBe('full');
|
||||
|
||||
$this->putJson('/manager/profile/view', ['view' => 'nonsense'])->assertUnprocessable();
|
||||
});
|
||||
|
||||
it('gives the full face to an account with the full permission, and the simple face to all others for good', function () {
|
||||
$full = makeUser(['posts.view', 'media.view', 'manager.full']);
|
||||
$plain = makeUser(['posts.view', 'media.view']);
|
||||
|
||||
expect(collect(menuOf($this, $full))->pluck('label')->all())->toBe(['Posts', 'Media']);
|
||||
expect(collect(menuOf($this, $plain))->pluck('label')->all())->toBe(['Posts']);
|
||||
|
||||
$this->putJson('/manager/profile/view', ['view' => 'full'])->assertForbidden();
|
||||
});
|
||||
|
||||
it('lets a super admin see everything and switch', function () {
|
||||
$admin = makeUser(superAdmin: true);
|
||||
|
||||
expect(collect(menuOf($this, $admin))->pluck('label'))->toContain('Posts', 'Media');
|
||||
|
||||
$this->putJson('/manager/profile/view', ['view' => 'simple'])->assertOk();
|
||||
|
||||
expect(collect(menuOf($this, $admin))->pluck('label')->all())->toBe(['Posts']);
|
||||
});
|
||||
|
||||
it('offers the two permissions in the group form only when the simple face is on', function () {
|
||||
expect(collect(app(ModuleRegistry::class)->permissionValues()))->toContain('manager.full', 'manager.switch');
|
||||
});
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Tests;
|
||||
|
||||
/** A site that turned the simple face of the manager on. */
|
||||
abstract class SimpleViewTestCase extends TestCase
|
||||
{
|
||||
protected function defineEnvironment($app): void
|
||||
{
|
||||
parent::defineEnvironment($app);
|
||||
|
||||
$app['config']->set('manager.simple_view', true);
|
||||
$app['config']->set('manager.menu.items', ['posts.index' => ['simple' => true, 'order' => 5, 'section' => 'Content', 'icon' => 'file']]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user