getJson(route('notifications.index'))->assertUnauthorized(); } public function test_user_sees_only_their_notifications_and_can_mark_them_read(): void { $user = User::factory()->create(); $other = User::factory()->create(); $user->notify(new DashboardAlert('order', 'New Etsy order #1', 'Buyer ยท GBP 5.00', 'success', route('shipping'))); $other->notify(new DashboardAlert('order', 'Private', 'Not yours', 'info')); $response = $this->actingAs($user)->getJson(route('notifications.index'))->assertOk() ->assertJsonPath('unread', 1)->assertJsonCount(1, 'items') ->assertJsonPath('items.0.title', 'New Etsy order #1')->assertJsonPath('items.0.level', 'success'); $id = $response->json('items.0.id'); $this->actingAs($other)->postJson(route('notifications.read', $id))->assertOk(); $this->assertSame(1, $user->unreadNotifications()->count()); $this->actingAs($user)->postJson(route('notifications.read', $id))->assertOk(); $this->assertSame(0, $user->unreadNotifications()->count()); } public function test_mark_all_read_clears_the_unread_count(): void { $user = User::factory()->create(); $user->notify(new DashboardAlert('print', 'One', 'a')); $user->notify(new DashboardAlert('print', 'Two', 'b')); $this->actingAs($user)->postJson(route('notifications.read-all'))->assertOk(); $this->actingAs($user)->getJson(route('notifications.index'))->assertJsonPath('unread', 0); } public function test_pages_include_the_notification_bell(): void { $this->actingAs(User::factory()->create())->get(route('dashboard'))->assertOk() ->assertSee('data-notifications-toggle', false)->assertSee('data-toast-region', false); } }