Skip to content

Commit

Permalink
test: update helper test
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurell876 committed Nov 15, 2024
1 parent aa0b5ff commit 9da17d2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/Models/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ protected function avatar(): Attribute
];
}

return AvatarHelper::generateRandomAvatar($this, Auth::user()->avatar_style);
return AvatarHelper::generateRandomAvatar($this, Auth::user()?->avatar_style);
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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
{
Expand Down

0 comments on commit 9da17d2

Please sign in to comment.