Skip to content

Commit

Permalink
Added Tests to ensure if a photo is approved , it is seen in the HTML…
Browse files Browse the repository at this point in the history
… for a profile
  • Loading branch information
MICHAELMUNAVU83 committed Nov 12, 2024
1 parent f071126 commit a814a8c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/animina_web/components/profile/stories_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ defmodule AniminaWeb.StoriesComponents do
attr :user, :any, required: false
attr :language, :any, required: true

# we display the state as an atom in the photo struct, but we need to make sure it is an atom
# as we are using it for pattern matching

def stories_display(assigns) do
~H"""
<div class="flex flex-col gap-4">
Expand Down Expand Up @@ -71,6 +74,7 @@ defmodule AniminaWeb.StoriesComponents do
}
src={Photo.get_optimized_photo_to_use(@story.photo, :normal)}
alt={@story.headline.subject}
id={"photo-for-story-#{@story.id}"}
class="absolute inset-0 object-cover w-full h-full -z-10"
/>
Expand All @@ -88,6 +92,9 @@ defmodule AniminaWeb.StoriesComponents do
</h3>
</div>
<div class="pb-2">
<p>
<%= @story.photo.state %>
</p>
<.story_body
story={@story}
user={@user}
Expand Down
3 changes: 3 additions & 0 deletions lib/animina_web/components/profile/story_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ defmodule AniminaWeb.StoryComponent do
{:ok, socket}
end

# we display the state as an atom in the photo struct, but we need to make sure it is an atom
# as we are using it for pattern matching

defp make_sure_photo_state_is_atom(nil) do
""
end
Expand Down
37 changes: 36 additions & 1 deletion test/animina_web/live/profile_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,25 @@ defmodule AniminaWeb.ProfileTest do
assert bookmark.reason == :visited
end

test "Story images that have been approved are displayed", %{
conn: conn,
public_user: public_user,
private_user: private_user,
private_user_story: private_user_story
} do
{:ok, index_live, html} =
conn
|> login_user(%{
"username_or_email" => public_user.username,
"password" => "MichaelTheEngineer"
})
|> live(~p"/#{private_user.username}")

assert html =~ private_user.name
# since the photo is approved , we will see it in the profile
assert has_element?(index_live, "#photo-for-story-#{private_user_story.id}")
end

test "Once a logged in user views a profile , a bookmark is created and a visit log entry ",
%{
conn: conn,
Expand Down Expand Up @@ -556,6 +575,21 @@ defmodule AniminaWeb.ProfileTest do
position: 1
})

file_path = Temp.path!(basedir: "priv/static/uploads", suffix: ".jpg")

file_path_without_uploads = String.replace(file_path, "uploads/", "")

Photo.create(%{
user_id: user.id,
filename: file_path_without_uploads,
original_filename: file_path_without_uploads,
size: 100,
ext: "jpg",
story_id: story.id,
mime: "image/jpeg",
state: :approved
})

story
end

Expand All @@ -570,7 +604,8 @@ defmodule AniminaWeb.ProfileTest do
original_filename: file_path_without_uploads,
size: 100,
ext: "jpg",
mime: "image/jpeg"
mime: "image/jpeg",
state: :approved
})
end

Expand Down

0 comments on commit a814a8c

Please sign in to comment.