Add HR resource labels and helper methods for various resources; update locale handling in user model and department factory

This commit is contained in:
Mekan1206
2026-07-31 23:40:35 +05:00
parent 581cb8241c
commit 20d032c4cc
83 changed files with 4386 additions and 39 deletions

View File

@@ -5,6 +5,7 @@ declare(strict_types=1);
use App\Enums\Gender;
use App\Enums\NavigationGroup;
use App\Filament\Resources\ActivityLogs\ActivityLogResource;
use App\Filament\Resources\Departments\DepartmentResource;
use App\Models\User;
use BezhanSalleh\LanguageSwitch\Events\LocaleChanged;
use Illuminate\Support\Facades\App;
@@ -44,6 +45,26 @@ it('returns translated filament resource navigation labels', function (): void {
expect(ActivityLogResource::getNavigationLabel())->toBe('Журнал аудита');
});
it('returns translated filament resource model labels', function (): void {
App::setLocale('tk');
expect(DepartmentResource::getPluralModelLabel())->toBe('Bölümler');
expect(DepartmentResource::getModelLabel())->toBe('Bölüm');
App::setLocale('ru');
expect(DepartmentResource::getPluralModelLabel())->toBe('Отделы');
expect(DepartmentResource::getModelLabel())->toBe('Отдел');
});
it('returns translated filament panel strings for turkmen locale', function (): void {
App::setLocale('tk');
expect(__('filament-panels::global-search.field.placeholder'))->toBe('Gözleg');
expect(__('filament-panels::resources/pages/list-records.breadcrumb'))->toBe('Sanaw');
expect(__('filament-actions::create.single.label', ['label' => 'Bölüm']))->toBe('Döret');
});
it('persists locale when locale changed event fires', function (): void {
$user = User::factory()->create(['locale' => 'en']);

View File

@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
use App\Models\Department;
it('generates an uppercase slug code from name', function (): void {
expect(Department::generateUniqueCodeFromName('Human Resources'))
->toBe('HUMAN-RESOURCES');
});
it('generates code on save when code is blank', function (): void {
$department = Department::factory()->create([
'name' => 'Human Resources',
'code' => '',
]);
expect($department->code)->toBe('HUMAN-RESOURCES');
});
it('does not overwrite an existing code on update', function (): void {
$department = Department::factory()->create([
'name' => 'Human Resources',
'code' => 'HR',
]);
$department->update(['name' => 'People Operations']);
expect($department->fresh()->code)->toBe('HR');
});
it('appends a suffix when the generated code already exists', function (): void {
Department::factory()->create([
'name' => 'Sales Team',
'code' => 'SALES',
]);
$department = Department::factory()->create([
'name' => 'Sales',
'code' => '',
]);
expect($department->code)->toBe('SALES-1');
});