Compare commits

..

No commits in common. "cb4de9a6ff17fec4cfd5de78f6da0668b9e3f36f" and "1d8f3360d8e88ec60726e879cfa7a8b02ce96bf6" have entirely different histories.

13 changed files with 34 additions and 207 deletions

View File

@ -194,7 +194,7 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
end end
defp get_value_for_key(:remaining, ammo_group), defp get_value_for_key(:remaining, ammo_group),
do: gettext("%{percentage}%", percentage: ammo_group |> Ammo.get_percentage_remaining()) do: "#{ammo_group |> Ammo.get_percentage_remaining()}%"
defp get_value_for_key(:actions, ammo_group) do defp get_value_for_key(:actions, ammo_group) do
assigns = %{ammo_group: ammo_group} assigns = %{ammo_group: ammo_group}

View File

@ -16,7 +16,7 @@
<span class="rounded-lg title text-lg"> <span class="rounded-lg title text-lg">
<%= gettext("Percentage left:") %> <%= gettext("Percentage left:") %>
<%= gettext("%{percentage}%", percentage: @ammo_group |> Ammo.get_percentage_remaining()) %> <%= "#{@ammo_group |> Ammo.get_percentage_remaining()}%" %>
</span> </span>
<%= if @ammo_group.notes do %> <%= if @ammo_group.notes do %>

View File

