story 6.8 and fixed the redundunt options issue
This commit is contained in:
@@ -1,269 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Mail\TestEmail;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Livewire\Volt\Volt;
|
||||
|
||||
beforeEach(function () {
|
||||
$this->admin = User::factory()->admin()->create([
|
||||
'password' => Hash::make('old-password'),
|
||||
]);
|
||||
});
|
||||
|
||||
// ===========================================
|
||||
// Access Tests
|
||||
// ===========================================
|
||||
|
||||
test('admin can view settings page', function () {
|
||||
$this->actingAs($this->admin)
|
||||
->get(route('admin.settings'))
|
||||
->assertOk()
|
||||
->assertSeeLivewire('admin.settings');
|
||||
});
|
||||
|
||||
test('non-admin cannot access settings page', function () {
|
||||
$client = User::factory()->individual()->create();
|
||||
|
||||
$this->actingAs($client)
|
||||
->get(route('admin.settings'))
|
||||
->assertForbidden();
|
||||
});
|
||||
|
||||
test('unauthenticated user cannot access settings page', function () {
|
||||
$this->get(route('admin.settings'))
|
||||
->assertRedirect(route('login'));
|
||||
});
|
||||
|
||||
// ===========================================
|
||||
// Profile Update Tests
|
||||
// ===========================================
|
||||
|
||||
test('admin can update profile information', function () {
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
Volt::test('admin.settings')
|
||||
->set('full_name', 'Updated Name')
|
||||
->set('email', 'updated@example.com')
|
||||
->set('preferred_language', 'en')
|
||||
->call('updateProfile')
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect($this->admin->fresh())
|
||||
->full_name->toBe('Updated Name')
|
||||
->email->toBe('updated@example.com')
|
||||
->preferred_language->toBe('en');
|
||||
});
|
||||
|
||||
test('profile update validates required fields', function () {
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
Volt::test('admin.settings')
|
||||
->set('full_name', '')
|
||||
->set('email', '')
|
||||
->call('updateProfile')
|
||||
->assertHasErrors(['full_name', 'email']);
|
||||
});
|
||||
|
||||
test('profile update prevents duplicate email', function () {
|
||||
$existingUser = User::factory()->create(['email' => 'taken@example.com']);
|
||||
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
Volt::test('admin.settings')
|
||||
->set('email', 'taken@example.com')
|
||||
->call('updateProfile')
|
||||
->assertHasErrors(['email']);
|
||||
});
|
||||
|
||||
test('profile update allows keeping own email', function () {
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
Volt::test('admin.settings')
|
||||
->set('email', $this->admin->email)
|
||||
->call('updateProfile')
|
||||
->assertHasNoErrors();
|
||||
});
|
||||
|
||||
test('profile update validates email format', function () {
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
Volt::test('admin.settings')
|
||||
->set('email', 'invalid-email')
|
||||
->call('updateProfile')
|
||||
->assertHasErrors(['email']);
|
||||
});
|
||||
|
||||
test('profile update validates language is ar or en', function () {
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
Volt::test('admin.settings')
|
||||
->set('preferred_language', 'fr')
|
||||
->call('updateProfile')
|
||||
->assertHasErrors(['preferred_language']);
|
||||
});
|
||||
|
||||
// ===========================================
|
||||
// Password Update Tests
|
||||
// ===========================================
|
||||
|
||||
test('admin can update password with correct current password', function () {
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
Volt::test('admin.settings')
|
||||
->set('current_password', 'old-password')
|
||||
->set('password', 'new-password123')
|
||||
->set('password_confirmation', 'new-password123')
|
||||
->call('updatePassword')
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect(Hash::check('new-password123', $this->admin->fresh()->password))->toBeTrue();
|
||||
});
|
||||
|
||||
test('password update fails with wrong current password', function () {
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
Volt::test('admin.settings')
|
||||
->set('current_password', 'wrong-password')
|
||||
->set('password', 'new-password123')
|
||||
->set('password_confirmation', 'new-password123')
|
||||
->call('updatePassword')
|
||||
->assertHasErrors(['current_password']);
|
||||
});
|
||||
|
||||
test('password update requires confirmation match', function () {
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
Volt::test('admin.settings')
|
||||
->set('current_password', 'old-password')
|
||||
->set('password', 'new-password123')
|
||||
->set('password_confirmation', 'different-password')
|
||||
->call('updatePassword')
|
||||
->assertHasErrors(['password']);
|
||||
});
|
||||
|
||||
test('password fields are cleared after successful update', function () {
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
$component = Volt::test('admin.settings')
|
||||
->set('current_password', 'old-password')
|
||||
->set('password', 'new-password123')
|
||||
->set('password_confirmation', 'new-password123')
|
||||
->call('updatePassword')
|
||||
->assertHasNoErrors();
|
||||
|
||||
expect($component->get('current_password'))->toBe('');
|
||||
expect($component->get('password'))->toBe('');
|
||||
expect($component->get('password_confirmation'))->toBe('');
|
||||
});
|
||||
|
||||
test('password update requires minimum length', function () {
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
Volt::test('admin.settings')
|
||||
->set('current_password', 'old-password')
|
||||
->set('password', 'short')
|
||||
->set('password_confirmation', 'short')
|
||||
->call('updatePassword')
|
||||
->assertHasErrors(['password']);
|
||||
});
|
||||
|
||||
// ===========================================
|
||||
// Test Email Tests
|
||||
// ===========================================
|
||||
|
||||
test('admin can send test email', function () {
|
||||
Mail::fake();
|
||||
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
Volt::test('admin.settings')
|
||||
->call('sendTestEmail')
|
||||
->assertHasNoErrors();
|
||||
|
||||
Mail::assertSent(TestEmail::class, fn ($mail) => $mail->hasTo($this->admin->email)
|
||||
);
|
||||
});
|
||||
|
||||
test('test email uses admin preferred language', function () {
|
||||
Mail::fake();
|
||||
|
||||
$this->admin->update(['preferred_language' => 'ar']);
|
||||
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
Volt::test('admin.settings')
|
||||
->call('sendTestEmail');
|
||||
|
||||
Mail::assertSent(TestEmail::class, fn ($mail) => $mail->locale === 'ar'
|
||||
);
|
||||
});
|
||||
|
||||
// ===========================================
|
||||
// Component Initialization Tests
|
||||
// ===========================================
|
||||
|
||||
test('component initializes with current admin data', function () {
|
||||
$this->admin->update([
|
||||
'full_name' => 'Test Admin',
|
||||
'email' => 'admin@test.com',
|
||||
'preferred_language' => 'en',
|
||||
]);
|
||||
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
$component = Volt::test('admin.settings');
|
||||
|
||||
expect($component->get('full_name'))->toBe('Test Admin');
|
||||
expect($component->get('email'))->toBe('admin@test.com');
|
||||
expect($component->get('preferred_language'))->toBe('en');
|
||||
});
|
||||
|
||||
test('component loads preferred language from user', function () {
|
||||
// Create admin with specific language preference
|
||||
$admin = User::factory()->admin()->create(['preferred_language' => 'ar']);
|
||||
|
||||
$this->actingAs($admin);
|
||||
|
||||
$component = Volt::test('admin.settings');
|
||||
|
||||
expect($component->get('preferred_language'))->toBe('ar');
|
||||
});
|
||||
|
||||
// ===========================================
|
||||
// UI Display Tests
|
||||
// ===========================================
|
||||
|
||||
test('settings page displays mail configuration info', function () {
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
$this->get(route('admin.settings'))
|
||||
->assertOk()
|
||||
->assertSee(config('mail.from.name'))
|
||||
->assertSee(config('mail.from.address'));
|
||||
});
|
||||
|
||||
test('settings page displays profile settings section', function () {
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
$this->get(route('admin.settings'))
|
||||
->assertOk()
|
||||
->assertSee(__('admin.profile_settings'));
|
||||
});
|
||||
|
||||
test('settings page displays password settings section', function () {
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
$this->get(route('admin.settings'))
|
||||
->assertOk()
|
||||
->assertSee(__('admin.password_settings'));
|
||||
});
|
||||
|
||||
test('settings page displays email settings section', function () {
|
||||
$this->actingAs($this->admin);
|
||||
|
||||
$this->get(route('admin.settings'))
|
||||
->assertOk()
|
||||
->assertSee(__('admin.email_settings'));
|
||||
});
|
||||
Reference in New Issue
Block a user