Skip to content

Commit

Permalink
Breaking: Make NavItem::$label property protected
Browse files Browse the repository at this point in the history
  • Loading branch information
caendesilva committed Feb 19, 2024
1 parent e2a8f36 commit 5fa2bb2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
? '-ml-8 pl-4 py-1 px-2 block text-indigo-600 dark:text-indigo-400 dark:font-medium border-l-[0.325rem] border-indigo-500 transition-colors duration-300 ease-in-out hover:bg-black/10'
: '-ml-4 p-2 block hover:bg-black/5 dark:hover:bg-black/10 text-indigo-600 dark:text-indigo-400 dark:font-medium border-l-[0.325rem] border-indigo-500 transition-colors duration-300 ease-in-out'
])>
{{ $item->label }}
{{ $item->getLabel() }}
</a>

@if(config('docs.table_of_contents.enabled', true))
Expand All @@ -21,7 +21,7 @@
? '-ml-8 pl-4 py-1 px-2 block border-l-[0.325rem] border-transparent transition-colors duration-300 ease-in-out hover:bg-black/10'
: 'block -ml-4 p-2 border-l-[0.325rem] border-transparent hover:bg-black/5 dark:hover:bg-black/10'
])>
{{ $item->label }}
{{ $item->getLabel() }}
</a>
@endif
</li>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<a href="{{ $item }}" {!! $item->isCurrent() ? 'aria-current="page"' : '' !!} @class([
'block my-2 md:my-0 md:inline-block py-1 text-gray-700 hover:text-gray-900 dark:text-gray-100',
'border-l-4 border-indigo-500 md:border-none font-medium -ml-6 pl-5 md:ml-0 md:pl-0 bg-gray-100 dark:bg-gray-800 md:bg-transparent dark:md:bg-transparent' => $item->isCurrent()
])>{{ $item->label }}</a>
])>{{ $item->getLabel() }}</a>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
class NavItem implements Stringable
{
protected Route $destination;
public string $label;
protected string $label;
public int $priority;
public ?string $group;

Expand Down
6 changes: 3 additions & 3 deletions packages/framework/tests/Feature/NavigationMenuTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public function testItemsAreSortedByPriority()
Routes::addRoute(new Route(new MarkdownPage('bar', ['navigation.priority' => 2])));
Routes::addRoute(new Route(new MarkdownPage('baz', ['navigation.priority' => 3])));

$this->assertSame(['Home', 'Foo', 'Bar', 'Baz'], $this->createNavigationMenu()->getItems()->pluck('label')->toArray());
$this->assertSame(['Home', 'Foo', 'Bar', 'Baz'], $this->createNavigationMenu()->getItems()->map(fn ($item) => $item->getLabel())->toArray());
}

public function testItemsWithHiddenPropertySetToTrueAreNotAdded()
{
Routes::addRoute(new Route(new MarkdownPage('foo', ['navigation.hidden' => true])));
Routes::addRoute(new Route(new MarkdownPage('bar', ['navigation.hidden' => false])));

$this->assertSame(['Home', 'Bar'], $this->createNavigationMenu()->getItems()->pluck('label')->toArray());
$this->assertSame(['Home', 'Bar'], $this->createNavigationMenu()->getItems()->map(fn ($item) => $item->getLabel())->toArray());
}

public function testCreatedCollectionIsSortedByNavigationMenuPriority()
Expand Down Expand Up @@ -266,7 +266,7 @@ public function testCanAddItemsToMainNavigationMenuResolvedFromContainer()
$navigation->add(new NavItem(new ExternalRoute('/foo'), 'Foo'));

$this->assertCount(2, $navigation->getItems());
$this->assertSame('Foo', $navigation->getItems()->last()->label);
$this->assertSame('Foo', $navigation->getItems()->last()->getLabel());
}

protected function createNavigationMenu(): NavigationMenu
Expand Down
16 changes: 8 additions & 8 deletions packages/framework/tests/Unit/NavItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ public function testCanConstructWithChildren()
];
$item = new NavItem($route, 'Test', 500, null, $children);

$this->assertSame('Test', $item->label);
$this->assertSame('Test', $item->getLabel());
$this->assertSame($route, $item->getDestination());
$this->assertSame(500, $item->priority);

$this->assertCount(2, $item->children);
$this->assertSame($children, $item->children);

$this->assertSame('Foo', $item->children[0]->label);
$this->assertSame('Bar', $item->children[1]->label);
$this->assertSame('Foo', $item->children[0]->getLabel());
$this->assertSame('Bar', $item->children[1]->getLabel());

$this->assertSame('foo.html', $item->children[0]->getLink());
$this->assertSame('bar.html', $item->children[1]->getLink());
Expand All @@ -110,7 +110,7 @@ public function testCanConstructWithChildrenWithoutRoute()
];
$item = new NavItem('', 'Test', 500, null, $children);

$this->assertSame('Test', $item->label);
$this->assertSame('Test', $item->getLabel());
$this->assertSame('', $item->getDestination()->getLink());

$this->assertCount(2, $item->children);
Expand Down Expand Up @@ -186,7 +186,7 @@ public function testForLink()
$item = NavItem::forLink('foo', 'bar');

$this->assertEquals(new ExternalRoute('foo'), $item->getDestination());
$this->assertSame('bar', $item->label);
$this->assertSame('bar', $item->getLabel());
$this->assertSame(500, $item->priority);
}

Expand All @@ -201,7 +201,7 @@ public function testForRoute()
$item = NavItem::forRoute($route, 'foo');

$this->assertSame($route, $item->getDestination());
$this->assertSame('foo', $item->label);
$this->assertSame('foo', $item->getLabel());
$this->assertSame(999, $item->priority);
}

Expand All @@ -211,7 +211,7 @@ public function testForIndexRoute()
$item = NavItem::forRoute($route, 'foo');

$this->assertSame($route, $item->getDestination());
$this->assertSame('foo', $item->label);
$this->assertSame('foo', $item->getLabel());
$this->assertSame(0, $item->priority);
}

Expand Down Expand Up @@ -265,7 +265,7 @@ public function testDropdownFacade()
{
$item = NavItem::dropdown('foo', []);

$this->assertSame('foo', $item->label);
$this->assertSame('foo', $item->getLabel());
$this->assertSame([], $item->getChildren());
$this->assertSame(999, $item->priority);
}
Expand Down

0 comments on commit 5fa2bb2

Please sign in to comment.