My space on the web https://inhji.de
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.
 
 
 
 
 

175 lines
5.3 KiB

defmodule Mirage.NotesTest do
use Mirage.DataCase
alias Mirage.Notes
describe "notes" do
alias Mirage.Notes.Note
@valid_attrs %{content: "some content", title: "some title"}
@update_attrs %{content: "some updated content"}
@update_attrs_with_link %{
content: "some updated content with a reference [[@OWN_ID]] [[@NOTE_ID]]"
}
@update_attrs_with_link_and_title %{
content: "some updated content with a reference [[@OWN_ID|Link to myself]] [[@NOTE_ID]]"
}
@invalid_attrs %{content: nil}
def note_fixture(attrs \\ %{}) do
{:ok, note} =
attrs
|> Enum.into(@valid_attrs)
|> Notes.create_note()
note
|> Notes.preload_note()
end
test "list_notes/0 returns all notes" do
note = note_fixture()
assert Notes.list_notes() == [note]
end
test "get_note!/1 returns the note with given id" do
note = note_fixture()
assert Notes.get_note!(note.id) |> Notes.preload_note() == note
end
test "create_note/1 with valid data creates a note" do
assert {:ok, %Note{} = note} = Notes.create_note(@valid_attrs)
assert note.content == "some content"
assert note.title == "some title"
end
test "create_note/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Notes.create_note(@invalid_attrs)
end
test "update_note/2 with valid data updates the note" do
note = note_fixture()
assert {:ok, %Note{} = note} = Notes.update_note(note, @update_attrs)
assert note.content == "some updated content"
end
test "update_note/2 with a cross-ref link renders a link to the referenced note" do
note = note_fixture()
attrs =
Map.update!(@update_attrs_with_link, :content, fn content ->
content
|> String.replace("@OWN_ID", to_string(note.id))
|> String.replace("@NOTE_ID", to_string(note.id + 1))
end)
assert {:ok, %Note{} = note} = Notes.update_note(note, attrs)
assert note.content ==
"some updated content with a reference [[#{note.id}]] [[#{note.id + 1}]]"
assert note.content_html =~ "#{note.title}"
end
test "update_note/2 with a cross-ref link and title renders a link to the referenced note" do
note = note_fixture()
attrs =
Map.update!(@update_attrs_with_link_and_title, :content, fn content ->
content
|> String.replace("@OWN_ID", to_string(note.id))
|> String.replace("@NOTE_ID", to_string(note.id + 1))
end)
assert {:ok, %Note{} = note} = Notes.update_note(note, attrs)
assert note.content ==
"some updated content with a reference [[#{note.id}|Link to myself]] [[#{
note.id + 1
}]]"
assert note.content_html =~ "Link to myself"
note =
Notes.get_note!(note.id)
|> Notes.preload_note()
IO.inspect(note)
end
test "update_note/2 with invalid data returns error changeset" do
note = note_fixture()
assert {:error, %Ecto.Changeset{}} = Notes.update_note(note, @invalid_attrs)
assert note == Notes.get_note!(note.id) |> Notes.preload_note()
end
test "delete_note/1 deletes the note" do
note = note_fixture()
assert {:ok, %Note{}} = Notes.delete_note(note)
assert_raise Ecto.NoResultsError, fn -> Notes.get_note!(note.id) end
end
test "change_note/1 returns a note changeset" do
note = note_fixture()
assert %Ecto.Changeset{} = Notes.change_note(note)
end
end
describe "topics" do
alias Mirage.Notes.Topic
@valid_attrs %{text: "some text"}
@update_attrs %{text: "some updated text"}
@invalid_attrs %{text: nil}
def topic_fixture(attrs \\ %{}) do
{:ok, topic} =
attrs
|> Enum.into(@valid_attrs)
|> Notes.create_topic()
topic
end
test "list_topics/0 returns all topics" do
topic = topic_fixture() |> Notes.preload_topic()
assert Notes.list_topics() == [topic]
end
test "get_topic!/1 returns the topic with given id" do
topic = topic_fixture()
assert Notes.get_topic!(topic.id) == topic
end
test "create_topic/1 with valid data creates a topic" do
assert {:ok, %Topic{} = topic} = Notes.create_topic(@valid_attrs)
assert topic.text == "some text"
end
test "create_topic/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Notes.create_topic(@invalid_attrs)
end
test "update_topic/2 with valid data updates the topic" do
topic = topic_fixture()
assert {:ok, topic} = Notes.update_topic(topic, @update_attrs)
assert topic.text == "some updated text"
end
test "update_topic/2 with invalid data returns error changeset" do
topic = topic_fixture()
assert {:error, %Ecto.Changeset{}} = Notes.update_topic(topic, @invalid_attrs)
assert topic == Notes.get_topic!(topic.id)
end
test "delete_topic/1 deletes the topic" do
topic = topic_fixture()
assert {:ok, %Topic{}} = Notes.delete_topic(topic)
assert_raise Ecto.NoResultsError, fn -> Notes.get_topic!(topic.id) end
end
test "change_topic/1 returns a topic changeset" do
topic = topic_fixture()
assert %Ecto.Changeset{} = Notes.change_topic(topic)
end
end
end