-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #231 from hydephp/refactor-navlinks
Refactor navigation link components
- Loading branch information
Showing
8 changed files
with
111 additions
and
17 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
packages/framework/resources/views/components/navigation/navigation-brand.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
<a aria-label="Home page link" href="{{ $navigation->getHomeLink($currentPage) }}" class="font-bold px-4"> | ||
{{ config('hyde.name', 'HydePHP') }} | ||
<a href="{{ $navigation->getHomeLink() }}" class="font-bold px-4" aria-label="Home page"> | ||
{{ config('hyde.name', 'HydePHP') }} | ||
</a> |
10 changes: 4 additions & 6 deletions
10
packages/framework/resources/views/components/navigation/navigation-link.blade.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
<a href="{{ $item->resolveLink($currentPage) }}" {{$item->isCurrent($page) ? '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($page) | ||
])> | ||
{{ $item->title }} | ||
</a> | ||
<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($page) | ||
])>{{ $item->title }}</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/framework/tests/Unit/Views/NavigationBrandViewTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Hyde\Framework\Testing\Unit\Views; | ||
|
||
use Hyde\Testing\TestCase; | ||
|
||
/** | ||
* @see resources/views/components/navigation/navigation-brand.blade.php | ||
*/ | ||
class NavigationBrandViewTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->mockRoute(); | ||
$this->mockPage(); | ||
} | ||
|
||
protected function render(): string | ||
{ | ||
return view('hyde::components.navigation.navigation-brand', [ | ||
'navigation' => \Hyde\Framework\Models\NavigationMenu::create(), | ||
])->render(); | ||
} | ||
|
||
public function test_component_links_to_home_route() | ||
{ | ||
$this->assertStringContainsString('href="index.html"', $this->render()); | ||
} | ||
|
||
public function test_component_uses_site_name() | ||
{ | ||
$this->assertStringContainsString('HydePHP', $this->render()); | ||
config(['hyde.name' => 'foo']); | ||
$this->assertStringContainsString('foo', $this->render()); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
packages/framework/tests/Unit/Views/NavigationLinkViewTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace Hyde\Framework\Testing\Unit\Views; | ||
|
||
use Hyde\Framework\Models\NavItem; | ||
use Hyde\Framework\Models\Route; | ||
use Hyde\Testing\TestCase; | ||
|
||
/** | ||
* @see resources/views/components/navigation/navigation-link.blade.php | ||
*/ | ||
class NavigationLinkViewTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->mockRoute(); | ||
$this->mockPage(); | ||
} | ||
|
||
protected function render(?NavItem $item = null): string | ||
{ | ||
return view('hyde::components.navigation.navigation-link', [ | ||
'item' => $item ?? NavItem::toLink('foo.html', 'Foo'), | ||
])->render(); | ||
} | ||
|
||
public function test_component_links_to_route_destination() | ||
{ | ||
$this->assertStringContainsString('href="foo.html"', $this->render()); | ||
} | ||
|
||
public function test_component_uses_title() | ||
{ | ||
$this->assertStringContainsString('Foo', $this->render()); | ||
} | ||
|
||
public function test_component_is_current_when_current_route_matches() | ||
{ | ||
$this->mockRoute(Route::get('index')); | ||
$this->assertStringContainsString('current', $this->render(NavItem::toRoute(Route::get('index'), 'Home'))); | ||
} | ||
|
||
public function test_component_has_aria_current_when_current_route_matches() | ||
{ | ||
$this->mockRoute(Route::get('index')); | ||
$this->assertStringContainsString('aria-current="page"', $this->render(NavItem::toRoute(Route::get('index'), 'Home'))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters