feat(sidebar) : expose GET /api/sidebar filtered by active modules
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Unit\Shared\Sidebar;
|
||||
|
||||
use App\Shared\Domain\Sidebar\SidebarFilter;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
final class SidebarFilterTest extends TestCase
|
||||
{
|
||||
public function testItemWithoutModuleIsAlwaysVisible(): void
|
||||
{
|
||||
$sections = [
|
||||
['label' => 'sidebar.core.section', 'icon' => 'mdi:home', 'items' => [
|
||||
['label' => 'sidebar.core.dashboard', 'to' => '/', 'icon' => 'mdi:view-dashboard'],
|
||||
]],
|
||||
];
|
||||
|
||||
$result = SidebarFilter::filter($sections, []);
|
||||
|
||||
self::assertCount(1, $result['sections']);
|
||||
self::assertSame('/', $result['sections'][0]['items'][0]['to']);
|
||||
self::assertSame([], $result['disabledRoutes']);
|
||||
self::assertArrayNotHasKey('module', $result['sections'][0]['items'][0]);
|
||||
}
|
||||
|
||||
public function testItemWithInactiveModuleIsHiddenAndRouteDisabled(): void
|
||||
{
|
||||
$sections = [
|
||||
['label' => 'sidebar.tt.section', 'icon' => 'mdi:clock', 'items' => [
|
||||
['label' => 'sidebar.tt.timesheet', 'to' => '/time-tracking', 'icon' => 'mdi:clock', 'module' => 'time_tracking'],
|
||||
]],
|
||||
];
|
||||
|
||||
$result = SidebarFilter::filter($sections, []);
|
||||
|
||||
self::assertSame([], $result['sections']);
|
||||
self::assertSame(['/time-tracking'], $result['disabledRoutes']);
|
||||
}
|
||||
|
||||
public function testItemWithActiveModuleIsVisible(): void
|
||||
{
|
||||
$sections = [
|
||||
['label' => 'sidebar.tt.section', 'icon' => 'mdi:clock', 'items' => [
|
||||
['label' => 'sidebar.tt.timesheet', 'to' => '/time-tracking', 'icon' => 'mdi:clock', 'module' => 'time_tracking'],
|
||||
]],
|
||||
];
|
||||
|
||||
$result = SidebarFilter::filter($sections, ['time_tracking']);
|
||||
|
||||
self::assertCount(1, $result['sections']);
|
||||
self::assertSame('/time-tracking', $result['sections'][0]['items'][0]['to']);
|
||||
self::assertSame([], $result['disabledRoutes']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user