From 9da17d2e99c8917266f7406aed8b7f5762a0af84 Mon Sep 17 00:00:00 2001 From: laurell seville Date: Fri, 15 Nov 2024 00:17:04 +0000 Subject: [PATCH] test: update helper test --- app/Models/Contact.php | 2 +- .../UserPreferencesIndexViewHelperTest.php | 34 ++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/app/Models/Contact.php b/app/Models/Contact.php index 8fb0cac3c0b..3aeb928a80f 100644 --- a/app/Models/Contact.php +++ b/app/Models/Contact.php @@ -446,7 +446,7 @@ protected function avatar(): Attribute ]; } - return AvatarHelper::generateRandomAvatar($this, Auth::user()->avatar_style); + return AvatarHelper::generateRandomAvatar($this, Auth::user()?->avatar_style); } ); } diff --git a/tests/Unit/Domains/Settings/ManageUserPreferences/Web/ViewHelpers/UserPreferencesIndexViewHelperTest.php b/tests/Unit/Domains/Settings/ManageUserPreferences/Web/ViewHelpers/UserPreferencesIndexViewHelperTest.php index 33d3c7c4a0a..c3bf9b5a511 100644 --- a/tests/Unit/Domains/Settings/ManageUserPreferences/Web/ViewHelpers/UserPreferencesIndexViewHelperTest.php +++ b/tests/Unit/Domains/Settings/ManageUserPreferences/Web/ViewHelpers/UserPreferencesIndexViewHelperTest.php @@ -3,6 +3,8 @@ namespace Tests\Unit\Domains\Settings\ManageUserPreferences\Web\ViewHelpers; use App\Domains\Settings\ManageUserPreferences\Web\ViewHelpers\UserPreferencesIndexViewHelper; +use App\Helpers\AvatarHelper; +use App\Models\Contact; use App\Models\User; use Carbon\Carbon; use Illuminate\Foundation\Testing\DatabaseTransactions; @@ -25,10 +27,11 @@ public function it_gets_the_data_needed_for_the_view(): void $array = UserPreferencesIndexViewHelper::data($user); $this->assertEquals( - 9, + 10, count($array) ); + $this->assertArrayHasKey('avatar_style', $array); $this->assertArrayHasKey('help', $array); $this->assertArrayHasKey('name_order', $array); $this->assertArrayHasKey('date_format', $array); @@ -48,6 +51,35 @@ public function it_gets_the_data_needed_for_the_view(): void ); } + /** @test */ + public function it_gets_the_data_needed_for_avatar_style(): void + { + $avatarStyle = 'placeholder-dicebear-style'; + + $user = User::factory()->create([ + 'avatar_style' => $avatarStyle, + ]); + + $array = UserPreferencesIndexViewHelper::dtoAvatarStyle($user); + + $contact = new Contact([ + 'first_name' => $user->first_name, + 'last_name' => $user->last_name, + ]); + + $this->assertEquals( + [ + 'url' => [ + 'store' => env('APP_URL').'/settings/preferences/avatar-style', + ], + 'style' => $avatarStyle, + 'avatar' => $contact->avatar, + 'default_avatar' => AvatarHelper::generateRandomAvatar($contact), + ], + $array + ); + } + /** @test */ public function it_gets_the_data_needed_for_help(): void {