diff --git a/tests/Feature/AttachmentUploadTest.php b/tests/Feature/AttachmentUploadTest.php index d2878ff..904a701 100644 --- a/tests/Feature/AttachmentUploadTest.php +++ b/tests/Feature/AttachmentUploadTest.php @@ -22,10 +22,9 @@ it('creates comment with file attachment via Livewire component', function () { $file = UploadedFile::fake()->image('photo.jpg', 100, 100); Livewire::test(Comments::class, ['model' => $post]) - ->set('newComment', '
Comment with attachment
') + ->set('commentData.body', 'Comment with attachment
') ->set('attachments', [$file]) ->call('addComment') - ->assertSet('newComment', '') ->assertSet('attachments', []); expect(Comment::count())->toBe(1); @@ -43,7 +42,7 @@ it('stores attachment with correct metadata', function () { $file = UploadedFile::fake()->image('vacation.jpg', 200, 200)->size(512); Livewire::test(Comments::class, ['model' => $post]) - ->set('newComment', 'Vacation photos
') + ->set('commentData.body', 'Vacation photos
') ->set('attachments', [$file]) ->call('addComment'); @@ -69,7 +68,7 @@ it('stores file on configured disk at comments/attachments/{comment_id}/ path', $file = UploadedFile::fake()->image('test.png', 50, 50); Livewire::test(Comments::class, ['model' => $post]) - ->set('newComment', 'File path test
') + ->set('commentData.body', 'File path test
') ->set('attachments', [$file]) ->call('addComment'); @@ -160,7 +159,7 @@ it('rejects file exceeding max size', function () { $oversizedFile = UploadedFile::fake()->create('big.pdf', CommentsConfig::getAttachmentMaxSize() + 1, 'application/pdf'); Livewire::test(Comments::class, ['model' => $post]) - ->set('newComment', 'Oversized file
') + ->set('commentData.body', 'Oversized file
') ->set('attachments', [$oversizedFile]) ->call('addComment') ->assertHasErrors('attachments.0'); @@ -180,7 +179,7 @@ it('rejects disallowed file type', function () { $exeFile = UploadedFile::fake()->create('script.exe', 100, 'application/x-msdownload'); Livewire::test(Comments::class, ['model' => $post]) - ->set('newComment', 'Malicious file
') + ->set('commentData.body', 'Malicious file
') ->set('attachments', [$exeFile]) ->call('addComment') ->assertHasErrors('attachments.0'); @@ -200,7 +199,7 @@ it('accepts allowed file types', function () { $imageFile = UploadedFile::fake()->image('photo.jpg', 100, 100); Livewire::test(Comments::class, ['model' => $post]) - ->set('newComment', 'Valid file
') + ->set('commentData.body', 'Valid file
') ->set('attachments', [$imageFile]) ->call('addComment') ->assertHasNoErrors('attachments.0'); @@ -243,7 +242,7 @@ it('creates comment with multiple file attachments', function () { $file2 = UploadedFile::fake()->create('notes.pdf', 512, 'application/pdf'); Livewire::test(Comments::class, ['model' => $post]) - ->set('newComment', 'Multiple files
') + ->set('commentData.body', 'Multiple files
') ->set('attachments', [$file1, $file2]) ->call('addComment'); @@ -276,11 +275,10 @@ it('creates reply with file attachment via CommentItem component', function () { Livewire::test(CommentItem::class, ['comment' => $comment]) ->call('startReply') - ->set('replyBody', 'Reply with attachment
') + ->set('replyData.body', 'Reply with attachment
') ->set('replyAttachments', [$file]) ->call('addReply') ->assertSet('isReplying', false) - ->assertSet('replyBody', '') ->assertSet('replyAttachments', []); $reply = Comment::where('parent_id', $comment->id)->first(); diff --git a/tests/Feature/CommentEventsTest.php b/tests/Feature/CommentEventsTest.php index 5688f0f..647fac4 100644 --- a/tests/Feature/CommentEventsTest.php +++ b/tests/Feature/CommentEventsTest.php @@ -20,7 +20,7 @@ it('fires CommentCreated event when adding a comment', function () { $this->actingAs($user); Livewire::test(Comments::class, ['model' => $post]) - ->set('newComment', 'New comment
') + ->set('commentData.body', 'New comment
') ->call('addComment'); Event::assertDispatched(CommentCreated::class, function (CommentCreated $event) use ($post) { @@ -47,7 +47,7 @@ it('fires CommentUpdated event when editing a comment', function () { Livewire::test(CommentItem::class, ['comment' => $comment]) ->call('startEdit') - ->set('editBody', 'Edited
') + ->set('editData.body', 'Edited
') ->call('saveEdit'); Event::assertDispatched(CommentUpdated::class, function (CommentUpdated $event) use ($comment) { @@ -95,7 +95,7 @@ it('fires CommentCreated event when adding a reply', function () { Livewire::test(CommentItem::class, ['comment' => $comment]) ->call('startReply') - ->set('replyBody', 'Reply text
') + ->set('replyData.body', 'Reply text
') ->call('addReply'); Event::assertDispatched(CommentCreated::class, function (CommentCreated $event) use ($comment) { @@ -113,7 +113,7 @@ it('carries correct comment and commentable in event payload', function () { $this->actingAs($user); Livewire::test(Comments::class, ['model' => $post]) - ->set('newComment', 'Payload test
') + ->set('commentData.body', 'Payload test
') ->call('addComment'); Event::assertDispatched(CommentCreated::class, function (CommentCreated $event) use ($post, $user) { diff --git a/tests/Feature/CommentItemComponentTest.php b/tests/Feature/CommentItemComponentTest.php index f3935ed..6c06a49 100644 --- a/tests/Feature/CommentItemComponentTest.php +++ b/tests/Feature/CommentItemComponentTest.php @@ -23,11 +23,9 @@ it('allows author to start and save edit on their comment', function () { Livewire::test(CommentItem::class, ['comment' => $comment]) ->call('startEdit') ->assertSet('isEditing', true) - ->assertSet('editBody', 'Original body
') - ->set('editBody', 'Updated body
') + ->set('editData.body', 'Updated body
') ->call('saveEdit') - ->assertSet('isEditing', false) - ->assertSet('editBody', ''); + ->assertSet('isEditing', false); $comment->refresh(); @@ -53,7 +51,7 @@ it('marks edited comment with edited indicator', function () { Livewire::test(CommentItem::class, ['comment' => $comment]) ->call('startEdit') - ->set('editBody', 'Changed
') + ->set('editData.body', 'Changed
') ->call('saveEdit'); $comment->refresh(); @@ -160,10 +158,9 @@ it('allows user to reply to a comment', function () { Livewire::test(CommentItem::class, ['comment' => $comment]) ->call('startReply') ->assertSet('isReplying', true) - ->set('replyBody', 'My reply
') + ->set('replyData.body', 'My reply
') ->call('addReply') - ->assertSet('isReplying', false) - ->assertSet('replyBody', ''); + ->assertSet('isReplying', false); $reply = Comment::where('parent_id', $comment->id)->first(); @@ -213,8 +210,7 @@ it('resets state when cancelling edit', function () { ->call('startEdit') ->assertSet('isEditing', true) ->call('cancelEdit') - ->assertSet('isEditing', false) - ->assertSet('editBody', ''); + ->assertSet('isEditing', false); }); it('resets state when cancelling reply', function () { @@ -233,10 +229,9 @@ it('resets state when cancelling reply', function () { Livewire::test(CommentItem::class, ['comment' => $comment]) ->call('startReply') ->assertSet('isReplying', true) - ->set('replyBody', 'Draft reply
') + ->set('replyData.body', 'Draft reply
') ->call('cancelReply') - ->assertSet('isReplying', false) - ->assertSet('replyBody', ''); + ->assertSet('isReplying', false); }); it('loads all replies within a thread eagerly', function () { diff --git a/tests/Feature/CommentsComponentTest.php b/tests/Feature/CommentsComponentTest.php index a561443..3522df0 100644 --- a/tests/Feature/CommentsComponentTest.php +++ b/tests/Feature/CommentsComponentTest.php @@ -13,9 +13,8 @@ it('allows authenticated user to create a comment on a post', function () { $this->actingAs($user); Livewire::test(Comments::class, ['model' => $post]) - ->set('newComment', 'Hello World
') - ->call('addComment') - ->assertSet('newComment', ''); + ->set('commentData.body', 'Hello World
') + ->call('addComment'); expect(Comment::count())->toBe(1); expect(Comment::first()->body)->toBe('Hello World
'); @@ -28,7 +27,7 @@ it('associates new comment with the authenticated user', function () { $this->actingAs($user); Livewire::test(Comments::class, ['model' => $post]) - ->set('newComment', 'Test
') + ->set('commentData.body', 'Test
') ->call('addComment'); $comment = Comment::first(); @@ -43,7 +42,7 @@ it('requires authentication to create a comment', function () { $post = Post::factory()->create(); Livewire::test(Comments::class, ['model' => $post]) - ->set('newComment', 'Hello
') + ->set('commentData.body', 'Hello
') ->call('addComment') ->assertForbidden(); }); @@ -55,9 +54,9 @@ it('validates that comment body is not empty', function () { $this->actingAs($user); Livewire::test(Comments::class, ['model' => $post]) - ->set('newComment', '') + ->set('commentData.body', '') ->call('addComment') - ->assertHasErrors('newComment'); + ->assertHasErrors('commentData.body'); expect(Comment::count())->toBe(0); }); diff --git a/tests/Feature/ContentSanitizationTest.php b/tests/Feature/ContentSanitizationTest.php index e679822..e49a302 100644 --- a/tests/Feature/ContentSanitizationTest.php +++ b/tests/Feature/ContentSanitizationTest.php @@ -162,7 +162,7 @@ it('sanitizes content submitted through livewire component', function () { $this->actingAs($user); Livewire::test(Comments::class, ['model' => $post]) - ->set('newComment', 'Hello
') + ->set('commentData.body', 'Hello
') ->call('addComment'); $comment = Comment::first(); diff --git a/tests/Feature/MentionDisplayTest.php b/tests/Feature/MentionDisplayTest.php index 9771f5f..fe96f86 100644 --- a/tests/Feature/MentionDisplayTest.php +++ b/tests/Feature/MentionDisplayTest.php @@ -16,7 +16,7 @@ it('renders mention with styled span', function () { 'commentable_type' => $post->getMorphClass(), 'commenter_id' => $user->getKey(), 'commenter_type' => $user->getMorphClass(), - 'body' => '@Alice said hi
', + 'body' => '@Alice said hi', ]); $comment->mentions()->attach($alice->id, ['commenter_type' => $alice->getMorphClass()]); @@ -38,7 +38,7 @@ it('renders multiple mentions with styled spans', function () { 'commentable_type' => $post->getMorphClass(), 'commenter_id' => $user->getKey(), 'commenter_type' => $user->getMorphClass(), - 'body' => '@Alice and @Bob
', + 'body' => '@Alice and @Bob', ]); $comment->mentions()->attach($alice->id, ['commenter_type' => $alice->getMorphClass()]); @@ -60,7 +60,7 @@ it('does not style non-mentioned @text', function () { 'commentable_type' => $post->getMorphClass(), 'commenter_id' => $user->getKey(), 'commenter_type' => $user->getMorphClass(), - 'body' => '@ghost is not here
', + 'body' => '@ghost is not here', ]); $rendered = $comment->renderBodyWithMentions(); @@ -78,7 +78,7 @@ it('renders comment-mention class in Livewire component', function () { 'commentable_type' => $post->getMorphClass(), 'commenter_id' => $user->getKey(), 'commenter_type' => $user->getMorphClass(), - 'body' => 'Hello @Alice
', + 'body' => 'Hello @Alice', ]); $comment->mentions()->attach($alice->id, ['commenter_type' => $alice->getMorphClass()]); diff --git a/tests/Feature/MentionSearchTest.php b/tests/Feature/MentionSearchTest.php index 45b4089..c6b0a06 100644 --- a/tests/Feature/MentionSearchTest.php +++ b/tests/Feature/MentionSearchTest.php @@ -7,66 +7,6 @@ use Relaticle\Comments\Models\Comment; use Relaticle\Comments\Tests\Models\Post; use Relaticle\Comments\Tests\Models\User; -it('returns matching users for search query', function () { - $alice = User::factory()->create(['name' => 'Alice']); - User::factory()->create(['name' => 'Bob']); - $post = Post::factory()->create(); - - $this->actingAs($alice); - - $component = Livewire::test(Comments::class, ['model' => $post]); - $results = $component->instance()->searchUsers('Ali'); - - expect($results)->toHaveCount(1); - expect($results[0])->toMatchArray([ - 'id' => $alice->id, - 'name' => 'Alice', - ]); - expect($results[0])->toHaveKey('avatar_url'); -}); - -it('returns empty array for empty query', function () { - $user = User::factory()->create(); - $post = Post::factory()->create(); - - $this->actingAs($user); - - $component = Livewire::test(Comments::class, ['model' => $post]); - $results = $component->instance()->searchUsers(''); - - expect($results)->toBeEmpty(); -}); - -it('returns empty array for no matches', function () { - $user = User::factory()->create(['name' => 'Alice']); - $post = Post::factory()->create(); - - $this->actingAs($user); - - $component = Livewire::test(Comments::class, ['model' => $post]); - $results = $component->instance()->searchUsers('zzz'); - - expect($results)->toBeEmpty(); -}); - -it('limits search results to configured max', function () { - $user = User::factory()->create(['name' => 'Admin']); - $post = Post::factory()->create(); - - for ($i = 1; $i <= 10; $i++) { - User::factory()->create(['name' => "Test User {$i}"]); - } - - config(['comments.mentions.max_results' => 3]); - - $this->actingAs($user); - - $component = Livewire::test(Comments::class, ['model' => $post]); - $results = $component->instance()->searchUsers('Test'); - - expect($results)->toHaveCount(3); -}); - it('stores mentions when creating comment with @mention', function () { $user = User::factory()->create(); $alice = User::factory()->create(['name' => 'Alice']); @@ -75,7 +15,7 @@ it('stores mentions when creating comment with @mention', function () { $this->actingAs($user); Livewire::test(Comments::class, ['model' => $post]) - ->set('newComment', 'Hey @Alice check this
') + ->set('commentData.body', 'Hey @Alice check this
') ->call('addComment'); $comment = Comment::first(); @@ -101,7 +41,7 @@ it('stores mentions when editing comment with @mention', function () { Livewire::test(CommentItem::class, ['comment' => $comment]) ->call('startEdit') - ->set('editBody', 'Updated @Bob
') + ->set('editData.body', 'Updated @Bob
') ->call('saveEdit'); $comment->refresh(); diff --git a/tests/Feature/RichEditorTest.php b/tests/Feature/RichEditorTest.php index 1b9adba..1f3b059 100644 --- a/tests/Feature/RichEditorTest.php +++ b/tests/Feature/RichEditorTest.php @@ -17,7 +17,7 @@ it('creates a comment with rich HTML content preserved', function () { $html = 'Hello bold and italic world
'; Livewire::test(Comments::class, ['model' => $post]) - ->set('newComment', $html) + ->set('commentData.body', $html) ->call('addComment'); $comment = Comment::first(); @@ -42,9 +42,15 @@ it('pre-fills editBody with existing comment HTML when starting edit', function $this->actingAs($user); - Livewire::test(CommentItem::class, ['comment' => $comment]) - ->call('startEdit') - ->assertSet('editBody', $originalHtml); + $component = Livewire::test(CommentItem::class, ['comment' => $comment]) + ->call('startEdit'); + + $editBody = $component->get('editData')['body']; + $bodyJson = json_encode($editBody); + + expect($bodyJson)->toContain('Hello '); + expect($bodyJson)->toContain('world'); + expect($bodyJson)->toContain('bold'); }); it('saves edited HTML content through edit form', function () { @@ -65,13 +71,14 @@ it('saves edited HTML content through edit form', function () { Livewire::test(CommentItem::class, ['comment' => $comment]) ->call('startEdit') - ->set('editBody', $updatedHtml) + ->set('editData.body', $updatedHtml) ->call('saveEdit'); $comment->refresh(); expect($comment->body)->toContain('bold'); - expect($comment->body)->toContain('a link'); + expect($comment->body)->toContain('href="https://example.com"'); + expect($comment->body)->toContain('>a link'); }); it('creates reply with rich HTML content', function () { @@ -91,7 +98,7 @@ it('creates reply with rich HTML content', function () { Livewire::test(CommentItem::class, ['comment' => $comment]) ->call('startReply') - ->set('replyBody', $replyHtml) + ->set('replyData.body', $replyHtml) ->call('addReply'); $reply = Comment::where('parent_id', $comment->id)->first(); diff --git a/tests/TestCase.php b/tests/TestCase.php index a35745a..f2407f9 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -2,6 +2,8 @@ namespace Relaticle\Comments\Tests; +use BladeUI\Heroicons\BladeHeroiconsServiceProvider; +use BladeUI\Icons\BladeIconsServiceProvider; use Filament\Actions\ActionsServiceProvider; use Filament\FilamentServiceProvider; use Filament\Forms\FormsServiceProvider; @@ -29,6 +31,8 @@ abstract class TestCase extends Orchestra { return [ LivewireServiceProvider::class, + BladeIconsServiceProvider::class, + BladeHeroiconsServiceProvider::class, SupportServiceProvider::class, SchemasServiceProvider::class, FormsServiceProvider::class,