A free open source IT asset/license management system
Fixed AlertMenu test
snipeb8f6a4294da3
diff --git a/resources/views/livewire/alert-menu.blade.php b/resources/views/livewire/alert-menu.blade.phpindex 05455e8477..c8ae26dd99 100644--- a/resources/views/livewire/alert-menu.blade.php+++ b/resources/views/livewire/alert-menu.blade.php@@ -9,8 +9,15 @@whether or not there are alerts. When count > 0, show thereal badge. When zero, hide with visibility (still occupieslayout width). Prevents the layout shift that would otherwise- happen when the lazy placeholder hydrates in. --}}- <span class="label label-danger" @if ($alert_count === 0) aria-hidden="true" style="visibility: hidden" @endif>{{ $alert_count ?: '0' }}</span>+ happen when the lazy placeholder hydrates in.++ Null-coalesce inline on ($alert_count ?? 0) is defensive.+ AlertMenu::render() always passes alert_count, but a Rollbar+ report from develop.snipeitapp.com showed+ "Undefined variable $alert_count" firing from a Livewire+ /livewire/update flow. Cheaper to guard the blade than to+ chase down which lifecycle path lost the data. --}}+ <span class="label label-danger" @if (($alert_count ?? 0) === 0) aria-hidden="true" style="visibility: hidden" @endif>{{ ($alert_count ?? 0) ?: '0' }}</span></a><ul class="dropdown-menu">diff --git a/tests/Feature/Livewire/AlertMenuTest.php b/tests/Feature/Livewire/AlertMenuTest.phpindex 72ac1522dd..b6a61d5c7e 100644--- a/tests/Feature/Livewire/AlertMenuTest.php+++ b/tests/Feature/Livewire/AlertMenuTest.php@@ -20,7 +20,22 @@ class AlertMenuTest extends TestCase{$placeholder = (new AlertMenu)->placeholder();+ // Placeholder icon deliberately matches whatever glyph the+ // loaded view (livewire/alert-menu.blade.php) renders via+ // <x-icon type="alerts"/>. IconHelper maps "alerts" to+ // fa-flag, so the placeholder uses fa-flag too — otherwise+ // hydration would visibly swap the icon on first paint.$this->assertStringContainsString('dropdown', $placeholder);- $this->assertStringContainsString('fa-bell', $placeholder);+ $this->assertStringContainsString('fa-flag', $placeholder);+ }++ public function test_placeholder_reserves_badge_footprint(): void+ {+ $placeholder = (new AlertMenu)->placeholder();++ // The hidden .label reserves badge width so hydration with+ // alerts does not push the surrounding top-nav items sideways.+ $this->assertStringContainsString('label label-danger', $placeholder);+ $this->assertStringContainsString('visibility: hidden', $placeholder);}}