Skip to content

Commit

Permalink
Add configuration helper to the Navigation facade to create item array
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Jul 10, 2024
1 parent 17cd699 commit 5e27628
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
18 changes: 17 additions & 1 deletion packages/framework/src/Facades/Navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,26 @@

namespace Hyde\Facades;

use function compact;

/**
* General facade for navigation features.
*/
class Navigation
{
//
/**
* Configuration helper method to define a new navigation item, with better IDE support.
*
* The returned array will then be used by the framework to create a new NavigationItem instance.
*
* @see https://hydephp.com/docs/2.x/navigation-api
*
* @param string<\Hyde\Support\Models\RouteKey>|string $destination Route key, or an external URI.
* @param string|null $label If not provided, Hyde will try to get it from the route's connected page, or from the URL.
* @param int|null $priority If not provided, Hyde will try to get it from the route or the default priority of 500.
*/
public static function item(string $destination, ?string $label = null, ?int $priority = null): array
{
return compact('destination', 'label', 'priority');
}
}
23 changes: 22 additions & 1 deletion packages/framework/tests/Unit/Facades/NavigationFacadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,33 @@

namespace Hyde\Framework\Testing\Unit\Facades;

use Hyde\Facades\Navigation;
use Hyde\Testing\UnitTestCase;

/**
* @covers \Hyde\Facades\Navigation
*/
class NavigationFacadeTest extends UnitTestCase
{
//
public function testItem(): void
{
$item = Navigation::item('home', 'Home', 100);

$this->assertSame([
'destination' => 'home',
'label' => 'Home',
'priority' => 100,
], $item);
}

public function testItemWithOnlyDestination(): void
{
$item = Navigation::item('home');

$this->assertSame([
'destination' => 'home',
'label' => null,
'priority' => null,
], $item);
}
}

0 comments on commit 5e27628

Please sign in to comment.