Compare commits

...

3 Commits

  1. 13
      CHANGELOG.md
  2. 3
      assets/css/app.scss
  3. BIN
      assets/static/images/phoenix.png
  4. 64
      lib/mirage/links.ex
  5. 19
      lib/mirage/links/link.ex
  6. 18
      lib/mirage/links/note_link.ex
  7. 8
      lib/mirage/notes.ex
  8. 4
      lib/mirage/notes/note.ex
  9. 20
      lib/mirage/notes/note_link.ex
  10. 28
      lib/mirage_web/live/link_live/form_component.ex
  11. 2
      lib/mirage_web/live/link_live/form_component.html.leex
  12. 22
      lib/mirage_web/live/link_live/index.ex
  13. 23
      lib/mirage_web/live/link_live/index.html.leex
  14. 4
      lib/mirage_web/live/link_live/show.ex
  15. 32
      lib/mirage_web/live/link_live/show.html.leex
  16. 8
      lib/mirage_web/live/live_helpers.ex
  17. 23
      lib/mirage_web/live/note_link_live/index.html.leex
  18. 32
      lib/mirage_web/live/note_link_live/show.html.leex
  19. 43
      lib/mirage_web/live/show_note_live.ex
  20. 2
      lib/mirage_web/live/show_note_live.html.leex
  21. 10
      lib/mirage_web/router.ex
  22. 2
      mix.exs
  23. 12
      priv/repo/migrations/20210215182411_add_notes_links_join_table.exs
  24. 19
      priv/repo/migrations/20210215183316_migrate_links_to_join_table.exs
  25. 59
      test/mirage/links_test.exs
  26. 1
      test/mirage_web/controllers/user_registration_controller_test.exs
  27. 1
      test/mirage_web/controllers/user_session_controller_test.exs
  28. 76
      test/mirage_web/live/link_live_test.exs
  29. 76
      test/mirage_web/live/note_link_live_test.exs
  30. 16
      test/support/fixtures/link_fixtures.ex

13
CHANGELOG.md

