You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

91 lines
3.0 KiB

defmodule MirageWeb.NoteControllerTest do
use MirageWeb.ConnCase
import Mirage.NoteFixtures
setup :register_and_log_in_user
@create_attrs %{content: "some content", title: "some title", topic_string: "some tag"}
@update_attrs %{
content: "some updated content with link [[@NOTE_ID]]",
topic_string: "some other tag"
}
@invalid_attrs %{content: nil}
describe "index" do
test "lists all notes", %{conn: conn} do
conn = get(conn, Routes.note_path(conn, :index))
assert html_response(conn, 200) =~ "Listing Notes"
end
end
describe "new note" do
test "renders form", %{conn: conn} do
conn = get(conn, Routes.note_path(conn, :new))
assert html_response(conn, 200) =~ "New Note"
end
end
describe "create note" do
test "redirects to show when data is valid", %{conn: conn} do
conn = post(conn, Routes.note_path(conn, :create), note: @create_attrs)
assert %{id: id} = redirected_params(conn)
assert redirected_to(conn) == Routes.live_path(conn, MirageWeb.ShowNoteLive, id)
conn = get(conn, Routes.live_path(conn, MirageWeb.ShowNoteLive, id))
assert html_response(conn, 200) =~ "some title"
assert html_response(conn, 200) =~ "some tag"
end
test "renders errors when data is invalid", %{conn: conn} do
conn = post(conn, Routes.note_path(conn, :create), note: @invalid_attrs)
assert html_response(conn, 200) =~ "New Note"
end
end
describe "edit note" do
setup [:create_note]
test "renders form for editing chosen note", %{conn: conn, note: note} do
conn = get(conn, Routes.note_path(conn, :edit, note))
assert html_response(conn, 200) =~ "Edit Note"
end
end
describe "update note" do
setup [:create_note]
test "redirects when data is valid", %{conn: conn, note: note} do
attrs =
Map.update!(@update_attrs, :content, fn content ->
String.replace(content, "@NOTE_ID", to_string(note.id))
end)
conn = put(conn, Routes.note_path(conn, :update, note), note: attrs)
assert redirected_to(conn) == Routes.live_path(conn, MirageWeb.ShowNoteLive, note)
conn = get(conn, Routes.live_path(conn, MirageWeb.ShowNoteLive, note))
assert html_response(conn, 200) =~ "some updated content with link"
assert html_response(conn, 200) =~ "some other tag"
refute html_response(conn, 200) =~ "some tag"
end
test "renders errors when data is invalid", %{conn: conn, note: note} do
conn = put(conn, Routes.note_path(conn, :update, note), note: @invalid_attrs)
assert html_response(conn, 200) =~ "Edit Note"
end
end
describe "delete note" do
setup [:create_note]
test "deletes chosen note", %{conn: conn, note: note} do
conn = delete(conn, Routes.note_path(conn, :delete, note))
assert redirected_to(conn) == Routes.note_path(conn, :index)
assert_error_sent 404, fn ->
get(conn, Routes.live_path(conn, MirageWeb.ShowNoteLive, note))
end
end
end
end