defmodule HomemanWeb.TaskLiveTest do use HomemanWeb.ConnCase import Phoenix.LiveViewTest import Homeman.AccountsFixtures @create_attrs %{description: "some description", phase: "some phase", emoji: "some emoji", completed_at: "2024-01-21T05:40:00"} @update_attrs %{description: "some updated description", phase: "some updated phase", emoji: "some updated emoji", completed_at: "2024-01-22T05:40:00"} @invalid_attrs %{description: nil, phase: nil, emoji: nil, completed_at: nil} defp create_task(_) do task = task_fixture() %{task: task} end describe "Index" do setup [:create_task] test "lists all tasks", %{conn: conn, task: task} do {:ok, _index_live, html} = live(conn, ~p"/tasks") assert html =~ "Listing Tasks" assert html =~ task.description end test "saves new task", %{conn: conn} do {:ok, index_live, _html} = live(conn, ~p"/tasks") assert index_live |> element("a", "New Task") |> render_click() =~ "New Task" assert_patch(index_live, ~p"/tasks/new") assert index_live |> form("#task-form", task: @invalid_attrs) |> render_change() =~ "can't be blank" assert index_live |> form("#task-form", task: @create_attrs) |> render_submit() assert_patch(index_live, ~p"/tasks") html = render(index_live) assert html =~ "Task created successfully" assert html =~ "some description" end test "updates task in listing", %{conn: conn, task: task} do {:ok, index_live, _html} = live(conn, ~p"/tasks") assert index_live |> element("#tasks-#{task.id} a", "Edit") |> render_click() =~ "Edit Task" assert_patch(index_live, ~p"/tasks/#{task}/edit") assert index_live |> form("#task-form", task: @invalid_attrs) |> render_change() =~ "can't be blank" assert index_live |> form("#task-form", task: @update_attrs) |> render_submit() assert_patch(index_live, ~p"/tasks") html = render(index_live) assert html =~ "Task updated successfully" assert html =~ "some updated description" end test "deletes task in listing", %{conn: conn, task: task} do {:ok, index_live, _html} = live(conn, ~p"/tasks") assert index_live |> element("#tasks-#{task.id} a", "Delete") |> render_click() refute has_element?(index_live, "#tasks-#{task.id}") end end describe "Show" do setup [:create_task] test "displays task", %{conn: conn, task: task} do {:ok, _show_live, html} = live(conn, ~p"/tasks/#{task}") assert html =~ "Show Task" assert html =~ task.description end test "updates task within modal", %{conn: conn, task: task} do {:ok, show_live, _html} = live(conn, ~p"/tasks/#{task}") assert show_live |> element("a", "Edit") |> render_click() =~ "Edit Task" assert_patch(show_live, ~p"/tasks/#{task}/show/edit") assert show_live |> form("#task-form", task: @invalid_attrs) |> render_change() =~ "can't be blank" assert show_live |> form("#task-form", task: @update_attrs) |> render_submit() assert_patch(show_live, ~p"/tasks/#{task}") html = render(show_live) assert html =~ "Task updated successfully" assert html =~ "some updated description" end end end