-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathMenuLoginsTest.php
More file actions
102 lines (81 loc) · 3.21 KB
/
MenuLoginsTest.php
File metadata and controls
102 lines (81 loc) · 3.21 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
91
92
93
94
95
96
97
98
99
100
101
102
<?php
namespace DutchCodingCompany\FilamentDeveloperLogins\Tests\Feature;
use DutchCodingCompany\FilamentDeveloperLogins\Exceptions\ImplementationException;
use DutchCodingCompany\FilamentDeveloperLogins\FilamentDeveloperLoginsPlugin;
use DutchCodingCompany\FilamentDeveloperLogins\Livewire\MenuLogins;
use DutchCodingCompany\FilamentDeveloperLogins\Tests\Fixtures\TestUser;
use DutchCodingCompany\FilamentDeveloperLogins\Tests\TestCase;
use Filament\Facades\Filament;
use Filament\Pages\Dashboard;
use Filament\Panel;
use Livewire\Livewire;
final class MenuLoginsTest extends TestCase
{
public function test_component_is_rendered(): void
{
$user = TestUser::factory()->create();
$this->actingAs($user)
->get(Dashboard::getUrl())
->assertSeeLivewire(MenuLogins::class);
}
public function test_component_is_not_rendered_when_switchable_is_false(): void
{
FilamentDeveloperLoginsPlugin::current()
->switchable(false);
$user = TestUser::factory()->create();
$this->actingAs($user)
->get(Dashboard::getUrl())
->assertDontSeeLivewire(MenuLogins::class);
}
public function test_component_is_not_rendered_when_plugin_is_not_enabled(): void
{
FilamentDeveloperLoginsPlugin::current()
->enabled(false);
$user = TestUser::factory()->create();
$this->actingAs($user)
->get(Dashboard::getUrl())
->assertDontSeeLivewire(MenuLogins::class);
}
public function test_livewire_displays_to_correct_amount_of_users(): void
{
Livewire::actingAs(TestUser::factory()->create())
->test(MenuLogins::class)
->assertViewHas('users', function (array $users) {
return count($users) === 1;
});
}
public function test_forbidden_is_returned_when_enabled_or_switchable_is_false(): void
{
$authenticatedUser = TestUser::factory()->create();
TestUser::factory()->create([
'email' => 'developer@dutchcodingcompany.com',
'is_admin' => false,
]);
FilamentDeveloperLoginsPlugin::current()
->enabled(false);
Livewire::actingAs($authenticatedUser)
->test(MenuLogins::class)
->call('loginAs', 'developer@dutchcodingcompany.com')
->assertForbidden();
FilamentDeveloperLoginsPlugin::current()
->enabled()
->switchable(false);
Livewire::actingAs($authenticatedUser)
->test(MenuLogins::class)
->call('loginAs', 'developer@dutchcodingcompany.com')
->assertForbidden();
}
public function test_component_is_only_rendered_in_panel_with_plugin(): void
{
$user = TestUser::factory()->create();
$this->actingAs($user)
->get(Dashboard::getUrl(panel: $this->panelName))
->assertSuccessful()
->assertSeeLivewire(MenuLogins::class);
$this->expectException(ImplementationException::class);
$this->actingAs($user)
->get(Dashboard::getUrl(panel: $this->panelName.'-other'))
->assertSuccessful()
->assertDontSeeLivewire(MenuLogins::class);
}
}