add 記事の追加
This commit is contained in:
parent
2031881803
commit
1f3124f3f8
3 changed files with 32 additions and 25 deletions
|
|
@ -65,6 +65,7 @@ defmodule PhoenixRealWorldWeb.ArticleLive.FormComponent do
|
|||
end
|
||||
|
||||
defp save_article(socket, :new, article_params) do
|
||||
article_params = Map.put(article_params, "user_id", socket.assigns.current_user.id)
|
||||
case Blogs.create_article(article_params) do
|
||||
{:ok, article} ->
|
||||
notify_parent({:saved, article})
|
||||
|
|
|
|||
|
|
@ -18,16 +18,16 @@
|
|||
<div class="sr-only">
|
||||
<.link navigate={~p"/articles/#{article}"}>Show</.link>
|
||||
</div>
|
||||
<.link patch={~p"/articles/#{article}/edit"}>Edit</.link>
|
||||
<%!-- <.link patch={~p"/articles/#{article}/edit"}>Edit</.link> --%>
|
||||
</:action>
|
||||
<:action :let={{id, article}}>
|
||||
<%!-- <:action :let={{id, article}}>
|
||||
<.link
|
||||
phx-click={JS.push("delete", value: %{id: article.id}) |> hide("##{id}")}
|
||||
data-confirm="Are you sure?"
|
||||
>
|
||||
Delete
|
||||
</.link>
|
||||
</:action>
|
||||
</:action> --%>
|
||||
</.table>
|
||||
|
||||
<.modal :if={@live_action in [:new, :edit]} id="article-modal" show on_cancel={JS.patch(~p"/articles")}>
|
||||
|
|
@ -37,6 +37,7 @@
|
|||
title={@page_title}
|
||||
action={@live_action}
|
||||
article={@article}
|
||||
current_user={@current_user}
|
||||
patch={~p"/articles"}
|
||||
/>
|
||||
</.modal>
|
||||
|
|
|
|||
|
|
@ -24,7 +24,12 @@ defmodule PhoenixRealWorldWeb.ArticleLiveTest do
|
|||
end
|
||||
|
||||
test "saves new article", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/articles")
|
||||
# {:ok, index_live, _html} = live(conn, ~p"/articles")
|
||||
#↓追加
|
||||
{:ok, index_live, _html} =
|
||||
conn
|
||||
|> log_in_user(user_fixture())
|
||||
|> live(~p"/articles")
|
||||
|
||||
assert index_live |> element("a", "New Article") |> render_click() =~
|
||||
"New Article"
|
||||
|
|
@ -46,35 +51,35 @@ defmodule PhoenixRealWorldWeb.ArticleLiveTest do
|
|||
assert html =~ "some title"
|
||||
end
|
||||
|
||||
test "updates article in listing", %{conn: conn, article: article} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/articles")
|
||||
# test "updates article in listing", %{conn: conn, article: article} do
|
||||
# {:ok, index_live, _html} = live(conn, ~p"/articles")
|
||||
|
||||
assert index_live |> element("#articles-#{article.id} a", "Edit") |> render_click() =~
|
||||
"Edit Article"
|
||||
# assert index_live |> element("#articles-#{article.id} a", "Edit") |> render_click() =~
|
||||
# "Edit Article"
|
||||
|
||||
assert_patch(index_live, ~p"/articles/#{article}/edit")
|
||||
# assert_patch(index_live, ~p"/articles/#{article}/edit")
|
||||
|
||||
assert index_live
|
||||
|> form("#article-form", article: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
# assert index_live
|
||||
# |> form("#article-form", article: @invalid_attrs)
|
||||
# |> render_change() =~ "can't be blank"
|
||||
|
||||
assert index_live
|
||||
|> form("#article-form", article: @update_attrs)
|
||||
|> render_submit()
|
||||
# assert index_live
|
||||
# |> form("#article-form", article: @update_attrs)
|
||||
# |> render_submit()
|
||||
|
||||
assert_patch(index_live, ~p"/articles")
|
||||
# assert_patch(index_live, ~p"/articles")
|
||||
|
||||
html = render(index_live)
|
||||
assert html =~ "Article updated successfully"
|
||||
assert html =~ "some updated title"
|
||||
end
|
||||
# html = render(index_live)
|
||||
# assert html =~ "Article updated successfully"
|
||||
# assert html =~ "some updated title"
|
||||
# end
|
||||
|
||||
test "deletes article in listing", %{conn: conn, article: article} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/articles")
|
||||
# test "deletes article in listing", %{conn: conn, article: article} do
|
||||
# {:ok, index_live, _html} = live(conn, ~p"/articles")
|
||||
|
||||
assert index_live |> element("#articles-#{article.id} a", "Delete") |> render_click()
|
||||
refute has_element?(index_live, "#articles-#{article.id}")
|
||||
end
|
||||
# assert index_live |> element("#articles-#{article.id} a", "Delete") |> render_click()
|
||||
# refute has_element?(index_live, "#articles-#{article.id}")
|
||||
# end
|
||||
end
|
||||
|
||||
describe "Show" do
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue