-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathResyncPluginActionTest.php
More file actions
90 lines (72 loc) · 2.78 KB
/
ResyncPluginActionTest.php
File metadata and controls
90 lines (72 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
namespace Tests\Feature\Filament;
use App\Filament\Resources\PluginResource\Pages\EditPlugin;
use App\Jobs\SyncPlugin;
use App\Models\Plugin;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Bus;
use Livewire\Livewire;
use Tests\TestCase;
class ResyncPluginActionTest extends TestCase
{
use RefreshDatabase;
private User $admin;
protected function setUp(): void
{
parent::setUp();
$this->admin = User::factory()->create(['email' => 'admin@test.com']);
config(['filament.users' => ['admin@test.com']]);
}
public function test_resync_action_dispatches_job(): void
{
Bus::fake([SyncPlugin::class]);
$plugin = Plugin::factory()->free()->approved()->create([
'repository_url' => 'https://github.com/acme/test-plugin',
]);
Livewire::actingAs($this->admin)
->test(EditPlugin::class, ['record' => $plugin->getRouteKey()])
->callAction('resync')
->assertNotified();
Bus::assertDispatched(SyncPlugin::class, function ($job) use ($plugin) {
return $job->plugin->is($plugin);
});
}
public function test_resync_action_visible_when_repository_url_exists(): void
{
$plugin = Plugin::factory()->free()->approved()->create([
'repository_url' => 'https://github.com/acme/test-plugin',
]);
Livewire::actingAs($this->admin)
->test(EditPlugin::class, ['record' => $plugin->getRouteKey()])
->assertActionVisible('resync');
}
public function test_resync_action_hidden_when_no_repository_url(): void
{
$plugin = Plugin::factory()->free()->approved()->create([
'repository_url' => null,
]);
Livewire::actingAs($this->admin)
->test(EditPlugin::class, ['record' => $plugin->getRouteKey()])
->assertActionHidden('resync');
}
public function test_view_github_action_uses_repository_url(): void
{
$plugin = Plugin::factory()->free()->approved()->create([
'repository_url' => 'https://github.com/acme/test-plugin',
]);
Livewire::actingAs($this->admin)
->test(EditPlugin::class, ['record' => $plugin->getRouteKey()])
->assertActionVisible('viewGithub')
->assertActionHasUrl('viewGithub', 'https://github.com/acme/test-plugin');
}
public function test_view_github_action_hidden_when_no_repository_url(): void
{
$plugin = Plugin::factory()->free()->approved()->create([
'repository_url' => null,
]);
Livewire::actingAs($this->admin)
->test(EditPlugin::class, ['record' => $plugin->getRouteKey()])
->assertActionHidden('viewGithub');
}
}