mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Initial profile and account tests setup
This commit is contained in:
+1
-1
@@ -16,7 +16,7 @@ return [
|
||||
|
||||
'features' => [
|
||||
Features::registration(),
|
||||
// Features::profile(),
|
||||
Features::profile(),
|
||||
Features::resources(),
|
||||
],
|
||||
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+2
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"/js/filament.js": "/js/filament.js?id=9995e728ce8648b81f5d",
|
||||
"/css/filament.css": "/css/filament.css?id=59ae2ccb0284510a04e7",
|
||||
"/css/filament.css": "/css/filament.css?id=861788a74c7acdcdfb24",
|
||||
"/js/filament.js.map": "/js/filament.js.map?id=1d3615b89069bfd79261",
|
||||
"/css/filament.css.map": "/css/filament.css.map?id=e875f899bca9d385fc36"
|
||||
"/css/filament.css.map": "/css/filament.css.map?id=0cdd1f4b1a3b98124155"
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
@props([
|
||||
'cols' => 1,
|
||||
'legend' => null,
|
||||
])
|
||||
|
||||
<fieldset {{ $attributes->merge(['class' => 'border rounded border-grey-100 p-4 md:px-6 grid grid-cols-1 gap-2 lg:gap-6 lg:grid-cols-'.$cols]) }}>
|
||||
<fieldset class="border rounded border-grey-100 p-4 md:px-6">
|
||||
@if ($legend)
|
||||
<legend class="text-gray-500 text-sm leading-tight font-semibold px-2">{{ $legend }}</legend>
|
||||
@endif
|
||||
{{ $slot }}
|
||||
<div {{ $attributes }}>
|
||||
{{ $slot }}
|
||||
</div>
|
||||
</fieldset>
|
||||
@@ -34,7 +34,7 @@
|
||||
</div>
|
||||
<div class="flex-grow relative">
|
||||
<label class="btn" for="{{ $id }}">{{ __('Change') }}</label>
|
||||
<input type="file" wire:model="{{ $field }}" class="sr-only" id="{{ $id }}" {{ $attributes }}>
|
||||
<input type="file" class="sr-only" id="{{ $id }}" {{ $attributes }}>
|
||||
<div x-show="isUploading" :aria-hidden="!isUploading" class="absolute bottom-0 -mb-3 w-48 max-w-full">
|
||||
<x-filament::progress progress="progress" />
|
||||
</div>
|
||||
|
||||
@@ -8,15 +8,15 @@
|
||||
</x-filament::input-group-stacked>
|
||||
|
||||
<x-filament::input-group-stacked field="avatar" for="photo" :label="__('Avatar')">
|
||||
<x-filament::input-avatar field="avatar" :avatar="$avatar" :user="$user" delete="deleteAvatar" id="photo" tabindex="3" />
|
||||
<x-filament::input-avatar field="avatar" wire:model="avatar" :avatar="$avatar" :user="$user" delete="deleteAvatar" id="photo" tabindex="3" />
|
||||
<x-slot name="hint">
|
||||
{{ __('Optional') }}
|
||||
</x-slot>
|
||||
</x-filament::input-group-stacked>
|
||||
|
||||
<x-filament::fieldset :legend="__('Update Password')" cols="2">
|
||||
<x-filament::fieldset :legend="__('Update Password')" class="grid grid-cols-1 gap-2 lg:gap-6 lg:grid-cols-2">
|
||||
<x-filament::input-group-stacked field="password" for="password" :label="__('New Password')">
|
||||
<x-filament::input type="password" field="password" wire:model.lazy="password" id="password" autocomplete="new-password" tabindex="4" />
|
||||
<x-filament::input type="password" field="password" wire:model="password" id="password" autocomplete="new-password" tabindex="4" />
|
||||
<x-slot name="hint">
|
||||
{{ __('Optional') }}
|
||||
</x-slot>
|
||||
@@ -26,7 +26,7 @@
|
||||
</x-filament::input-group-stacked>
|
||||
|
||||
<x-filament::input-group-stacked field="password_confirmation" for="password_confirmation" :label="__('Confirm New Password')">
|
||||
<x-filament::input type="password" field="password_confirmation" wire:model.lazy="password_confirmation" id="password_confirmation" autocomplete="new-password" tabindex="5" />
|
||||
<x-filament::input type="password" field="password_confirmation" wire:model="password_confirmation" id="password_confirmation" autocomplete="new-password" tabindex="5" />
|
||||
</x-filament::input-group-stacked>
|
||||
</x-filament::fieldset>
|
||||
|
||||
|
||||
@@ -26,7 +26,8 @@ class Account extends Component
|
||||
'required',
|
||||
'email',
|
||||
],
|
||||
'password' => 'nullable',
|
||||
'password' => 'nullable|required_with:password_confirmation|min:8|confirmed',
|
||||
'password_confirmation' => 'nullable|same:password',
|
||||
];
|
||||
|
||||
public function updated($user)
|
||||
@@ -37,8 +38,6 @@ class Account extends Component
|
||||
'email',
|
||||
Rule::unique('users', 'email')->ignore($this->user->id),
|
||||
],
|
||||
'password' => 'nullable|required_with:password_confirmation|min:8',
|
||||
'password_confirmation' => 'nullable|same:password',
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\Tests\Feature;
|
||||
|
||||
use Livewire\Livewire;
|
||||
use Filament\Tests\TestCase;
|
||||
use Filament\Tests\Database\Models\User;
|
||||
use Filament\Http\Livewire\Account;
|
||||
|
||||
class ProfileAccountTest extends TestCase
|
||||
{
|
||||
public $user;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->user = User::factory()->create();
|
||||
}
|
||||
|
||||
public function test_name_is_required()
|
||||
{
|
||||
$this->accountComponent()
|
||||
->set('user.name', '')
|
||||
->call('submit')
|
||||
->assertHasErrors(['user.name' => 'required']);
|
||||
}
|
||||
|
||||
public function test_name_is_minimum_two_characters()
|
||||
{
|
||||
$this->accountComponent()
|
||||
->set('user.name', 'a')
|
||||
->call('submit')
|
||||
->assertHasErrors(['user.name' => 'min']);
|
||||
}
|
||||
|
||||
public function test_email_is_required()
|
||||
{
|
||||
$this->accountComponent()
|
||||
->set('user.email', '')
|
||||
->call('submit')
|
||||
->assertHasErrors(['user.email' => 'required']);
|
||||
}
|
||||
|
||||
public function test_email_is_valid_email()
|
||||
{
|
||||
$this->accountComponent()
|
||||
->set('user.email', 'Something')
|
||||
->call('submit')
|
||||
->assertHasErrors(['user.email' => 'email']);
|
||||
}
|
||||
|
||||
public function test_email_is_unique()
|
||||
{
|
||||
User::factory()->create(['email' => 'test@example.com']);
|
||||
|
||||
$this->accountComponent()
|
||||
->set('user.email', 'test@example.com')
|
||||
->assertHasErrors(['user.email' => 'unique']);
|
||||
}
|
||||
|
||||
public function test_password_may_be_left_blank()
|
||||
{
|
||||
$this->accountComponent()
|
||||
->set('password', '')
|
||||
->call('submit')
|
||||
->assertHasNoErrors(['password' => 'nullable']);
|
||||
}
|
||||
|
||||
public function test_password_is_minimum_eight_characters()
|
||||
{
|
||||
$this->accountComponent()
|
||||
->set('password', 'test')
|
||||
->call('submit')
|
||||
->assertHasErrors(['password' => 'min']);
|
||||
}
|
||||
|
||||
public function test_password_must_be_confirmed()
|
||||
{
|
||||
$this->accountComponent()
|
||||
->set('password', 'test')
|
||||
->call('submit')
|
||||
->assertHasErrors(['password' => 'confirmed']);
|
||||
}
|
||||
|
||||
public function test_password_confirmation_may_be_left_blank()
|
||||
{
|
||||
$this->accountComponent()
|
||||
->set('password_confirmation', '')
|
||||
->call('submit')
|
||||
->assertHasNoErrors(['password_confirmation' => 'nullable']);
|
||||
}
|
||||
|
||||
public function test_password_confirmation_matches_password()
|
||||
{
|
||||
$this->accountComponent()
|
||||
->set('password', 'test')
|
||||
->set('password_confirmation', 'test2')
|
||||
->call('submit')
|
||||
->assertHasErrors(['password_confirmation' => 'same']);
|
||||
}
|
||||
|
||||
public function test_account_saved()
|
||||
{
|
||||
$this->accountComponent()
|
||||
->call('submit')
|
||||
->assertDispatchedBrowserEvent('notify', __('Account saved!'));
|
||||
}
|
||||
|
||||
public function accountComponent()
|
||||
{
|
||||
return Livewire::test(Account::class, ['user' => $this->user]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\Tests\Feature;
|
||||
|
||||
use Livewire\Livewire;
|
||||
use Filament\Tests\TestCase;
|
||||
use Filament\Tests\Database\Models\User;
|
||||
use Filament\Http\Livewire\Profile;
|
||||
use Filament\Http\Livewire\Account;
|
||||
|
||||
class ProfileTest extends TestCase
|
||||
{
|
||||
public $user;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->user = User::factory()->create();
|
||||
}
|
||||
|
||||
public function test_can_see_profile_and_user_account_form()
|
||||
{
|
||||
Livewire::actingAs($this->user)
|
||||
->test(Profile::class)
|
||||
->assertSee(__('Profile'))
|
||||
->assertSeeLivewire('filament-account');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user