work on contexts

This commit is contained in:
2022-11-24 12:44:34 -05:00
parent a0a0697f2d
commit cc11491106
18 changed files with 771 additions and 249 deletions

View File

@ -23,18 +23,17 @@ defmodule MemexWeb.ContextLiveTest do
"visibility" => nil
}
defp create_context(_) do
context = context_fixture()
%{context: context}
defp create_context(%{user: user}) do
[context: context_fixture(user)]
end
describe "Index" do
setup [:create_context]
setup [:register_and_log_in_user, :create_context]
test "lists all contexts", %{conn: conn, context: context} do
{:ok, _index_live, html} = live(conn, Routes.context_index_path(conn, :index))
assert html =~ "listing contexts"
assert html =~ "contexts"
assert html =~ context.content
end
@ -56,15 +55,15 @@ defmodule MemexWeb.ContextLiveTest do
|> render_submit()
|> follow_redirect(conn, Routes.context_index_path(conn, :index))
assert html =~ "context created successfully"
assert html =~ "#{@create_attrs |> Map.get("title")} created"
assert html =~ "some content"
end
test "updates context in listing", %{conn: conn, context: context} do
{:ok, index_live, _html} = live(conn, Routes.context_index_path(conn, :index))
assert index_live |> element("#context-#{context.id} a", "edit") |> render_click() =~
"edit context"
assert index_live |> element("[data-qa=\"context-edit-#{context.id}\"]") |> render_click() =~
"edit"
assert_patch(index_live, Routes.context_index_path(conn, :edit, context))
@ -78,20 +77,20 @@ defmodule MemexWeb.ContextLiveTest do
|> render_submit()
|> follow_redirect(conn, Routes.context_index_path(conn, :index))
assert html =~ "context updated successfully"
assert html =~ "#{@update_attrs |> Map.get("title")} saved"
assert html =~ "some updated content"
end
test "deletes context in listing", %{conn: conn, context: context} do
{:ok, index_live, _html} = live(conn, Routes.context_index_path(conn, :index))
assert index_live |> element("#context-#{context.id} a", "delete") |> render_click()
assert index_live |> element("[data-qa=\"delete-context-#{context.id}\"]") |> render_click()
refute has_element?(index_live, "#context-#{context.id}")
end
end
describe "show" do
setup [:create_context]
setup [:register_and_log_in_user, :create_context]
test "displays context", %{conn: conn, context: context} do
{:ok, _show_live, html} = live(conn, Routes.context_show_path(conn, :show, context))
@ -103,8 +102,7 @@ defmodule MemexWeb.ContextLiveTest do
test "updates context within modal", %{conn: conn, context: context} do
{:ok, show_live, _html} = live(conn, Routes.context_show_path(conn, :show, context))
assert show_live |> element("a", "edit") |> render_click() =~
"edit context"
assert show_live |> element("a", "edit") |> render_click() =~ "edit"
assert_patch(show_live, Routes.context_show_path(conn, :edit, context))
@ -118,8 +116,20 @@ defmodule MemexWeb.ContextLiveTest do
|> render_submit()
|> follow_redirect(conn, Routes.context_show_path(conn, :show, context))
assert html =~ "context updated successfully"
assert html =~ "#{@update_attrs |> Map.get("title")} saved"
assert html =~ "some updated content"
end
test "deletes context", %{conn: conn, context: context} do
{:ok, show_live, _html} = live(conn, Routes.context_show_path(conn, :show, context))
{:ok, index_live, _html} =
show_live
|> element("[data-qa=\"delete-context-#{context.id}\"]")
|> render_click()
|> follow_redirect(conn, Routes.context_index_path(conn, :index))
refute has_element?(index_live, "#context-#{context.id}")
end
end
end