From 759c63a9354b6ff3955fb73fea0ad9e700441286 Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Wed, 13 Mar 2024 21:23:44 +0100 Subject: [PATCH] Refactor component to use attribute merging Create attribute bag in test setup Update test to expect cleaner HTML output --- .../views/components/navigation/navigation-link.blade.php | 6 ++++-- .../framework/tests/Unit/Views/NavigationLinkViewTest.php | 2 ++ .../framework/tests/Unit/Views/NavigationMenuViewTest.php | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/framework/resources/views/components/navigation/navigation-link.blade.php b/packages/framework/resources/views/components/navigation/navigation-link.blade.php index 207172ff4ea..0460e6fb38f 100644 --- a/packages/framework/resources/views/components/navigation/navigation-link.blade.php +++ b/packages/framework/resources/views/components/navigation/navigation-link.blade.php @@ -1,4 +1,6 @@ -isActive() ? 'aria-current="page"' : '' !!} @class([ +except('item')->class([ 'navigation-link block my-2 md:my-0 md:inline-block py-1 text-gray-700 hover:text-gray-900 dark:text-gray-100', 'navigation-link-active 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->isActive() -])>{{ $item->getLabel() }} \ No newline at end of file +])->merge([ + 'aria-current' => ($item->isActive() ? 'page' : false), +])) }}>{{ $item->getLabel() }} \ No newline at end of file diff --git a/packages/framework/tests/Unit/Views/NavigationLinkViewTest.php b/packages/framework/tests/Unit/Views/NavigationLinkViewTest.php index 53b3a14b553..14aa79c074a 100644 --- a/packages/framework/tests/Unit/Views/NavigationLinkViewTest.php +++ b/packages/framework/tests/Unit/Views/NavigationLinkViewTest.php @@ -5,6 +5,7 @@ namespace Hyde\Framework\Testing\Unit\Views; use Hyde\Foundation\Facades\Routes; +use Illuminate\View\ComponentAttributeBag; use Hyde\Framework\Features\Navigation\NavItem; use Hyde\Testing\TestCase; @@ -24,6 +25,7 @@ protected function render(?NavItem $item = null): string { return view('hyde::components.navigation.navigation-link', [ 'item' => $item ?? NavItem::forLink('foo.html', 'Foo'), + 'attributes' => new ComponentAttributeBag(), ])->render(); } diff --git a/packages/framework/tests/Unit/Views/NavigationMenuViewTest.php b/packages/framework/tests/Unit/Views/NavigationMenuViewTest.php index a40d6782b33..18d9bfd7cbf 100644 --- a/packages/framework/tests/Unit/Views/NavigationMenuViewTest.php +++ b/packages/framework/tests/Unit/Views/NavigationMenuViewTest.php @@ -73,7 +73,7 @@ public function testNavigationMenuWithRootPages() $contents = $foo->compile(); $this->assertStringContainsString('