@ -5,6 +5,19 @@ See [Conventional Commits](Https://conventionalcommits.org) for commit guideline
<!-- changelog -->
## [v0.36.0](https://git.inhji.de/inhji/mirage/compare/v0.35.0...v0.36.0) (2021-02-15)
### Features:
* rename note_link to link
### Bug Fixes:
* delete phoenix image
## [v0.35.0](https://git.inhji.de/inhji/mirage/compare/v0.34.8...v0.35.0) (2021-02-14)

3
assets/css/app.scss

@ -222,7 +222,8 @@ kbd {
display: flex;
padding: 1rem;
border: 1px solid $border-base;
@include color-assign(background-color, on-surface);
@include color-assign(border-color, on-surface);
@include color-assign(background-color, surface);
margin-bottom: 1rem;
a {

BIN
assets/static/images/phoenix.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

64
lib/mirage/links.ex

@ -6,7 +6,7 @@ defmodule Mirage.Links do
import Ecto.Query, warn: false
alias Mirage.Repo
alias Mirage.Links.NoteLink
alias Mirage.Links.Link
@doc """
Returns the list of notes_links.
@ -14,89 +14,89 @@ defmodule Mirage.Links do
## Examples
iex> list_notes_links()
[%NoteLink{}, ...]
[%Link{}, ...]
"""
def list_notes_links do
NoteLink
def list_links do
Link
|> Repo.all()
end
@doc """
Gets a single note_link.
Gets a single link.
Raises if the Note link does not exist.
## Examples
iex> get_note_link!(123)
%NoteLink{}
iex> get_link!(123)
%Link{}
"""
def get_note_link!(id), do: Repo.get!(NoteLink, id)
def get_link!(id), do: Repo.get!(Link, id)
@doc """
Creates a note_link.
Creates a link.
## Examples
iex> create_note_link(%{field: value})
{:ok, %NoteLink{}}
iex> create_link(%{field: value})
{:ok, %Link{}}
iex> create_note_link(%{field: bad_value})
iex> create_link(%{field: bad_value})
{:error, ...}
"""
def create_note_link(attrs \\ %{}) do
%NoteLink{}
|> NoteLink.changeset(attrs)
def create_link(attrs \\ %{}) do
%Link{}
|> Link.changeset(attrs)
|> Repo.insert()
end
@doc """
Updates a note_link.
Updates a link.
## Examples
iex> update_note_link(note_link, %{field: new_value})
{:ok, %NoteLink{}}
iex> update_link(link, %{field: new_value})
{:ok, %Link{}}
iex> update_note_link(note_link, %{field: bad_value})
iex> update_link(link, %{field: bad_value})
{:error, ...}
"""
def update_note_link(%NoteLink{} = note_link, attrs) do
note_link
|> NoteLink.changeset(attrs)
def update_link(%Link{} = link, attrs) do
link
|> Link.changeset(attrs)
|> Repo.update()
end
@doc """
Deletes a NoteLink.
Deletes a Link.
## Examples
iex> delete_note_link(note_link)
{:ok, %NoteLink{}}
iex> delete_link(link)
{:ok, %Link{}}
iex> delete_note_link(note_link)
iex> delete_link(link)
{:error, ...}
"""
def delete_note_link(%NoteLink{} = note_link) do
Repo.delete(note_link)
def delete_link(%Link{} = link) do
Repo.delete(link)
end
@doc """
Returns a data structure for tracking note_link changes.
Returns a data structure for tracking link changes.
## Examples
iex> change_note_link(note_link)
iex> change_link(link)
%Todo{...}
"""
def change_note_link(%NoteLink{} = note_link, attrs \\ %{}) do
NoteLink.changeset(note_link, attrs)
def change_link(%Link{} = link, attrs \\ %{}) do
Link.changeset(link, attrs)
end
end

19
lib/mirage/links/link.ex

@ -0,0 +1,19 @@
defmodule Mirage.Links.Link do
use Ecto.Schema
import Ecto.Changeset
alias Mirage.Notes.Note
schema "links" do
field :title, :string
field :url, :string
many_to_many :note, Note, join_through: "notes_links"
end
@doc false
def changeset(link, attrs) do
link
|> cast(attrs, [:title, :url])
|> validate_required([:url])
end
end

18
lib/mirage/links/note_link.ex

@ -1,18 +0,0 @@
defmodule Mirage.Links.NoteLink do
use Ecto.Schema
import Ecto.Changeset
schema "notes_links" do
field :title, :string
field :url, :string
belongs_to :note, Mirage.Notes.Note
end
@doc false
def changeset(link, attrs) do
link
|> cast(attrs, [:title, :url, :note_id])
|> validate_required([:url, :note_id])
end
end

8
lib/mirage/notes.ex

@ -6,7 +6,7 @@ defmodule Mirage.Notes do
import Ecto.Query, warn: false
alias Mirage.Repo
alias Mirage.Notes.{Note, Topic, NoteNote, NoteTopic}
alias Mirage.Notes.{Note, Topic, NoteNote, NoteTopic, NoteLink}
@note_preloads [:links, :topics, :backlinks]
@topic_preloads [notes: @note_preloads]
@ -337,4 +337,10 @@ defmodule Mirage.Notes do
def change_topic(%Topic{} = topic, attrs \\ %{}) do
Topic.changeset(topic, attrs)
end
def create_note_link(attrs) do
%NoteLink{}
|> NoteLink.changeset(attrs)
|> Repo.insert()
end
end

4
lib/mirage/notes/note.ex

@ -3,14 +3,14 @@ defmodule Mirage.Notes.Note do
import Ecto.Changeset
alias Mirage.Notes.{Topic, Tags, Note}
alias Mirage.Links.NoteLink
alias Mirage.Links.Link
schema "notes" do
field :title, :string
field :content, :string
field :content_html, :string
has_many :links, NoteLink
many_to_many :links, Link, join_through: "notes_links"
many_to_many :topics, Topic, join_through: "notes_topics"
many_to_many :backlinks, Note,

20
lib/mirage/notes/note_link.ex

@ -0,0 +1,20 @@
defmodule Mirage.Notes.NoteLink do
use Ecto.Schema
import Ecto.Changeset
alias Mirage.Notes.Note
alias Mirage.Links.Link
schema "notes_links" do
belongs_to :note, Note
belongs_to :link, Link
end
@attrs [:note_id, :link_id]
@doc false
def changeset(note_link, attrs) do
note_link
|> cast(attrs, @attrs)
|> validate_required(@attrs)
end
end

28
lib/mirage_web/live/note_link_live/form_component.ex → lib/mirage_web/live/link_live/form_component.ex

@ -1,11 +1,11 @@
defmodule MirageWeb.NoteLinkLive.FormComponent do
defmodule MirageWeb.LinkLive.FormComponent do
use MirageWeb, :live_component
alias Mirage.Links
@impl true
def update(%{note_link: note_link} = assigns, socket) do
changeset = Links.change_note_link(note_link)
def update(%{link: link} = assigns, socket) do
changeset = Links.change_link(link)
{:ok,
socket
@ -14,22 +14,22 @@ defmodule MirageWeb.NoteLinkLive.FormComponent do
end
@impl true
def handle_event("validate", %{"note_link" => note_link_params}, socket) do
def handle_event("validate", %{"link" => link_params}, socket) do
changeset =
socket.assigns.note_link
|> Links.change_note_link(note_link_params)
socket.assigns.link
|> Links.change_link(link_params)
|> Map.put(:action, :validate)
{:noreply, assign(socket, :changeset, changeset)}
end
def handle_event("save", %{"note_link" => note_link_params}, socket) do
save_note_link(socket, socket.assigns.action, note_link_params)
def handle_event("save", %{"link" => link_params}, socket) do
save_link(socket, socket.assigns.action, link_params)
end
defp save_note_link(socket, :edit, note_link_params) do
case Links.update_note_link(socket.assigns.note_link, note_link_params) do
{:ok, _note_link} ->
defp save_link(socket, :edit, link_params) do
case Links.update_link(socket.assigns.link, link_params) do
{:ok, _link} ->
{:noreply,
socket
|> put_flash(:info, "Note link updated successfully")
@ -40,9 +40,9 @@ defmodule MirageWeb.NoteLinkLive.FormComponent do
end
end
defp save_note_link(socket, :new, note_link_params) do
case Links.create_note_link(note_link_params) do
{:ok, _note_link} ->
defp save_link(socket, :new, link_params) do
case Links.create_link(link_params) do
{:ok, _link} ->
{:noreply,
socket
|> put_flash(:info, "Note link created successfully")

2
lib/mirage_web/live/note_link_live/form_component.html.leex → lib/mirage_web/live/link_live/form_component.html.leex

@ -1,7 +1,7 @@
<h2><%= @title %></h2>
<%= f = form_for @changeset, "#",
id: "note_link-form",
id: "link-form",
phx_target: @myself,
phx_change: "validate",
phx_submit: "save" %>

22
lib/mirage_web/live/note_link_live/index.ex → lib/mirage_web/live/link_live/index.ex

@ -1,12 +1,12 @@
defmodule MirageWeb.NoteLinkLive.Index do
defmodule MirageWeb.LinkLive.Index do
use MirageWeb, :live_view
alias Mirage.Links
alias Mirage.Links.NoteLink
alias Mirage.Links.Link
@impl true
def mount(_params, _session, socket) do
{:ok, assign(socket, :notes_links, list_notes_links())}
{:ok, assign(socket, :notes_links, Links.list_links())}
end
@impl true
@ -17,30 +17,30 @@ defmodule MirageWeb.NoteLinkLive.Index do
defp apply_action(socket, :edit, %{"id" => id}) do
socket
|> assign(:page_title, "Edit Note link")
|> assign(:note_link, Links.get_note_link!(id))
|> assign(:link, Links.get_link!(id))
end
defp apply_action(socket, :new, _params) do
socket
|> assign(:page_title, "New Note link")
|> assign(:note_link, %NoteLink{})
|> assign(:link, %Link{})
end
defp apply_action(socket, :index, _params) do
socket
|> assign(:page_title, "Listing Notes links")
|> assign(:note_link, nil)
|> assign(:link, nil)
end
@impl true
def handle_event("delete", %{"id" => id}, socket) do
note_link = Links.get_note_link!(id)
{:ok, _} = Links.delete_note_link(note_link)
link = Links.get_link!(id)
{:ok, _} = Links.delete_link(link)
{:noreply, assign(socket, :notes_links, list_notes_links())}
{:noreply, assign(socket, :notes_links, list_links())}
end
defp list_notes_links do
Links.list_notes_links()
defp list_links do
Links.list_links()
end
end

23
lib/mirage_web/live/link_live/index.html.leex

@ -0,0 +1,23 @@
<header class="hero">
<h1>Listing Links</h1>
</header>
<%= if @live_action in [:new, :edit] do %>
<%= live_modal @socket, MirageWeb.LinkLive.FormComponent,
id: @link.id || :new,
title: @page_title,
action: @live_action,
link: @link,
return_to: Routes.link_index_path(@socket, :index) %>
<% end %>
<section class="bg-content width-full grid cards wrap">
<%= for link <- @notes_links do %>
<%= live_redirect to: Routes.link_show_path(@socket, :show, link), class: "col card", id: "link-#{link.id}" do %>
<strong><%= link.title %></strong>
<p><%= link.url %></p>
<% end %>
<% end %>
</section>

4
lib/mirage_web/live/note_link_live/show.ex → lib/mirage_web/live/link_live/show.ex

@ -1,4 +1,4 @@
defmodule MirageWeb.NoteLinkLive.Show do
defmodule MirageWeb.LinkLive.Show do
use MirageWeb, :live_view
alias Mirage.Links
@ -13,7 +13,7 @@ defmodule MirageWeb.NoteLinkLive.Show do
{:noreply,
socket
|> assign(:page_title, page_title(socket.assigns.live_action))
|> assign(:note_link, Links.get_note_link!(id))}
|> assign(:link, Links.get_link!(id))}
end
defp page_title(:show), do: "Show Note link"

32
lib/mirage_web/live/link_live/show.html.leex

@ -0,0 +1,32 @@
<header class="hero">
<h1>Show Note link</h1>
</header>
<%= if @live_action in [:edit] do %>
<%= live_modal @socket, MirageWeb.LinkLive.FormComponent,
id: @link.id,
title: @page_title,
action: @live_action,
link: @link,
return_to: Routes.link_show_path(@socket, :show, @link) %>
<% end %>
<ul>
<li>
<strong>Title:</strong>
<%= @link.title %>
</li>
<li>
<strong>Url:</strong>
<%= @link.url %>
</li>
</ul>
<div class="buttons">
<%= live_patch "Edit", to: Routes.link_show_path(@socket, :edit, @link), class: "button", class: "button" %>
<%= live_redirect "Back", to: Routes.link_index_path(@socket, :index), class: "button" %>
<%= link "Delete", to: "#", phx_click: "delete", phx_value_id: @link.id, data: [confirm: "Are you sure?"], class: "button" %>
</div>

8
lib/mirage_web/live/live_helpers.ex

@ -9,11 +9,11 @@ defmodule MirageWeb.LiveHelpers do
## Examples
<%= live_modal @socket, MirageWeb.NoteLinkLive.FormComponent,
id: @note_link.id || :new,
<%= live_modal @socket, MirageWeb.LinkLive.FormComponent,
id: @link.id || :new,
action: @live_action,
note_link: @note_link,
return_to: Routes.note_link_index_path(@socket, :index) %>
link: @link,
return_to: Routes.link_index_path(@socket, :index) %>
"""
def live_modal(socket, component, opts) do
path = Keyword.fetch!(opts, :return_to)

23
lib/mirage_web/live/note_link_live/index.html.leex

@ -1,23 +0,0 @@
<header class="hero">
<h1>Listing Links</h1>
</header>
<%= if @live_action in [:new, :edit] do %>
<%= live_modal @socket, MirageWeb.NoteLinkLive.FormComponent,
id: @note_link.id || :new,
title: @page_title,
action: @live_action,
note_link: @note_link,
return_to: Routes.note_link_index_path(@socket, :index) %>
<% end %>
<section class="bg-content width-full grid cards wrap">
<%= for note_link <- @notes_links do %>
<%= live_redirect to: Routes.note_link_show_path(@socket, :show, note_link), class: "col card", id: "note_link-#{note_link.id}" do %>
<strong><%= note_link.title %></strong>
<p><%= note_link.url %></p>
<% end %>
<% end %>
</section>

32
lib/mirage_web/live/note_link_live/show.html.leex

@ -1,32 +0,0 @@
<header class="hero">
<h1>Show Note link</h1>
</header>
<%= if @live_action in [:edit] do %>
<%= live_modal @socket, MirageWeb.NoteLinkLive.FormComponent,
id: @note_link.id,
title: @page_title,
action: @live_action,
note_link: @note_link,
return_to: Routes.note_link_show_path(@socket, :show, @note_link) %>
<% end %>
<ul>
<li>
<strong>Title:</strong>
<%= @note_link.title %>
</li>
<li>
<strong>Url:</strong>
<%= @note_link.url %>
</li>
</ul>
<div class="buttons">
<%= live_patch "Edit", to: Routes.note_link_show_path(@socket, :edit, @note_link), class: "button", class: "button" %>
<%= live_redirect "Back", to: Routes.note_link_index_path(@socket, :index), class: "button" %>
<%= link "Delete", to: "#", phx_click: "delete", phx_value_id: @note_link.id, data: [confirm: "Are you sure?"], class: "button" %>
</div>

43
lib/mirage_web/live/show_note_live.ex

@ -2,8 +2,9 @@ defmodule MirageWeb.ShowNoteLive do
use MirageWeb, :live_view
alias Mirage.Notes
alias Mirage.Notes.NoteLink
alias Mirage.Links
alias Mirage.Links.NoteLink
alias Mirage.Links.Link
@impl true
def mount(_params, %{"user_id" => user_id}, socket) do
@ -18,13 +19,13 @@ defmodule MirageWeb.ShowNoteLive do
|> Notes.get_note!()
|> Notes.preload_note()
link_changeset = NoteLink.changeset(%NoteLink{}, %{note_id: note_id})
link_changeset = Link.changeset(%Link{}, %{note_id: note_id})
{:noreply, socket |> assign(%{note: note, link_changeset: link_changeset})}
end
def handle_event("delete_link", %{"link-id" => link_id}, socket) do
link = Links.get_note_link!(link_id)
{:ok, _} = Links.delete_note_link(link)
link = Links.get_link!(link_id)
{:ok, _} = Links.delete_link(link)
note =
socket.assigns.note.id
@ -35,23 +36,23 @@ defmodule MirageWeb.ShowNoteLive do
end
@impl true
def handle_event("save_link", %{"note_link" => link}, socket) do
case Links.create_note_link(link) do
{:ok, _link} ->
note_id = socket.assigns.note.id
note =
note_id
|> Notes.get_note!()
|> Notes.preload_note()
{:noreply,
socket
|> assign(%{
note: note,
link_changeset: NoteLink.changeset(%NoteLink{}, %{note_id: note_id})
})}
def handle_event("save_link", %{"link" => link}, socket) do
note_id = socket.assigns.note.id
with {:ok, link} <- Links.create_link(link),
{:ok, note_link} <- Notes.create_note_link(%{link_id: link.id, note_id: note_id}) do
note =
note_id
|> Notes.get_note!()
|> Notes.preload_note()
{:noreply,
socket
|> assign(%{
note: note,
link_changeset: Link.changeset(%Link{}, %{note_id: note_id})
})}
else
_ ->
{:noreply, socket}
end

2
lib/mirage_web/live/show_note_live.html.leex

@ -34,7 +34,7 @@
<div class="link-wrapper">
<%= link link.title || link.url, to: link.url, class: "link" %>
<%= if @current_user do %>
<%= link "🗑️ DELETE", to: "#", phx_click: "delete_link", phx_value_link_id: link.id %>
<%= link "🗑️ DELETE", to: "#", phx_click: "delete_link", phx_value_link_id: link.id, data: [confirm: "Are you sure?"] %>
<% end %>
</div>
<% end %>

10
lib/mirage_web/router.ex

@ -32,12 +32,12 @@ defmodule MirageWeb.Router do
resources "/topics", TopicController
resources "/settings", SettingController, only: [:index, :show, :edit, :update]
live "/links", NoteLinkLive.Index, :index
live "/links/new", NoteLinkLive.Index, :new
live "/links/:id/edit", NoteLinkLive.Index, :edit
live "/links", LinkLive.Index, :index
live "/links/new", LinkLive.Index, :new
live "/links/:id/edit", LinkLive.Index, :edit
live "/links/:id", NoteLinkLive.Show, :show
live "/links/:id/show/edit", NoteLinkLive.Show, :edit
live "/links/:id", LinkLive.Show, :show
live "/links/:id/show/edit", LinkLive.Show, :edit
live "/notes/:id", ShowNoteLive
end

2
mix.exs

@ -1,7 +1,7 @@
defmodule Mirage.MixProject do
use Mix.Project
@version "0.35.0"
@version "0.36.0"
def project do
[

12
priv/repo/migrations/20210215182411_add_notes_links_join_table.exs

@ -0,0 +1,12 @@
defmodule Mirage.Repo.Migrations.AddNotesLinksJoinTable do
use Ecto.Migration
def change do
rename table(:notes_links), to: table(:links)
create table(:notes_links) do
add :note_id, references(:notes, on_delete: :delete_all)
add :link_id, references(:links, on_delete: :delete_all)
end
end
end

19
priv/repo/migrations/20210215183316_migrate_links_to_join_table.exs

@ -0,0 +1,19 @@
defmodule Mirage.Repo.Migrations.MigrateLinksToJoinTable do
use Ecto.Migration
import Ecto.Query
def change do
execute(&link_join_up/0, &link_join_down/0)
end
def link_join_up() do
links = repo().all(from l in Mirage.Links.Link)
|> Enum.map(fn l -> %{note_id: l.note_id, link_id: l.id} end)
repo().insert_all("notes_links", links)
end
def link_join_down() do
repo().query!("DELETE FROM notes_links")
end
end

59
test/mirage/links_test.exs

@ -1,11 +1,11 @@
defmodule Mirage.LinksTest do
use Mirage.DataCase
import Mirage.NoteLinkFixtures
import Mirage.LinkFixtures
import Mirage.NoteFixtures
alias Mirage.Links
alias Mirage.Links.NoteLink
alias Mirage.Links.Link
describe "notes_links" do
setup [:create_note]
@ -15,49 +15,48 @@ defmodule Mirage.LinksTest do
@invalid_attrs %{title: nil, url: nil}
test "list_notes_links/0 returns all notes_links" do
note_link = note_link_fixture()
assert Links.list_notes_links() == [note_link]
link = link_fixture()
assert Links.list_links() == [link]
end
test "get_note_link!/1 returns the note_link with given id" do
note_link = note_link_fixture()
assert Links.get_note_link!(note_link.id) == note_link
test "get_link!/1 returns the link with given id" do
link = link_fixture()
assert Links.get_link!(link.id) == link
end
test "create_note_link/1 with valid data creates a note_link", %{note: note} do
assert {:ok, %NoteLink{} = note_link} =
Links.create_note_link(@valid_attrs |> with_note(note))
test "create_link/1 with valid data creates a link", %{note: note} do
assert {:ok, %Link{} = link} = Links.create_link(@valid_attrs |> with_note(note))
assert note_link.title == "some title"
assert note_link.url == "some url"
assert link.title == "some title"
assert link.url == "some url"
end
test "create_note_link/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Links.create_note_link(@invalid_attrs)
test "create_link/1 with invalid data returns error changeset" do
assert {:error, %Ecto.Changeset{}} = Links.create_link(@invalid_attrs)
end
test "update_note_link/2 with valid data updates the note_link" do
note_link = note_link_fixture()
assert {:ok, %NoteLink{} = note_link} = Links.update_note_link(note_link, @update_attrs)
assert note_link.title == "some updated title"
assert note_link.url == "some updated url"
test "update_link/2 with valid data updates the link" do
link = link_fixture()
assert {:ok, %Link{} = link} = Links.update_link(link, @update_attrs)
assert link.title == "some updated title"
assert link.url == "some updated url"
end
test "update_note_link/2 with invalid data returns error changeset" do
note_link = note_link_fixture()
assert {:error, %Ecto.Changeset{}} = Links.update_note_link(note_link, @invalid_attrs)
assert note_link == Links.get_note_link!(note_link.id)
test "update_link/2 with invalid data returns error changeset" do
link = link_fixture()
assert {:error, %Ecto.Changeset{}} = Links.update_link(link, @invalid_attrs)
assert link == Links.get_link!(link.id)
end
test "delete_note_link/1 deletes the note_link" do
note_link = note_link_fixture()
assert {:ok, %NoteLink{}} = Links.delete_note_link(note_link)
assert_raise Ecto.NoResultsError, fn -> Links.get_note_link!(note_link.id) end
test "delete_link/1 deletes the link" do
link = link_fixture()
assert {:ok, %Link{}} = Links.delete_link(link)
assert_raise Ecto.NoResultsError, fn -> Links.get_link!(link.id) end
end
test "change_note_link/1 returns a note_link changeset" do
note_link = note_link_fixture()
assert %Ecto.Changeset{} = Links.change_note_link(note_link)
test "change_link/1 returns a link changeset" do
link = link_fixture()
assert %Ecto.Changeset{} = Links.change_link(link)
end
end
end

1
test/mirage_web/controllers/user_registration_controller_test.exs

@ -34,7 +34,6 @@ defmodule MirageWeb.UserRegistrationControllerTest do
# Now do a logged in request and assert on the menu
conn = get(conn, "/")
response = html_response(conn, 200)
assert response =~ email
assert response =~ "Log out</a>"
end

1
test/mirage_web/controllers/user_session_controller_test.exs

@ -35,7 +35,6 @@ defmodule MirageWeb.UserSessionControllerTest do
# Now do a logged in request and assert on the menu
conn = get(conn, "/")
response = html_response(conn, 200)
assert response =~ user.email
assert response =~ "Log out</a>"
end

76
test/mirage_web/live/link_live_test.exs

@ -0,0 +1,76 @@
defmodule MirageWeb.LinkLiveTest do
use MirageWeb.ConnCase
import Phoenix.LiveViewTest
import Mirage.LinkFixtures
import Mirage.NoteFixtures
@update_attrs %{title: "some updated title", url: "some updated url"}
@invalid_attrs %{title: nil, url: nil}
describe "Index" do
setup [:create_link, :create_note]
test "lists all notes_links", %{conn: conn, link: link} do
{:ok, _index_live, html} = live(conn, Routes.link_index_path(conn, :index))
assert html =~ "Listing Notes links"
assert html =~ link.title
end
test "updates link in listing", %{conn: conn, link: link} do
{:ok, show_live, _html} = live(conn, Routes.link_show_path(conn, :show, link))
assert show_live |> element("a", "Edit") |> render_click() =~
"Edit Note link"
assert_patch(show_live, Routes.link_show_path(conn, :edit, link))
assert show_live
|> form("#link-form", link: @invalid_attrs)
|> render_change() =~ "can&apos;t be blank"
{:ok, _, html} =
show_live
|> form("#link-form", link: @update_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.link_show_path(conn, :show, link))
assert html =~ "Note link updated successfully"
assert html =~ "some updated title"
end
end
describe "Show" do
setup [:create_link]
test "displays link", %{conn: conn, link: link} do
{:ok, _show_live, html} = live(conn, Routes.link_show_path(conn, :show, link))
assert html =~ "Show Note link"
assert html =~ link.title
end
test "updates link within modal", %{conn: conn, link: link} do
{:ok, show_live, _html} = live(conn, Routes.link_show_path(conn, :show, link))
assert show_live |> element("a", "Edit") |> render_click() =~
"Edit Note link"
assert_patch(show_live, Routes.link_show_path(conn, :edit, link))
assert show_live
|> form("#link-form", link: @invalid_attrs)
|> render_change() =~ "can&apos;t be blank"
{:ok, _, html} =
show_live
|> form("#link-form", link: @update_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.link_show_path(conn, :show, link))
assert html =~ "Note link updated successfully"
assert html =~ "some updated title"
end
end
end

76
test/mirage_web/live/note_link_live_test.exs

@ -1,76 +0,0 @@
defmodule MirageWeb.NoteLinkLiveTest do
use MirageWeb.ConnCase
import Phoenix.LiveViewTest
import Mirage.NoteLinkFixtures
import Mirage.NoteFixtures
@update_attrs %{title: "some updated title", url: "some updated url"}
@invalid_attrs %{title: nil, url: nil}
describe "Index" do
setup [:create_note_link, :create_note]
test "lists all notes_links", %{conn: conn, note_link: note_link} do
{:ok, _index_live, html} = live(conn, Routes.note_link_index_path(conn, :index))
assert html =~ "Listing Notes links"
assert html =~ note_link.title
end
test "updates note_link in listing", %{conn: conn, note_link: note_link} do
{:ok, show_live, _html} = live(conn, Routes.note_link_show_path(conn, :show, note_link))
assert show_live |> element("a", "Edit") |> render_click() =~
"Edit Note link"
assert_patch(show_live, Routes.note_link_show_path(conn, :edit, note_link))
assert show_live
|> form("#note_link-form", note_link: @invalid_attrs)
|> render_change() =~ "can&apos;t be blank"
{:ok, _, html} =
show_live
|> form("#note_link-form", note_link: @update_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.note_link_show_path(conn, :show, note_link))
assert html =~ "Note link updated successfully"
assert html =~ "some updated title"
end
end
describe "Show" do
setup [:create_note_link]
test "displays note_link", %{conn: conn, note_link: note_link} do
{:ok, _show_live, html} = live(conn, Routes.note_link_show_path(conn, :show, note_link))
assert html =~ "Show Note link"
assert html =~ note_link.title
end
test "updates note_link within modal", %{conn: conn, note_link: note_link} do
{:ok, show_live, _html} = live(conn, Routes.note_link_show_path(conn, :show, note_link))
assert show_live |> element("a", "Edit") |> render_click() =~
"Edit Note link"
assert_patch(show_live, Routes.note_link_show_path(conn, :edit, note_link))
assert show_live
|> form("#note_link-form", note_link: @invalid_attrs)
|> render_change() =~ "can&apos;t be blank"
{:ok, _, html} =
show_live
|> form("#note_link-form", note_link: @update_attrs)
|> render_submit()
|> follow_redirect(conn, Routes.note_link_show_path(conn, :show, note_link))
assert html =~ "Note link updated successfully"
assert html =~ "some updated title"
end
end
end

16
test/support/fixtures/note_link_fixtures.ex → test/support/fixtures/link_fixtures.ex

@ -1,4 +1,4 @@
defmodule Mirage.NoteLinkFixtures do
defmodule Mirage.LinkFixtures do
@moduledoc """
This module defines test helpers for creating
entities via the `Mirage.Links` context.
@ -6,19 +6,19 @@ defmodule Mirage.NoteLinkFixtures do
@create_attrs %{title: "some title", url: "some url"}
def note_link_fixture() do
def link_fixture() do
note = Mirage.NoteFixtures.note_fixture()
{:ok, note_link} =
{:ok, link} =
%{note_id: note.id}
|> Enum.into(@create_attrs)
|> Mirage.Links.create_note_link()
|> Mirage.Links.create_link()
note_link
link
end
def create_note_link(_) do
note_link = note_link_fixture()
%{note_link: note_link}
def create_link(_) do
link = link_fixture()
%{link: link}
end
end
Loading…
Cancel
Save