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.
This commit is contained in:
@@ -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', '<p>Comment with attachment</p>')
|
||||
->set('commentData.body', '<p>Comment with attachment</p>')
|
||||
->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', '<p>Vacation photos</p>')
|
||||
->set('commentData.body', '<p>Vacation photos</p>')
|
||||
->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', '<p>File path test</p>')
|
||||
->set('commentData.body', '<p>File path test</p>')
|
||||
->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', '<p>Oversized file</p>')
|
||||
->set('commentData.body', '<p>Oversized file</p>')
|
||||
->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', '<p>Malicious file</p>')
|
||||
->set('commentData.body', '<p>Malicious file</p>')
|
||||
->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', '<p>Valid file</p>')
|
||||
->set('commentData.body', '<p>Valid file</p>')
|
||||
->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', '<p>Multiple files</p>')
|
||||
->set('commentData.body', '<p>Multiple files</p>')
|
||||
->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', '<p>Reply with attachment</p>')
|
||||
->set('replyData.body', '<p>Reply with attachment</p>')
|
||||
->set('replyAttachments', [$file])
|
||||
->call('addReply')
|
||||
->assertSet('isReplying', false)
|
||||
->assertSet('replyBody', '')
|
||||
->assertSet('replyAttachments', []);
|
||||
|
||||
$reply = Comment::where('parent_id', $comment->id)->first();
|
||||
|
||||
@@ -20,7 +20,7 @@ it('fires CommentCreated event when adding a comment', function () {
|
||||
$this->actingAs($user);
|
||||
|
||||
Livewire::test(Comments::class, ['model' => $post])
|
||||
->set('newComment', '<p>New comment</p>')
|
||||
->set('commentData.body', '<p>New comment</p>')
|
||||
->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', '<p>Edited</p>')
|
||||
->set('editData.body', '<p>Edited</p>')
|
||||
->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', '<p>Reply text</p>')
|
||||
->set('replyData.body', '<p>Reply text</p>')
|
||||
->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', '<p>Payload test</p>')
|
||||
->set('commentData.body', '<p>Payload test</p>')
|
||||
->call('addComment');
|
||||
|
||||
Event::assertDispatched(CommentCreated::class, function (CommentCreated $event) use ($post, $user) {
|
||||
|
||||
@@ -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', '<p>Original body</p>')
|
||||
->set('editBody', '<p>Updated body</p>')
|
||||
->set('editData.body', '<p>Updated body</p>')
|
||||
->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', '<p>Changed</p>')
|
||||
->set('editData.body', '<p>Changed</p>')
|
||||
->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', '<p>My reply</p>')
|
||||
->set('replyData.body', '<p>My reply</p>')
|
||||
->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', '<p>Draft reply</p>')
|
||||
->set('replyData.body', '<p>Draft reply</p>')
|
||||
->call('cancelReply')
|
||||
->assertSet('isReplying', false)
|
||||
->assertSet('replyBody', '');
|
||||
->assertSet('isReplying', false);
|
||||
});
|
||||
|
||||
it('loads all replies within a thread eagerly', function () {
|
||||
|
||||
@@ -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', '<p>Hello World</p>')
|
||||
->call('addComment')
|
||||
->assertSet('newComment', '');
|
||||
->set('commentData.body', '<p>Hello World</p>')
|
||||
->call('addComment');
|
||||
|
||||
expect(Comment::count())->toBe(1);
|
||||
expect(Comment::first()->body)->toBe('<p>Hello World</p>');
|
||||
@@ -28,7 +27,7 @@ it('associates new comment with the authenticated user', function () {
|
||||
$this->actingAs($user);
|
||||
|
||||
Livewire::test(Comments::class, ['model' => $post])
|
||||
->set('newComment', '<p>Test</p>')
|
||||
->set('commentData.body', '<p>Test</p>')
|
||||
->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', '<p>Hello</p>')
|
||||
->set('commentData.body', '<p>Hello</p>')
|
||||
->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);
|
||||
});
|
||||
|
||||
@@ -162,7 +162,7 @@ it('sanitizes content submitted through livewire component', function () {
|
||||
$this->actingAs($user);
|
||||
|
||||
Livewire::test(Comments::class, ['model' => $post])
|
||||
->set('newComment', '<p>Hello</p><script>alert("xss")</script>')
|
||||
->set('commentData.body', '<p>Hello</p><script>alert("xss")</script>')
|
||||
->call('addComment');
|
||||
|
||||
$comment = Comment::first();
|
||||
|
||||
@@ -16,7 +16,7 @@ it('renders mention with styled span', function () {
|
||||
'commentable_type' => $post->getMorphClass(),
|
||||
'commenter_id' => $user->getKey(),
|
||||
'commenter_type' => $user->getMorphClass(),
|
||||
'body' => '<p>@Alice said hi</p>',
|
||||
'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' => '<p>@Alice and @Bob</p>',
|
||||
'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' => '<p>@ghost is not here</p>',
|
||||
'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' => '<p>Hello @Alice</p>',
|
||||
'body' => 'Hello @Alice',
|
||||
]);
|
||||
|
||||
$comment->mentions()->attach($alice->id, ['commenter_type' => $alice->getMorphClass()]);
|
||||
|
||||
@@ -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', '<p>Hey @Alice check this</p>')
|
||||
->set('commentData.body', '<p>Hey @Alice check this</p>')
|
||||
->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', '<p>Updated @Bob</p>')
|
||||
->set('editData.body', '<p>Updated @Bob</p>')
|
||||
->call('saveEdit');
|
||||
|
||||
$comment->refresh();
|
||||
|
||||
@@ -17,7 +17,7 @@ it('creates a comment with rich HTML content preserved', function () {
|
||||
$html = '<p>Hello <strong>bold</strong> and <em>italic</em> world</p>';
|
||||
|
||||
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('<strong>bold</strong>');
|
||||
expect($comment->body)->toContain('<a href="https://example.com">a link</a>');
|
||||
expect($comment->body)->toContain('href="https://example.com"');
|
||||
expect($comment->body)->toContain('>a link</a>');
|
||||
});
|
||||
|
||||
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();
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user