@ -95,12 +95,11 @@ defmodule CanneryWeb.ViewHelpers do
~H""" ~H"""
<label for={@id} class="inline-flex relative items-center cursor-pointer"> <label for={@id} class="inline-flex relative items-center cursor-pointer">
<input <input
id={@id}
type="checkbox" type="checkbox"
value={@value} value={@value}
checked={@value} checked={@value}
id={@id}
class="sr-only peer" class="sr-only peer"
data-qa={@id}
{ {
if assigns |> Map.has_key?(:target), if assigns |> Map.has_key?(:target),
do: %{"phx-click" => @action, "phx-value-value" => @value, "phx-target" => @target}, do: %{"phx-click" => @action, "phx-value-value" => @value, "phx-target" => @target},

View File

@ -962,9 +962,3 @@ msgstr ""
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Used up on:" msgid "Used up on:"
msgstr "" msgstr ""
#: lib/cannery_web/live/ammo_group_live/index.ex:197
#: lib/cannery_web/live/ammo_group_live/show.html.heex:19
#, elixir-autogen, elixir-format
msgid "%{percentage}%"
msgstr ""

View File

@ -945,9 +945,3 @@ msgstr ""
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Used up on:" msgid "Used up on:"
msgstr "" msgstr ""
#: lib/cannery_web/live/ammo_group_live/index.ex:197
#: lib/cannery_web/live/ammo_group_live/show.html.heex:19
#, elixir-autogen, elixir-format
msgid "%{percentage}%"
msgstr ""

View File

@ -946,9 +946,3 @@ msgstr ""
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Used up on:" msgid "Used up on:"
msgstr "" msgstr ""
#: lib/cannery_web/live/ammo_group_live/index.ex:197
#: lib/cannery_web/live/ammo_group_live/show.html.heex:19
#, elixir-autogen, elixir-format
msgid "%{percentage}%"
msgstr ""

View File

@ -960,9 +960,3 @@ msgstr ""
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Used up on:" msgid "Used up on:"
msgstr "" msgstr ""
#: lib/cannery_web/live/ammo_group_live/index.ex:197
#: lib/cannery_web/live/ammo_group_live/show.html.heex:19
#, elixir-autogen, elixir-format
msgid "%{percentage}%"
msgstr ""

View File

@ -965,9 +965,3 @@ msgstr ""
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Used up on:" msgid "Used up on:"
msgstr "" msgstr ""
#: lib/cannery_web/live/ammo_group_live/index.ex:197
#: lib/cannery_web/live/ammo_group_live/show.html.heex:19
#, elixir-autogen, elixir-format
msgid "%{percentage}%"
msgstr ""

View File

@ -956,9 +956,3 @@ msgstr ""
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
msgid "Used up on:" msgid "Used up on:"
msgstr "" msgstr ""
#: lib/cannery_web/live/ammo_group_live/index.ex:197
#: lib/cannery_web/live/ammo_group_live/show.html.heex:19
#, elixir-autogen, elixir-format
msgid "%{percentage}%"
msgstr ""

View File

@ -10,23 +10,10 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
@moduletag :ammo_group_live_test @moduletag :ammo_group_live_test
@shot_group_create_attrs %{"ammo_left" => 5, "notes" => "some notes"} @shot_group_create_attrs %{"ammo_left" => 5, "notes" => "some notes"}
@shot_group_update_attrs %{ @shot_group_update_attrs %{"count" => 5, "notes" => "some updated notes"}
"count" => 5,
"date" => ~N[2022-02-13 03:17:00],
"notes" => "some updated notes"
}
@create_attrs %{"count" => 42, "notes" => "some notes", "price_paid" => 120.5} @create_attrs %{"count" => 42, "notes" => "some notes", "price_paid" => 120.5}
@update_attrs %{"count" => 43, "notes" => "some updated notes", "price_paid" => 456.7} @update_attrs %{"count" => 43, "notes" => "some updated notes", "price_paid" => 456.7}
@ammo_group_create_limit 10_000 @ammo_group_create_limit 10_000
@ammo_group_attrs %{
"price_paid" => 50,
"count" => 20
}
@shot_group_attrs %{
"price_paid" => 50,
"count" => 20
}
# @invalid_attrs %{count: -1, notes: nil, price_paid: nil} # @invalid_attrs %{count: -1, notes: nil, price_paid: nil}
defp create_ammo_group(%{current_user: current_user}) do defp create_ammo_group(%{current_user: current_user}) do
@ -34,28 +21,14 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
container = container_fixture(current_user) container = container_fixture(current_user)
{1, [ammo_group]} = ammo_group_fixture(ammo_type, container, current_user) {1, [ammo_group]} = ammo_group_fixture(ammo_type, container, current_user)
%{ammo_type: ammo_type, ammo_group: ammo_group, container: container} shot_group =
end %{"count" => 5, "date" => ~N[2022-02-13 03:17:00], "notes" => "some notes"}
|> shot_group_fixture(current_user, ammo_group)
defp create_shot_group(%{current_user: current_user, ammo_group: ammo_group}) do
shot_group = shot_group_fixture(@shot_group_update_attrs, current_user, ammo_group)
ammo_group = ammo_group |> Repo.reload!()
%{ammo_group: ammo_group, shot_group: shot_group} %{ammo_group: ammo_group, shot_group: shot_group}
end end
defp create_empty_ammo_group(%{ describe "Index" do
current_user: current_user,
ammo_type: ammo_type,
container: container
}) do
{1, [ammo_group]} = ammo_group_fixture(@ammo_group_attrs, ammo_type, container, current_user)
shot_group = shot_group_fixture(@shot_group_attrs, current_user, ammo_group)
ammo_group = ammo_group |> Repo.reload!()
%{empty_ammo_group: ammo_group, shot_group: shot_group}
end
describe "Index of ammo group" do
setup [:register_and_log_in_user, :create_ammo_group] setup [:register_and_log_in_user, :create_ammo_group]
test "lists all ammo_groups", %{conn: conn, ammo_group: ammo_group} do test "lists all ammo_groups", %{conn: conn, ammo_group: ammo_group} do
@ -150,6 +123,27 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
) )
end end
test "saves new shot_group", %{conn: conn, ammo_group: ammo_group} do
{:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index))
assert index_live |> element("a", dgettext("actions", "Record shots")) |> render_click() =~
gettext("Record shots")
assert_patch(index_live, Routes.ammo_group_index_path(conn, :add_shot_group, ammo_group))
# assert index_live
# |> form("#shot_group-form", shot_group: @invalid_attrs)
# |> render_change() =~ dgettext("errors", "is invalid")
{:ok, _view, html} =
index_live
|> form("#shot-group-form", shot_group: @shot_group_create_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.ammo_group_index_path(conn, :index))
assert html =~ dgettext("prompts", "Shots recorded successfully")
end
test "updates ammo_group in listing", %{conn: conn, ammo_group: ammo_group} do test "updates ammo_group in listing", %{conn: conn, ammo_group: ammo_group} do
{:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index)) {:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index))
@ -183,59 +177,9 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
refute has_element?(index_live, "#ammo_group-#{ammo_group.id}") refute has_element?(index_live, "#ammo_group-#{ammo_group.id}")
end end
test "saves new shot_group", %{conn: conn, ammo_group: ammo_group} do
{:ok, index_live, _html} = live(conn, Routes.ammo_group_index_path(conn, :index))
assert index_live |> element("a", dgettext("actions", "Record shots")) |> render_click() =~
gettext("Record shots")
assert_patch(index_live, Routes.ammo_group_index_path(conn, :add_shot_group, ammo_group))
# assert index_live
# |> form("#shot_group-form", shot_group: @invalid_attrs)
# |> render_change() =~ dgettext("errors", "is invalid")
{:ok, _view, html} =
index_live
|> form("#shot-group-form", shot_group: @shot_group_create_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.ammo_group_index_path(conn, :index))
assert html =~ dgettext("prompts", "Shots recorded successfully")
end
end end
describe "Index of empty ammo group" do describe "Show" do
setup [:register_and_log_in_user, :create_ammo_group, :create_empty_ammo_group]
test "hides empty ammo groups by default", %{conn: conn, empty_ammo_group: ammo_group} do
{:ok, show_live, html} = live(conn, Routes.ammo_group_index_path(conn, :index))
assert html =~ gettext("Show used")
refute html =~ gettext("$%{amount}", amount: 50.00 |> :erlang.float_to_binary(decimals: 2))
refute html =~
"\n" <>
gettext("%{percentage}%",
percentage: ammo_group |> Ammo.get_percentage_remaining()
) <>
"\n"
html = show_live |> element("[data-qa=\"toggle_show_used\"]") |> render_click()
assert html =~ gettext("$%{amount}", amount: 50.00 |> :erlang.float_to_binary(decimals: 2))
assert html =~
"\n" <>
gettext("%{percentage}%",
percentage: ammo_group |> Ammo.get_percentage_remaining()
) <>
"\n"
end
end
describe "Show ammo group" do
setup [:register_and_log_in_user, :create_ammo_group] setup [:register_and_log_in_user, :create_ammo_group]
test "displays ammo_group", %{conn: conn, ammo_group: ammo_group} do test "displays ammo_group", %{conn: conn, ammo_group: ammo_group} do
@ -290,10 +234,6 @@ defmodule CanneryWeb.AmmoGroupLiveTest do
assert html =~ dgettext("prompts", "Shots recorded successfully") assert html =~ dgettext("prompts", "Shots recorded successfully")
end end
end
describe "Show ammo group with shot group" do
setup [:register_and_log_in_user, :create_ammo_group, :create_shot_group]
test "updates shot_group in listing", test "updates shot_group in listing",
%{conn: conn, ammo_group: ammo_group, shot_group: shot_group} do %{conn: conn, ammo_group: ammo_group, shot_group: shot_group} do

