diff --git a/resources/views/filament/infolists/components/comments-entry.blade.php b/resources/views/filament/infolists/components/comments-entry.blade.php
index 9af985c..d9e1290 100644
--- a/resources/views/filament/infolists/components/comments-entry.blade.php
+++ b/resources/views/filament/infolists/components/comments-entry.blade.php
@@ -9,6 +9,7 @@
:load-more-label="$getLoadMoreLabel()"
:per-page-increment="$getPerPageIncrement()"
:sidebar-enabled="$isSidebarEnabled()"
+ :show-subscribers="$showSubscribers()"
:tip-tap-css-classes="$getTipTapCssClasses()"
/>
diff --git a/src/Livewire/Concerns/HasSidebar.php b/src/Livewire/Concerns/HasSidebar.php
index 6d073d4..3f2dcad 100644
--- a/src/Livewire/Concerns/HasSidebar.php
+++ b/src/Livewire/Concerns/HasSidebar.php
@@ -15,9 +15,9 @@ trait HasSidebar
public ?bool $showSubscribers = null;
- public function mountHasSidebar(?bool $enableSidebar = null, ?bool $showSubscribers = null): void
+ public function mountHasSidebar(?bool $sidebarEnabled = null, ?bool $showSubscribers = null): void
{
- $this->sidebarEnabled = $enableSidebar ?? (bool) config('commentions.subscriptions.show_sidebar');
+ $this->sidebarEnabled = $sidebarEnabled ?? (bool) config('commentions.subscriptions.show_sidebar');
$this->showSubscribers = $showSubscribers ?? (bool) config('commentions.subscriptions.show_subscribers', true);
}
diff --git a/tests/Filament/CommentsEntryTest.php b/tests/Filament/CommentsEntryTest.php
new file mode 100644
index 0000000..f7e4f1c
--- /dev/null
+++ b/tests/Filament/CommentsEntryTest.php
@@ -0,0 +1,91 @@
+ Auth::user());
+});
+
+/**
+ * Minimal Livewire host that renders the package's `CommentsEntry`
+ * inside a Filament schema, exercising the real infolist blade view.
+ */
+class CommentsEntryTestHarness extends Component implements HasSchemas
+{
+ use InteractsWithSchemas;
+
+ public Post $record;
+
+ public bool $disableSidebar = false;
+
+ public bool $hideSubscribers = false;
+
+ public function commentsInfolist(Schema $schema): Schema
+ {
+ return $schema
+ ->record($this->record)
+ ->components([
+ CommentsEntry::make('comments')
+ ->disableSidebar($this->disableSidebar)
+ ->hideSubscribers($this->hideSubscribers),
+ ]);
+ }
+
+ public function render()
+ {
+ return <<<'BLADE'
+
{{ $this->getSchema('commentsInfolist') }}
+ BLADE;
+ }
+}
+
+test('CommentsEntry disableSidebar removes the subscription sidebar', function () {
+ /** @var User $user */
+ $user = User::factory()->create();
+ actingAs($user);
+
+ /** @var Post $post */
+ $post = Post::factory()->create();
+ $post->subscribe(User::factory()->create(['name' => 'Subscriber Sam']));
+
+ livewire(CommentsEntryTestHarness::class, [
+ 'record' => $post,
+ 'disableSidebar' => false,
+ ])->assertSee('Subscriber Sam');
+
+ livewire(CommentsEntryTestHarness::class, [
+ 'record' => $post,
+ 'disableSidebar' => true,
+ ])->assertDontSee('Subscriber Sam');
+});
+
+test('CommentsEntry hideSubscribers hides the subscribers list', function () {
+ /** @var User $user */
+ $user = User::factory()->create();
+ actingAs($user);
+
+ /** @var Post $post */
+ $post = Post::factory()->create();
+ $post->subscribe(User::factory()->create(['name' => 'Subscriber Sam']));
+
+ livewire(CommentsEntryTestHarness::class, [
+ 'record' => $post,
+ 'hideSubscribers' => false,
+ ])->assertSee('Subscriber Sam');
+
+ livewire(CommentsEntryTestHarness::class, [
+ 'record' => $post,
+ 'hideSubscribers' => true,
+ ])->assertDontSee('Subscriber Sam');
+});
diff --git a/tests/Livewire/CommentsSubscriptionTest.php b/tests/Livewire/CommentsSubscriptionTest.php
index 5bc3860..553e262 100644
--- a/tests/Livewire/CommentsSubscriptionTest.php
+++ b/tests/Livewire/CommentsSubscriptionTest.php
@@ -6,6 +6,7 @@
use Kirschbaum\Commentions\CommentSubscription;
use Kirschbaum\Commentions\Config;
use Kirschbaum\Commentions\Livewire\Comments;
+use Kirschbaum\Commentions\Livewire\SubscriptionSidebar;
use Tests\Models\Post;
use Tests\Models\User;
@@ -25,11 +26,47 @@
livewire(Comments::class, [
'record' => $post,
- // Livewire binds mount* params by name; HasSidebar expects `enableSidebar`.
- 'enableSidebar' => false,
+ // The blade views pass this as `:sidebar-enabled`, so the mount hook
+ // parameter must match the `sidebarEnabled` property name.
+ 'sidebarEnabled' => false,
])->assertSet('resolvedSidebarEnabled', false);
});
+test('subscriber visibility can be disabled via parameter', function () {
+ /** @var User $user */
+ $user = User::factory()->create();
+ actingAs($user);
+
+ $post = Post::factory()->create();
+
+ livewire(Comments::class, [
+ 'record' => $post,
+ 'showSubscribers' => false,
+ ])->assertSet('resolvedShowSubscribers', false);
+});
+
+test('the subscription sidebar hides the subscribers list when showSubscribers is false', function () {
+ /** @var User $user */
+ $user = User::factory()->create();
+ actingAs($user);
+
+ /** @var Post $post */
+ $post = Post::factory()->create();
+
+ $subscriber = User::factory()->create(['name' => 'Subscriber Sam']);
+ $post->subscribe($subscriber);
+
+ livewire(SubscriptionSidebar::class, [
+ 'record' => $post,
+ 'showSubscribers' => false,
+ ])->assertDontSee('Subscriber Sam');
+
+ livewire(SubscriptionSidebar::class, [
+ 'record' => $post,
+ 'showSubscribers' => true,
+ ])->assertSee('Subscriber Sam');
+});
+
test('canSubscribe reflects auth state', function () {
$post = Post::factory()->create();
diff --git a/tests/TestCase.php b/tests/TestCase.php
index 226f557..b94f599 100644
--- a/tests/TestCase.php
+++ b/tests/TestCase.php
@@ -4,7 +4,10 @@
use BladeUI\Heroicons\BladeHeroiconsServiceProvider;
use BladeUI\Icons\BladeIconsServiceProvider;
+use Filament\Actions\ActionsServiceProvider;
use Filament\FilamentServiceProvider;
+use Filament\Infolists\InfolistsServiceProvider;
+use Filament\Schemas\SchemasServiceProvider;
use Filament\Support\SupportServiceProvider;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
@@ -33,6 +36,9 @@ protected function getPackageProviders($app)
CommentionsServiceProvider::class,
FilamentServiceProvider::class,
SupportServiceProvider::class,
+ ActionsServiceProvider::class,
+ SchemasServiceProvider::class,
+ InfolistsServiceProvider::class,
LivewireServiceProvider::class,
];
}