-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6cc3cc8
commit 9fff753
Showing
1 changed file
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
|
||
use App\Filament\Resources\UserResource; | ||
use App\Models\User; | ||
use Tests\FrontendTestCase; | ||
|
||
use function Pest\Livewire\livewire; | ||
|
||
it('can render index page', function () { | ||
/** @var FrontendTestCase $this */ | ||
$this->get(UserResource::getUrl())->assertForbidden(); | ||
|
||
$this->actingAs(User::factory()->flowManager()->create()); | ||
$this->get(UserResource::getUrl())->assertForbidden(); | ||
|
||
$this->actingAs(User::factory()->networkManager()->create()); | ||
$this->get(UserResource::getUrl())->assertSuccessful(); | ||
|
||
$this->actingAs(User::factory()->system()->create()); | ||
$this->get(UserResource::getUrl())->assertSuccessful(); | ||
}); | ||
|
||
it('can render edit page', function () { | ||
/** @var FrontendTestCase $this */ | ||
$this->get(UserResource::getUrl('edit', [ | ||
'record' => User::factory()->create(), | ||
]))->assertForbidden(); | ||
|
||
$this->actingAs(User::factory()->flowManager()->create()); | ||
$this->get(UserResource::getUrl('edit', [ | ||
'record' => User::factory()->create(), | ||
]))->assertForbidden(); | ||
|
||
$this->actingAs(User::factory()->networkManager()->create()); | ||
$this->get(UserResource::getUrl('edit', [ | ||
'record' => User::factory()->create(), | ||
]))->assertSuccessful(); | ||
|
||
$this->actingAs(User::factory()->system()->create()); | ||
$this->get(UserResource::getUrl('edit', [ | ||
'record' => User::factory()->create(), | ||
]))->assertSuccessful(); | ||
}); | ||
|
||
it('can retrieve data for edit page', function () { | ||
$this->actingAs(User::factory()->system()->create()); | ||
$user = User::factory()->create(); | ||
|
||
livewire(UserResource\Pages\EditUser::class, [ | ||
'record' => $user->getKey(), | ||
]) | ||
->assertSet('data.id', $user->id) | ||
->assertSet('data.name', $user->name) | ||
->assertSet('data.role', $user->role->value); | ||
}); | ||
|
||
it('can edit', function () { | ||
/** @var FrontendTestCase $this */ | ||
$this->actingAs(User::factory()->system()->create()); | ||
|
||
$user = User::factory()->create(); | ||
$newData = User::factory()->make(); | ||
|
||
livewire(UserResource\Pages\EditUser::class, [ | ||
'record' => $user->getKey(), | ||
]) | ||
->set('data.role_id', $newData->role_id) | ||
->call('save'); | ||
|
||
expect($user->refresh()) | ||
->role_id->toBe($newData->role_id); | ||
}); | ||
|
||
it('can validate edit input', function () { | ||
$this->actingAs(User::factory()->system()->create()); | ||
|
||
$user = User::factory()->create(); | ||
|
||
livewire(UserResource\Pages\EditUser::class, [ | ||
'record' => $user->getKey(), | ||
]) | ||
->set('data.role_id', null) | ||
->call('save') | ||
->assertHasErrors(['data.role_id' => 'required']); | ||
}); |