create(); $alice = User::factory()->create(['name' => 'Alice']); $post = Post::factory()->create(); $this->actingAs($user); Livewire::test(Comments::class, ['model' => $post]) ->set('commentData.body', '
Hey @Alice check this
') ->call('addComment'); $comment = Comment::first(); expect($comment->mentions)->toHaveCount(1); expect($comment->mentions->first()->id)->toBe($alice->id); }); it('stores mentions when editing comment with @mention', function () { $user = User::factory()->create(); $bob = User::factory()->create(['name' => 'Bob']); $post = Post::factory()->create(); $comment = Comment::factory()->create([ 'commentable_id' => $post->id, 'commentable_type' => $post->getMorphClass(), 'commenter_id' => $user->getKey(), 'commenter_type' => $user->getMorphClass(), 'body' => 'Original comment
', ]); $this->actingAs($user); Livewire::test(CommentItem::class, ['comment' => $comment]) ->call('startEdit') ->set('editData.body', 'Updated @Bob
') ->call('saveEdit'); $comment->refresh(); expect($comment->mentions)->toHaveCount(1); expect($comment->mentions->first()->id)->toBe($bob->id); });