Files
relaticle-comments/tests/Feature/SubscriptionToggleTest.php
manukminasyan 29fcbd8aec feat: initial release of relaticle/comments
Filament comments package with:
- Polymorphic commenting on any Eloquent model
- Threaded replies with configurable depth
- @mentions with autocomplete and user search
- Emoji reactions with toggle and who-reacted tooltips
- File attachments via Livewire uploads
- Reply and mention notifications via Filament notification system
- Thread subscriptions for notification control
- Real-time broadcasting (opt-in Echo) with polling fallback
- Dark mode support
- CommentsAction, CommentsTableAction, CommentsEntry for Filament integration
- 204 tests, 421 assertions
2026-03-26 23:02:56 +04:00

84 lines
2.4 KiB
PHP

<?php
use Livewire\Livewire;
use Relaticle\Comments\CommentSubscription;
use Relaticle\Comments\Livewire\Comments;
use Relaticle\Comments\Tests\Models\Post;
use Relaticle\Comments\Tests\Models\User;
it('subscribes user when toggling from unsubscribed state', function () {
$user = User::factory()->create();
$post = Post::factory()->create();
$this->actingAs($user);
expect(CommentSubscription::isSubscribed($post, $user))->toBeFalse();
Livewire::test(Comments::class, ['model' => $post])
->call('toggleSubscription');
expect(CommentSubscription::isSubscribed($post, $user))->toBeTrue();
});
it('unsubscribes user when toggling from subscribed state', function () {
$user = User::factory()->create();
$post = Post::factory()->create();
CommentSubscription::subscribe($post, $user);
$this->actingAs($user);
expect(CommentSubscription::isSubscribed($post, $user))->toBeTrue();
Livewire::test(Comments::class, ['model' => $post])
->call('toggleSubscription');
expect(CommentSubscription::isSubscribed($post, $user))->toBeFalse();
});
it('returns true for isSubscribed computed when user is subscribed', function () {
$user = User::factory()->create();
$post = Post::factory()->create();
CommentSubscription::subscribe($post, $user);
$this->actingAs($user);
$component = Livewire::test(Comments::class, ['model' => $post]);
expect($component->instance()->isSubscribed())->toBeTrue();
});
it('returns false for isSubscribed computed when user is not subscribed', function () {
$user = User::factory()->create();
$post = Post::factory()->create();
$this->actingAs($user);
$component = Livewire::test(Comments::class, ['model' => $post]);
expect($component->instance()->isSubscribed())->toBeFalse();
});
it('renders Subscribed text for subscribed user', function () {
$user = User::factory()->create();
$post = Post::factory()->create();
CommentSubscription::subscribe($post, $user);
$this->actingAs($user);
Livewire::test(Comments::class, ['model' => $post])
->assertSee('Subscribed');
});
it('renders Subscribe text for unsubscribed user', function () {
$user = User::factory()->create();
$post = Post::factory()->create();
$this->actingAs($user);
Livewire::test(Comments::class, ['model' => $post])
->assertSee('Subscribe');
});