|
6 | 6 | use Kirschbaum\Commentions\CommentSubscription; |
7 | 7 | use Kirschbaum\Commentions\Config; |
8 | 8 | use Kirschbaum\Commentions\Livewire\Comments; |
| 9 | +use Kirschbaum\Commentions\Livewire\SubscriptionSidebar; |
9 | 10 | use Tests\Models\Post; |
10 | 11 | use Tests\Models\User; |
11 | 12 |
|
|
25 | 26 |
|
26 | 27 | livewire(Comments::class, [ |
27 | 28 | 'record' => $post, |
28 | | - // Livewire binds mount* params by name; HasSidebar expects `enableSidebar`. |
29 | | - 'enableSidebar' => false, |
| 29 | + // The blade views pass this as `:sidebar-enabled`, so the mount hook |
| 30 | + // parameter must match the `sidebarEnabled` property name. |
| 31 | + 'sidebarEnabled' => false, |
30 | 32 | ])->assertSet('resolvedSidebarEnabled', false); |
31 | 33 | }); |
32 | 34 |
|
| 35 | +test('subscriber visibility can be disabled via parameter', function () { |
| 36 | + /** @var User $user */ |
| 37 | + $user = User::factory()->create(); |
| 38 | + actingAs($user); |
| 39 | + |
| 40 | + $post = Post::factory()->create(); |
| 41 | + |
| 42 | + livewire(Comments::class, [ |
| 43 | + 'record' => $post, |
| 44 | + 'showSubscribers' => false, |
| 45 | + ])->assertSet('resolvedShowSubscribers', false); |
| 46 | +}); |
| 47 | + |
| 48 | +test('the subscription sidebar hides the subscribers list when showSubscribers is false', function () { |
| 49 | + /** @var User $user */ |
| 50 | + $user = User::factory()->create(); |
| 51 | + actingAs($user); |
| 52 | + |
| 53 | + /** @var Post $post */ |
| 54 | + $post = Post::factory()->create(); |
| 55 | + |
| 56 | + $subscriber = User::factory()->create(['name' => 'Subscriber Sam']); |
| 57 | + $post->subscribe($subscriber); |
| 58 | + |
| 59 | + livewire(SubscriptionSidebar::class, [ |
| 60 | + 'record' => $post, |
| 61 | + 'showSubscribers' => false, |
| 62 | + ])->assertDontSee('Subscriber Sam'); |
| 63 | + |
| 64 | + livewire(SubscriptionSidebar::class, [ |
| 65 | + 'record' => $post, |
| 66 | + 'showSubscribers' => true, |
| 67 | + ])->assertSee('Subscriber Sam'); |
| 68 | +}); |
| 69 | + |
33 | 70 | test('canSubscribe reflects auth state', function () { |
34 | 71 | $post = Post::factory()->create(); |
35 | 72 |
|
|
102 | 139 | ])->exists())->toBeFalse(); |
103 | 140 | }); |
104 | 141 |
|
105 | | -test('showSubscribers defaults to config when not provided', function () { |
106 | | - config(['commentions.subscriptions.show_subscribers' => false]); |
| 142 | +test('showSubscribers defaults to config when not provided', function (bool $showSubscribers) { |
| 143 | + config(['commentions.subscriptions.show_subscribers' => $showSubscribers]); |
107 | 144 |
|
108 | 145 | /** @var User $user */ |
109 | 146 | $user = User::factory()->create(); |
|
113 | 150 |
|
114 | 151 | livewire(Comments::class, [ |
115 | 152 | 'record' => $post, |
116 | | - ])->assertSet('showSubscribers', false); |
117 | | -}); |
| 153 | + ])->assertSet('showSubscribers', $showSubscribers); |
| 154 | +})->with( |
| 155 | + ['Show subscribers' => true], |
| 156 | + ['Hide subscribers' => false], |
| 157 | +); |
0 commit comments