Skip to content

Commit

Permalink
test: adding tags_live tests
Browse files Browse the repository at this point in the history
  • Loading branch information
panoramix360 committed Nov 14, 2023
1 parent b534ce9 commit 99269c2
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 10 deletions.
27 changes: 18 additions & 9 deletions lib/app_web/live/tags_live.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
highlight={fn _ -> false end}
>
<:column :let={tag} label="Name" key="text">
<td class="px-6 py-4 text-center" data-test-id="text">
<td class="px-6 py-4 text-center" data-test-id={"text_#{tag.id}"}>
<%= tag.text %>
</td>
</:column>

<:column :let={tag} label="Color" key="color">
<td class="px-6 py-4 text-center" data-test-id="color">
<td class="px-6 py-4 text-center" data-test-id={"color_#{tag.id}"}>
">
<span
style={"background-color:#{tag.color}"}
class="max-w-[144px] text-white font-bold py-1 px-2 rounded-full
Expand All @@ -27,13 +28,17 @@
</:column>

<:column :let={tag} label="Created At" key="inserted_at">
<td class="px-6 py-4 text-center" data-test-id="color">
<%= format_date(tag.inserted_at) %>
<td class="px-6 py-4 text-center" data-test-id={"inserted_at_#{tag.id}"}>
> <%= format_date(tag.inserted_at) %>
</td>
</:column>

<:column :let={tag} label="Latest" key="last_used_at">
<td class="px-6 py-4 text-center" data-test-id="color">
<td
class="px-6 py-4 text-center"
data-test-id={"last_used_at_#{tag.id}"}
>
>
<%= if tag.last_used_at do %>
<%= format_date(tag.last_used_at) %>
<% else %>
Expand All @@ -43,21 +48,25 @@
</:column>

<:column :let={tag} label="Items Count" key="items_count">
<td class="px-6 py-4 text-center" data-test-id="color">
<td class="px-6 py-4 text-center" data-test-id={"items_count_#{tag.id}"}>
>
<a href={~p"/?filter_by_tag=#{tag.text}"} class="underline">
<%= tag.items_count %>
</a>
</td>
</:column>

<:column :let={tag} label="Total Time Logged" key="total_time_logged">
<td class="px-6 py-4 text-center" data-test-id="color">
<%= format_seconds(tag.total_time_logged) %>
<td
class="px-6 py-4 text-center"
data-test-id={"total_time_logged_#{tag.id}"}
>
> <%= format_seconds(tag.total_time_logged) %>
</td>
</:column>

<:column :let={tag} label="Actions" key="actions">
<td class="px-6 py-4 text-center" data-test-id="actions">
<td class="px-6 py-4 text-center" data-test-id={"actions_#{tag.id}"}>
<%= link("Edit", to: Routes.tag_path(@socket, :edit, tag)) %>

<span class="text-red-500 ml-10">
Expand Down
1 change: 0 additions & 1 deletion test/app_web/live/stats_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,5 @@ defmodule AppWeb.StatsLiveTest do
[first_element | _] = Floki.find(result, "td[data-test-id=person_id_1]")

assert first_element |> Floki.text() =~ "1"
first_element |> Floki.text() |> dbg()
end
end
45 changes: 45 additions & 0 deletions test/app_web/live/tags_live_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
defmodule AppWeb.TagsLiveTest do
use AppWeb.ConnCase, async: true
alias App.{Item, Timer, Tag}
import Phoenix.LiveViewTest

@person_id 55

test "disconnected and connected render", %{conn: conn} do
{:ok, page_live, disconnected_html} = live(conn, "/tags")
assert disconnected_html =~ "Tags"
assert render(page_live) =~ "Tags"
end

# test "display tags on table", %{conn: conn} do
# add_tag(%{person_id: @person_id, text: "Tag1", color: "#000000"})
# add_tag(%{person_id: @person_id, text: "Tag2", color: "#000000"})
# add_tag(%{person_id: @person_id, text: "Tag3", color: "#000000"})

# {:ok, page_live, _html} = live(conn, "/tags")

# assert render(page_live) =~ "Tags"

# assert page_live
# |> element("td[data-test-id=text_1]")
# |> render() =~
# "start!s"
# end

defp add_tag(attrs) do
{:ok, tag} = Tag.create_tag(attrs)

{:ok, %{model: item}} = Item.create_item(%{
person_id: @person_id,
status: 0,
text: "some item",
tags: [tag]
})

seconds_ago_date = NaiveDateTime.new(Date.utc_today(), Time.add(Time.utc_now(), -10))
Timer.start(%{item_id: item.id, person_id: @person_id, start: seconds_ago_date})
Timer.stop_timer_for_item_id(item.id)

tag
end
end

0 comments on commit 99269c2

Please sign in to comment.