1+ <?php
2+
3+ namespace Tests \Feature \Filament ;
4+
5+ use App \Filament \Resources \PluginResource \Pages \EditPlugin ;
6+ use App \Jobs \SyncPlugin ;
7+ use App \Models \Plugin ;
8+ use App \Models \User ;
9+ use Illuminate \Foundation \Testing \RefreshDatabase ;
10+ use Illuminate \Support \Facades \Bus ;
11+ use Livewire \Livewire ;
12+ use Tests \TestCase ;
13+
14+ class ResyncPluginActionTest extends TestCase
15+ {
16+ use RefreshDatabase;
17+
18+ private User $ admin ;
19+
20+ protected function setUp (): void
21+ {
22+ parent ::setUp ();
23+
24+ $ this ->admin = User::factory ()->create (['email ' => 'admin@test.com ' ]);
25+ config (['filament.users ' => ['admin@test.com ' ]]);
26+ }
27+
28+ public function test_resync_action_dispatches_job (): void
29+ {
30+ Bus::fake ([SyncPlugin::class]);
31+
32+ $ plugin = Plugin::factory ()->free ()->approved ()->create ([
33+ 'repository_url ' => 'https://github.com/acme/test-plugin ' ,
34+ ]);
35+
36+ Livewire::actingAs ($ this ->admin )
37+ ->test (EditPlugin::class, ['record ' => $ plugin ->getRouteKey ()])
38+ ->callAction ('resync ' )
39+ ->assertNotified ();
40+
41+ Bus::assertDispatched (SyncPlugin::class, function ($ job ) use ($ plugin ) {
42+ return $ job ->plugin ->is ($ plugin );
43+ });
44+ }
45+
46+ public function test_resync_action_visible_when_repository_url_exists (): void
47+ {
48+ $ plugin = Plugin::factory ()->free ()->approved ()->create ([
49+ 'repository_url ' => 'https://github.com/acme/test-plugin ' ,
50+ ]);
51+
52+ Livewire::actingAs ($ this ->admin )
53+ ->test (EditPlugin::class, ['record ' => $ plugin ->getRouteKey ()])
54+ ->assertActionVisible ('resync ' );
55+ }
56+
57+ public function test_resync_action_hidden_when_no_repository_url (): void
58+ {
59+ $ plugin = Plugin::factory ()->free ()->approved ()->create ([
60+ 'repository_url ' => null ,
61+ ]);
62+
63+ Livewire::actingAs ($ this ->admin )
64+ ->test (EditPlugin::class, ['record ' => $ plugin ->getRouteKey ()])
65+ ->assertActionHidden ('resync ' );
66+ }
67+ }
0 commit comments