diff --git a/app/Livewire/NotificationCount.php b/app/Livewire/NotificationCount.php deleted file mode 100644 index 3eefbac5..00000000 --- a/app/Livewire/NotificationCount.php +++ /dev/null @@ -1,35 +0,0 @@ - 'updateCount', - ]; - - public function updateCount(int $count): int - { - return $count; - } - - public function render(): View - { - $this->count = Auth::user()->unreadNotifications()->count(); // @phpstan-ignore-line - - return view('livewire.notification-count', [ - 'count' => $this->count, - ]); - } -} diff --git a/app/Livewire/NotificationIndicator.php b/app/Livewire/NotificationIndicator.php deleted file mode 100644 index d7baa23b..00000000 --- a/app/Livewire/NotificationIndicator.php +++ /dev/null @@ -1,32 +0,0 @@ - 0; - } - - public function render(): View - { - $this->hasNotification = $this->setHasNotification( - Auth::user()->unreadNotifications()->count(), // @phpstan-ignore-line - ); - - return view('livewire.notification-indicator', [ - 'hasNotification' => $this->hasNotification, - ]); - } -} diff --git a/resources/views/livewire/notification-count.blade.php b/resources/views/livewire/notification-count.blade.php index 7e6ca155..4c160d61 100644 --- a/resources/views/livewire/notification-count.blade.php +++ b/resources/views/livewire/notification-count.blade.php @@ -1,3 +1,18 @@ + Auth::user()->unreadNotifications()->count()]); + +on(['NotificationMarkedAsRead' => fn (int $count) => $count ]); + +?> + {{ $count }} diff --git a/resources/views/livewire/notification-indicator.blade.php b/resources/views/livewire/notification-indicator.blade.php index 5591ac6b..65416902 100644 --- a/resources/views/livewire/notification-indicator.blade.php +++ b/resources/views/livewire/notification-indicator.blade.php @@ -1,3 +1,22 @@ + Auth::user()->unreadNotifications()->count() > 0 ]); + +on(['NotificationMarkedAsRead' => fn (int $count) => $count > 0 ]); + +?> + ! $hasNotification, + 'block' => $hasNotification, + ]) > diff --git a/tests/Feature/Livewire/Components/NotificationCountTest.php b/tests/Feature/Livewire/Components/NotificationCountTest.php new file mode 100644 index 00000000..8179bf18 --- /dev/null +++ b/tests/Feature/Livewire/Components/NotificationCountTest.php @@ -0,0 +1,19 @@ +user = $this->login(); +}); + +it('renders successfully', function (): void { + Volt::test('notification-count') + ->assertStatus(200); +}); + +it('can display user count notification', function (): void { + Volt::test('notification-count') + ->assertSee($this->user->unreadNotifications()->count()); +}); diff --git a/tests/Feature/Livewire/Components/NotificationIndicatorTest.php b/tests/Feature/Livewire/Components/NotificationIndicatorTest.php new file mode 100644 index 00000000..0791a500 --- /dev/null +++ b/tests/Feature/Livewire/Components/NotificationIndicatorTest.php @@ -0,0 +1,19 @@ +user = $this->login(); +}); + +it('renders successfully', function (): void { + Volt::test('notification-indicator') + ->assertStatus(200); +}); + +it('mask indicator if user can have unread notification', function (): void { + Volt::test('notification-indicator') + ->assertSet('hasNotification', false); +});