forked from rubyforgood/homeward-tails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adopter foster dashboard update the liked pets design (rubyforgood#912)
* Update Start * Update working with arguments * Removes adopter foster profile (rubyforgood#906) * Remove adopter foster profile * lint * comment for later * fix test * Update testing * Update view displaying heart images * Update component now able to pass liked pets * Update to syntax * Add the user logic back in * Update to user image * Update to syntax * Update to initial method * Update with testing * Update with new tests * Update with refactor * Update standard * Update to tests * Refactor * Update to logic --------- Co-authored-by: Ben <[email protected]>
- Loading branch information
1 parent
5c638e6
commit 15c1505
Showing
4 changed files
with
88 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<span class="<%= container_class %>"><%= pet_avatar %></span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# frozen_string_literal: true | ||
|
||
# Renders a Pet's image and the Heart like button | ||
class PetAvatarComponent < ApplicationComponent | ||
param :pet, Types::Instance(Pet) | ||
option :like, optional: true | ||
|
||
private | ||
|
||
def pet_avatar | ||
pet_image || pet_initials_span | ||
end | ||
|
||
def pet_image | ||
if pet.images.present? && pet.images.first.present? | ||
image_tag(url_for(pet.images.first), alt: pet.name, class: image_class) | ||
end | ||
end | ||
|
||
def pet_initials_span | ||
if pet.name.present? | ||
content_tag(:span, pet_initials, class: initials_class) | ||
end | ||
end | ||
|
||
def pet_initials | ||
pet.name[0].upcase | ||
end | ||
|
||
def image_class | ||
"rounded-circle" | ||
end | ||
|
||
def initials_class | ||
"avatar-initials rounded-circle fs-2" | ||
end | ||
|
||
def container_class | ||
"avatar avatar-xl avatar-primary rounded-circle border border-4 border-white" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class PetAvatarComponentTest < ViewComponent::TestCase | ||
setup do | ||
@user = create(:user) | ||
@component = AvatarComponent.new(@user) | ||
end | ||
|
||
context "when pet does and does not exists" do | ||
setup do | ||
@pet_with_image = create(:pet, :with_image) | ||
@pet_without_image = create(:pet) | ||
end | ||
|
||
should "has and image" do | ||
url = "/example.png" | ||
stub(:url_for, url) do | ||
render_inline(@component) | ||
assert_selector("img[src='#{url_for(@pet_with_image.images.first)}']", count: 1) | ||
end | ||
end | ||
|
||
should "does not have an image but shows initials" do | ||
url = "/example.png" | ||
stub(:url_for, url) do | ||
@component = AvatarComponent.new(pet: @pet_without_image) | ||
render_inline(@component) | ||
assert_selector(@pet_without_image.name[0, 2].upcase) | ||
end | ||
end | ||
end | ||
end |