defmodule DingeWeb.DingLiveTest do use DingeWeb.ConnCase import Phoenix.LiveViewTest import Dinge.LedgerFixtures @create_attrs %{count: 42, status: :active, title: "some title", target_count: 42, ding_type: :countdown, target_type: :default} @update_attrs %{count: 43, status: :inactive, title: "some updated title", target_count: 43, ding_type: :countup, target_type: :daily} @invalid_attrs %{count: nil, status: nil, title: nil, target_count: nil, ding_type: nil, target_type: nil} defp create_ding(_) do ding = ding_fixture() %{ding: ding} end describe "Index" do setup [:create_ding] test "lists all dings", %{conn: conn, ding: ding} do {:ok, _index_live, html} = live(conn, ~p"/dings") assert html =~ "Listing Dings" assert html =~ ding.title end test "saves new ding", %{conn: conn} do {:ok, index_live, _html} = live(conn, ~p"/dings") assert index_live |> element("a", "New Ding") |> render_click() =~ "New Ding" assert_patch(index_live, ~p"/dings/new") assert index_live |> form("#ding-form", ding: @invalid_attrs) |> render_change() =~ "can't be blank" assert index_live |> form("#ding-form", ding: @create_attrs) |> render_submit() assert_patch(index_live, ~p"/dings") html = render(index_live) assert html =~ "Ding created successfully" assert html =~ "some title" end test "updates ding in listing", %{conn: conn, ding: ding} do {:ok, index_live, _html} = live(conn, ~p"/dings") assert index_live |> element("#dings-#{ding.id} a", "Edit") |> render_click() =~ "Edit Ding" assert_patch(index_live, ~p"/dings/#{ding}/edit") assert index_live |> form("#ding-form", ding: @invalid_attrs) |> render_change() =~ "can't be blank" assert index_live |> form("#ding-form", ding: @update_attrs) |> render_submit() assert_patch(index_live, ~p"/dings") html = render(index_live) assert html =~ "Ding updated successfully" assert html =~ "some updated title" end test "deletes ding in listing", %{conn: conn, ding: ding} do {:ok, index_live, _html} = live(conn, ~p"/dings") assert index_live |> element("#dings-#{ding.id} a", "Delete") |> render_click() refute has_element?(index_live, "#dings-#{ding.id}") end end describe "Show" do setup [:create_ding] test "displays ding", %{conn: conn, ding: ding} do {:ok, _show_live, html} = live(conn, ~p"/dings/#{ding}") assert html =~ "Show Ding" assert html =~ ding.title end test "updates ding within modal", %{conn: conn, ding: ding} do {:ok, show_live, _html} = live(conn, ~p"/dings/#{ding}") assert show_live |> element("a", "Edit") |> render_click() =~ "Edit Ding" assert_patch(show_live, ~p"/dings/#{ding}/show/edit") assert show_live |> form("#ding-form", ding: @invalid_attrs) |> render_change() =~ "can't be blank" assert show_live |> form("#ding-form", ding: @update_attrs) |> render_submit() assert_patch(show_live, ~p"/dings/#{ding}") html = render(show_live) assert html =~ "Ding updated successfully" assert html =~ "some updated title" end end end