Skip to content

Commit

Permalink
Merge branch 'master' into 2.x-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Apr 30, 2024
2 parents 3833e22 + 3d2d696 commit 45397da
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/framework/tests/Feature/NavigationMenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,38 @@ protected function createNavigationMenu(): MainNavigationMenu
{
return NavigationMenuGenerator::handle(MainNavigationMenu::class);
}

public function testHasDropdownsReturnsTrueWhenGroupIsExplicitlySetInFrontMatter()
{
config(['hyde.navigation.subdirectories' => 'hidden']);

Routes::addRoute((new MarkdownPage('foo', matter: ['navigation.group' => 'test-group']))->getRoute());

$this->assertTrue(NavigationMenu::create()->hasDropdowns());
}

public function testGetDropdownsReturnsCorrectArrayWhenGroupIsExplicitlySetInFrontMatter()
{
config(['hyde.navigation.subdirectories' => 'hidden']);

Routes::addRoute((new MarkdownPage('foo', matter: ['navigation.group' => 'test-group']))->getRoute());

$menu = NavigationMenu::create();
$this->assertCount(1, $menu->getDropdowns());

$this->assertEquals([
DropdownNavItem::fromArray('test-group', [
NavItem::fromRoute((new MarkdownPage('foo'))->getRoute()),
]),
], $menu->getDropdowns());
}

public function testHasDropdownsReturnsFalseWhenGroupIsNotExplicitlySetInFrontMatter()
{
config(['hyde.navigation.subdirectories' => 'hidden']);

Routes::addRoute((new MarkdownPage('foo'))->getRoute());
$menu = NavigationMenu::create();
$this->assertFalse($menu->hasDropdowns());
}
}
35 changes: 35 additions & 0 deletions packages/framework/tests/Unit/NavigationDataFactoryUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,36 @@ public function testSearchForHiddenInConfigsSelectsCorrectConfigurationBasedOnPa
$this->assertFalse($factory->makeHidden());
}

public function testMakeGroupUsesFrontMatterGroupIfSet()
{
$frontMatter = new FrontMatter(['navigation.group' => 'Test Group']);
$coreDataObject = new CoreDataObject($frontMatter, new Markdown(), MarkdownPage::class, 'test.md', '', '', '');
$factory = new NavigationConfigTestClass($coreDataObject);

$this->assertSame('Test Group', $factory->makeGroup());
}

public function testMakeGroupUsesFrontMatterGroupIfSetRegardlessOfSubdirectoryConfiguration()
{
self::mockConfig(['hyde.navigation.subdirectories' => 'hidden']);

$frontMatter = new FrontMatter(['navigation.group' => 'Test Group']);
$coreDataObject = new CoreDataObject($frontMatter, new Markdown(), MarkdownPage::class, 'test.md', '', '', '');
$factory = new NavigationConfigTestClass($coreDataObject);

$this->assertSame('Test Group', $factory->makeGroup());
}

public function testMakeGroupDefaultsToNullIfFrontMatterGroupNotSetAndSubdirectoriesNotUsed()
{
self::mockConfig(['hyde.navigation.subdirectories' => 'hidden']);

$coreDataObject = new CoreDataObject(new FrontMatter(), new Markdown(), MarkdownPage::class, 'test.md', '', '', '');
$factory = new NavigationConfigTestClass($coreDataObject);

$this->assertNull($factory->makeGroup());
}

protected function makeCoreDataObject(string $identifier = '', string $routeKey = '', string $pageClass = MarkdownPage::class): CoreDataObject
{
return new CoreDataObject(new FrontMatter(), new Markdown(), $pageClass, $identifier, '', '', $routeKey);
Expand Down Expand Up @@ -264,4 +294,9 @@ public function makeHidden(): bool
{
return parent::makeHidden();
}

public function makeGroup(): ?string
{
return parent::makeGroup();
}
}

0 comments on commit 45397da

Please sign in to comment.