Skip to content

Commit

Permalink
Breaking: The custom navigation item config now uses array inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Jul 10, 2024
1 parent b22c311 commit 7188b38
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ protected function generate(): void
$this->items->push(NavigationItem::create(DocumentationPage::home()));
}
} else {
collect(Config::getArray('hyde.navigation.custom', []))->each(function (NavigationItem $item): void {
collect(Config::getArray('hyde.navigation.custom', []))->each(function (array $item): void {
// Since these were added explicitly by the user, we can assume they should always be shown
$this->items->push($item);
$this->items->push(NavigationItem::create($item['destination'], $item['label'] ?? null, $item['priority'] ?? null));
});
}
}
Expand Down
45 changes: 38 additions & 7 deletions packages/framework/tests/Feature/NavigationMenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Hyde\Framework\Testing\Feature;

use Hyde\Hyde;
use Hyde\Facades\Navigation;
use Hyde\Support\Models\Route;
use Hyde\Foundation\Facades\Routes;
use Hyde\Framework\Features\Navigation\NavigationGroup;
Expand Down Expand Up @@ -91,9 +92,39 @@ public function testIsSortedAutomaticallyWhenUsingNavigationMenuCreate()
$this->assertEquals($expected, $menu->getItems());
}

public function testCanAddCustomLinksInConfig()
{
config(['hyde.navigation.custom' => [Navigation::item('foo', 'Foo')]]);

$menu = $this->createNavigationMenu();

$expected = collect([
NavigationItem::create(Routes::get('index')),
NavigationItem::create('foo', 'Foo'),
]);

$this->assertCount(count($expected), $menu->getItems());
$this->assertEquals($expected, $menu->getItems());
}

public function testCanAddCustomLinksInConfigAsArray()
{
config(['hyde.navigation.custom' => [['destination' => 'foo', 'label' => 'Foo']]]);

$menu = $this->createNavigationMenu();

$expected = collect([
NavigationItem::create(Routes::get('index')),
NavigationItem::create('foo', 'Foo'),
]);

$this->assertCount(count($expected), $menu->getItems());
$this->assertEquals($expected, $menu->getItems());
}

public function testExternalLinkCanBeAddedInConfig()
{
config(['hyde.navigation.custom' => [NavigationItem::create('https://example.com', 'foo')]]);
config(['hyde.navigation.custom' => [Navigation::item('https://example.com', 'foo')]]);

$menu = $this->createNavigationMenu();

Expand All @@ -108,7 +139,7 @@ public function testExternalLinkCanBeAddedInConfig()

public function testPathLinkCanBeAddedInConfig()
{
config(['hyde.navigation.custom' => [NavigationItem::create('foo', 'foo')]]);
config(['hyde.navigation.custom' => [Navigation::item('foo', 'foo')]]);

$menu = $this->createNavigationMenu();

Expand All @@ -124,8 +155,8 @@ public function testPathLinkCanBeAddedInConfig()
public function testDuplicatesAreNotRemovedWhenAddingInConfig()
{
config(['hyde.navigation.custom' => [
NavigationItem::create('foo', 'foo'),
NavigationItem::create('foo', 'foo'),
Navigation::item('foo', 'foo'),
Navigation::item('foo', 'foo'),
]]);

$menu = $this->createNavigationMenu();
Expand All @@ -143,8 +174,8 @@ public function testDuplicatesAreNotRemovedWhenAddingInConfig()
public function testDuplicatesAreNotRemovedWhenAddingInConfigRegardlessOfDestination()
{
config(['hyde.navigation.custom' => [
NavigationItem::create('foo', 'foo'),
NavigationItem::create('bar', 'foo'),
Navigation::item('foo', 'foo'),
Navigation::item('bar', 'foo'),
]]);

$menu = $this->createNavigationMenu();
Expand All @@ -163,7 +194,7 @@ public function testConfigItemsTakePrecedenceOverGeneratedItems()
{
$this->file('_pages/foo.md');

config(['hyde.navigation.custom' => [NavigationItem::create('bar', 'Foo')]]);
config(['hyde.navigation.custom' => [Navigation::item('bar', 'Foo')]]);

$menu = $this->createNavigationMenu();

Expand Down

0 comments on commit 7188b38

Please sign in to comment.