Skip to content

Commit

Permalink
slightly more test coverage of live views
Browse files Browse the repository at this point in the history
  • Loading branch information
doughsay committed Aug 2, 2023
1 parent 4fc4160 commit 1f5c5da
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 6 deletions.
4 changes: 2 additions & 2 deletions test/ambry_web/live/book_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ defmodule AmbryWeb.BookLiveTest do

setup :register_and_log_in_user

test "renders a book show page", %{conn: conn} do
%{id: book_id, title: book_title} = insert(:book)
test "renders a book show page with its media", %{conn: conn} do
%{book: %{id: book_id, title: book_title}} = insert(:media, status: :ready)

{:ok, _view, html} = live(conn, ~p"/books/#{book_id}")
assert html =~ escape(book_title)
Expand Down
14 changes: 14 additions & 0 deletions test/ambry_web/live/library_live_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule AmbryWeb.LibraryLiveTest do
use AmbryWeb.ConnCase

import Phoenix.LiveViewTest

setup :register_and_log_in_user

test "renders the library", %{conn: conn} do
%{title: book_title} = insert(:book)

{:ok, _view, html} = live(conn, ~p"/library")
assert html =~ escape(book_title)
end
end
12 changes: 10 additions & 2 deletions test/ambry_web/live/person_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@ defmodule AmbryWeb.PersonLiveTest do

setup :register_and_log_in_user

test "renders a person show page", %{conn: conn} do
%{id: person_id, name: person_name} = insert(:person)
test "renders a person show page with authored books", %{conn: conn} do
%{book_authors: [%{author: %{person: %{id: person_id, name: person_name}}} | _]} = insert(:book)

{:ok, _view, html} = live(conn, ~p"/people/#{person_id}")
assert html =~ escape(person_name)
end

test "renders a person show page with narrated books", %{conn: conn} do
%{media_narrators: [%{narrator: %{person: %{id: person_id} = person}} | _]} = insert(:media)
{:ok, %{name: person_name}} = Ambry.People.update_person(person, %{name: "Foo"})

{:ok, _view, html} = live(conn, ~p"/people/#{person_id}")
assert html =~ escape(person_name)
Expand Down
34 changes: 34 additions & 0 deletions test/ambry_web/live/search_live_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
defmodule AmbryWeb.SearchLiveTest do
use AmbryWeb.ConnCase

import Phoenix.LiveViewTest

setup :register_and_log_in_user

test "renders search results page when searching for a book", %{conn: conn} do
%{title: book_title} = book = insert(:book)
insert_index!(book)

{:ok, _view, html} = live(conn, ~p"/search/#{book_title}")

assert html =~ escape(book_title)
end

test "renders search results page when searching for a person", %{conn: conn} do
%{name: person_name} = person = insert(:person)
insert_index!(person)

{:ok, _view, html} = live(conn, ~p"/search/#{person_name}")

assert html =~ escape(person_name)
end

test "renders search results page when searching for a series", %{conn: conn} do
%{series_books: [%{series: %{name: series_name} = series} | _rest]} = insert(:book)
insert_index!(series)

{:ok, _view, html} = live(conn, ~p"/search/#{series_name}")

assert html =~ escape(series_name)
end
end
2 changes: 1 addition & 1 deletion test/ambry_web/live/series_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule AmbryWeb.SeriesLiveTest do
setup :register_and_log_in_user

test "renders a series show page", %{conn: conn} do
%{id: series_id, name: series_name} = insert(:series)
%{series_books: [%{series: %{id: series_id, name: series_name}} | _rest]} = insert(:book)

{:ok, _view, html} = live(conn, ~p"/series/#{series_id}")
assert html =~ escape(series_name)
Expand Down
4 changes: 3 additions & 1 deletion test/support/factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ defmodule Ambry.Factory do
mpd_path: "/uploads/media/#{media_id}.mpd",
hls_path: "/uploads/media/#{media_id}.m3u8",
mp4_path: "/uploads/media/#{media_id}.mp4",
duration: Decimal.new(time + 300)
duration: Decimal.new(time + 300),
published: Faker.Date.backward(15_466),
notes: Faker.Lorem.sentence()
}
end

Expand Down

0 comments on commit 1f5c5da

Please sign in to comment.