add ammo type live test for empty ammo groups

This commit is contained in:
shibao 2022-11-08 20:36:03 -05:00
parent 1d8f3360d8
commit ffd1029e78
3 changed files with 39 additions and 4 deletions

View File

@ -95,11 +95,12 @@ 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

@ -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 alias Cannery.{Ammo, Repo}
@moduletag :ammo_type_live_test @moduletag :ammo_type_live_test
@ -26,6 +26,14 @@ 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,
@ -40,6 +48,15 @@ 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]
@ -105,7 +122,7 @@ defmodule CanneryWeb.AmmoTypeLiveTest do
end end
end end
describe "Show" do describe "Show ammo type" 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
@ -139,4 +156,21 @@ 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

@ -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" => 25, "count" => 20,
"date" => ~N[2022-02-13 03:17:00], "date" => ~N[2022-02-13 03:17:00],
"notes" => "some notes" "notes" => "some notes"
}) })