Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
:load-more-label="$getLoadMoreLabel()"
:per-page-increment="$getPerPageIncrement()"
:sidebar-enabled="$isSidebarEnabled()"
:show-subscribers="$showSubscribers()"
:tip-tap-css-classes="$getTipTapCssClasses()"
/>
</x-dynamic-component>
4 changes: 2 additions & 2 deletions src/Livewire/Concerns/HasSidebar.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
91 changes: 91 additions & 0 deletions tests/Filament/CommentsEntryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

use Filament\Schemas\Concerns\InteractsWithSchemas;
use Filament\Schemas\Contracts\HasSchemas;
use Filament\Schemas\Schema;
use Illuminate\Support\Facades\Auth;
use Kirschbaum\Commentions\Config;
use Kirschbaum\Commentions\Filament\Infolists\Components\CommentsEntry;
use Livewire\Component;
use Tests\Models\Post;
use Tests\Models\User;

use function Pest\Laravel\actingAs;
use function Pest\Livewire\livewire;

beforeEach(function () {
Config::resolveAuthenticatedUserUsing(fn () => 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'
<div>{{ $this->getSchema('commentsInfolist') }}</div>
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');
});
41 changes: 39 additions & 2 deletions tests/Livewire/CommentsSubscriptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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();

Expand Down
6 changes: 6 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -33,6 +36,9 @@ protected function getPackageProviders($app)
CommentionsServiceProvider::class,
FilamentServiceProvider::class,
SupportServiceProvider::class,
ActionsServiceProvider::class,
SchemasServiceProvider::class,
InfolistsServiceProvider::class,
LivewireServiceProvider::class,
];
}
Expand Down
Loading