Browse Source

test: add test for show_note_live

main
Inhji Y. 7 months ago
parent
commit
3dc219e612
  1. 13
      test/mirage_web/controllers/note_controller_test.exs
  2. 18
      test/mirage_web/live/show_note_live_test.exs
  3. 18
      test/support/fixtures/note_fixtures.ex

13
test/mirage_web/controllers/note_controller_test.exs

@ -1,7 +1,6 @@
defmodule MirageWeb.NoteControllerTest do
use MirageWeb.ConnCase
alias Mirage.Notes
import Mirage.NoteFixtures
setup :register_and_log_in_user
@ -12,11 +11,6 @@ defmodule MirageWeb.NoteControllerTest do
}
@invalid_attrs %{content: nil}
def fixture(:note) do
{:ok, note} = Notes.create_note(@create_attrs)
note
end
describe "index" do
test "lists all notes", %{conn: conn} do
conn = get(conn, Routes.note_path(conn, :index))
@ -94,9 +88,4 @@ defmodule MirageWeb.NoteControllerTest do
end
end
end
defp create_note(_) do
note = fixture(:note)
%{note: note}
end
end

18
test/mirage_web/live/show_note_live_test.exs

@ -0,0 +1,18 @@
defmodule MirageWeb.ShowNoteLiveTest do
use MirageWeb.ConnCase
import Phoenix.LiveViewTest
import Mirage.NoteFixtures
describe "show note" do
setup [:create_note]
test "disconnected and connected render", %{conn: conn, note: note} do
{:ok, page_live, disconnected_html} = live(conn, "/notes/#{note.id}")
assert disconnected_html =~ note.title
assert disconnected_html =~ note.content
assert render(page_live) =~ note.title
assert render(page_live) =~ note.content
end
end
end

18
test/support/fixtures/note_fixtures.ex

@ -0,0 +1,18 @@
defmodule Mirage.NoteFixtures do
@moduledoc """
This module defines test helpers for creating
entities via the `Mirage.Notes` context.
"""
@create_attrs %{content: "some content", title: "some title", topic_string: "some tag"}
def fixture(:note) do
{:ok, note} = Mirage.Notes.create_note(@create_attrs)
note
end
def create_note(_) do
note = fixture(:note)
%{note: note}
end
end
Loading…
Cancel
Save