View File

@ -6,7 +6,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
use CanneryWeb.ConnCase use CanneryWeb.ConnCase
import Phoenix.LiveViewTest import Phoenix.LiveViewTest
import CanneryWeb.Gettext import CanneryWeb.Gettext
alias Cannery.{Ammo, Repo} alias Cannery.Ammo
@moduletag :ammo_type_live_test @moduletag :ammo_type_live_test
@ -26,14 +26,6 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
"name" => "some updated name", "name" => "some updated name",
"grains" => 456 "grains" => 456
} }
@ammo_group_attrs %{
"notes" => "some ammo group",
"count" => 20
}
@shot_group_attrs %{
"notes" => "some shot group",
"count" => 20
}
# @invalid_attrs %{ # @invalid_attrs %{
# "bullet_type" => nil, # "bullet_type" => nil,
@ -48,15 +40,6 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
%{ammo_type: ammo_type_fixture(@create_attrs, current_user)} %{ammo_type: ammo_type_fixture(@create_attrs, current_user)}
end end
defp create_empty_ammo_group(%{ammo_type: ammo_type, current_user: current_user}) do
container = container_fixture(current_user)
{1, [ammo_group]} = ammo_group_fixture(@ammo_group_attrs, ammo_type, container, current_user)
shot_group = shot_group_fixture(@shot_group_attrs, current_user, ammo_group)
ammo_group = ammo_group |> Repo.reload!()
%{ammo_group: ammo_group, shot_group: shot_group}
end
describe "Index" do describe "Index" do
setup [:register_and_log_in_user, :create_ammo_type] setup [:register_and_log_in_user, :create_ammo_type]
@ -122,7 +105,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
end end
end end
describe "Show ammo type" do describe "Show" do
setup [:register_and_log_in_user, :create_ammo_type] setup [:register_and_log_in_user, :create_ammo_type]
test "displays ammo_type", %{conn: conn, ammo_type: ammo_type} do test "displays ammo_type", %{conn: conn, ammo_type: ammo_type} do
@ -156,21 +139,4 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
assert html =~ "some updated bullet_type" assert html =~ "some updated bullet_type"
end end
end end
describe "Show ammo type with empty ammo group" do
setup [:register_and_log_in_user, :create_ammo_type, :create_empty_ammo_group]
test "hides empty ammo groups by default",
%{conn: conn, ammo_type: ammo_type} do
{:ok, show_live, html} = live(conn, Routes.ammo_type_show_path(conn, :show, ammo_type))
assert html =~ gettext("Show used")
refute html =~ "some ammo group"
html = show_live |> element("[data-qa=\"toggle_show_used\"]") |> render_click()
assert html =~ "some ammo group"
assert html =~ "Empty"
end
end
end end

