Files
relaticle-comments/tests/Feature/MentionSearchTest.php
manukminasyan 6c96fb900b fix: update tests for RichEditor form data paths and service providers
Update all tests to use new form state paths (commentData.body,
editData.body, replyData.body) instead of removed public properties.
Remove searchUsers() tests (method replaced by MentionProvider).
Add BladeUI Icons service providers to TestCase for RichEditor views.
2026-03-27 19:20:56 +04:00

52 lines
1.6 KiB
PHP

<?php
use Livewire\Livewire;
use Relaticle\Comments\Livewire\CommentItem;
use Relaticle\Comments\Livewire\Comments;
use Relaticle\Comments\Models\Comment;
use Relaticle\Comments\Tests\Models\Post;
use Relaticle\Comments\Tests\Models\User;
it('stores mentions when creating comment with @mention', function () {
$user = User::factory()->create();
$alice = User::factory()->create(['name' => 'Alice']);
$post = Post::factory()->create();
$this->actingAs($user);
Livewire::test(Comments::class, ['model' => $post])
->set('commentData.body', '<p>Hey @Alice check this</p>')
->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' => '<p>Original comment</p>',
]);
$this->actingAs($user);
Livewire::test(CommentItem::class, ['comment' => $comment])
->call('startEdit')
->set('editData.body', '<p>Updated @Bob</p>')
->call('saveEdit');
$comment->refresh();
expect($comment->mentions)->toHaveCount(1);
expect($comment->mentions->first()->id)->toBe($bob->id);
});