Files
relaticle-comments/tests/Feature/SubscriptionToggleTest.php
manukminasyan fd5bc5271b refactor: rename for Laravel conventions and better DX
- Rename IsCommenter trait to CanComment, Commenter interface to Commentator
- Move models to Models/ namespace (Comment, Reaction, Attachment, Subscription)
- Rename user_type/user_id polymorphic columns to commenter_type/commenter_id
- Rename Config class to CommentsConfig, update config key tables->table_names
- Rename getCommentName() to getCommentDisplayName() on commentator models
- Add column_names config section for commenter morph customization
- Add table_names config with all 5 tables individually configurable
- Expand translation file with structured i18n groups
- Update all Blade views, Livewire components, events, listeners, and tests
2026-03-27 14:53:12 +04:00

84 lines
2.3 KiB
PHP

<?php
use Livewire\Livewire;
use Relaticle\Comments\Livewire\Comments;
use Relaticle\Comments\Models\Subscription;
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(Subscription::isSubscribed($post, $user))->toBeFalse();
Livewire::test(Comments::class, ['model' => $post])
->call('toggleSubscription');
expect(Subscription::isSubscribed($post, $user))->toBeTrue();
});
it('unsubscribes user when toggling from subscribed state', function () {
$user = User::factory()->create();
$post = Post::factory()->create();
Subscription::subscribe($post, $user);
$this->actingAs($user);
expect(Subscription::isSubscribed($post, $user))->toBeTrue();
Livewire::test(Comments::class, ['model' => $post])
->call('toggleSubscription');
expect(Subscription::isSubscribed($post, $user))->toBeFalse();
});
it('returns true for isSubscribed computed when user is subscribed', function () {
$user = User::factory()->create();
$post = Post::factory()->create();
Subscription::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();
Subscription::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');
});