View File

@ -6,7 +6,7 @@ defmodule CanneryWeb.ContainerLiveTest do
use CanneryWeb.ConnCase use CanneryWeb.ConnCase
import Phoenix.LiveViewTest import Phoenix.LiveViewTest
import CanneryWeb.Gettext import CanneryWeb.Gettext
alias Cannery.{Containers, Repo} alias Cannery.Containers
@moduletag :container_live_test @moduletag :container_live_test
@ -22,22 +22,6 @@ defmodule CanneryWeb.ContainerLiveTest do
"name" => "some updated name", "name" => "some updated name",
"type" => "some updated type" "type" => "some updated type"
} }
@ammo_type_attrs %{
"bullet_type" => "some bullet_type",
"case_material" => "some case_material",
"desc" => "some desc",
"manufacturer" => "some manufacturer",
"name" => "some name",
"grains" => 120
}
@ammo_group_attrs %{
"notes" => "some ammo group",
"count" => 20
}
@shot_group_attrs %{
"notes" => "some shot group",
"count" => 20
}
# @invalid_attrs %{desc: nil, location: nil, name: nil, type: nil} # @invalid_attrs %{desc: nil, location: nil, name: nil, type: nil}
@ -46,15 +30,6 @@ defmodule CanneryWeb.ContainerLiveTest do
%{container: container} %{container: container}
end end
defp create_empty_ammo_group(%{container: container, current_user: current_user}) do
ammo_type = ammo_type_fixture(@ammo_type_attrs, current_user)
{1, [ammo_group]} = ammo_group_fixture(@ammo_group_attrs, ammo_type, container, current_user)
shot_group = shot_group_fixture(@shot_group_attrs, current_user, ammo_group)
ammo_group = ammo_group |> Repo.reload!()
%{ammo_group: ammo_group, shot_group: shot_group}
end
describe "Index" do describe "Index" do
setup [:register_and_log_in_user, :create_container] setup [:register_and_log_in_user, :create_container]
@ -159,21 +134,4 @@ defmodule CanneryWeb.ContainerLiveTest do
assert html =~ "some updated location" assert html =~ "some updated location"
end end
end end
describe "Show with empty ammo group" do
setup [:register_and_log_in_user, :create_container, :create_empty_ammo_group]
test "hides empty ammo groups by default",
%{conn: conn, container: container} do
{:ok, show_live, html} = live(conn, Routes.container_show_path(conn, :show, container))
assert html =~ gettext("Show used")
refute html =~ "some ammo group"
html = show_live |> element("[data-qa=\"toggle_show_used\"]") |> render_click()
assert html =~ "some ammo group"
assert html =~ "Empty"
end
end
end end

View File

@ -76,7 +76,7 @@ defmodule Cannery.Fixtures do
def shot_group_fixture(attrs \\ %{}, %User{} = user, %AmmoGroup{} = ammo_group) do def shot_group_fixture(attrs \\ %{}, %User{} = user, %AmmoGroup{} = ammo_group) do
attrs attrs
|> Enum.into(%{ |> Enum.into(%{
"count" => 20, "count" => 25,
"date" => ~N[2022-02-13 03:17:00], "date" => ~N[2022-02-13 03:17:00],
"notes" => "some notes" "notes" => "some notes"
}) })