ML-182.3: convert record_set_live/index_test to PhoenixTest
This commit is contained in:
@@ -2,7 +2,6 @@ defmodule MusicLibraryWeb.RecordSetLive.IndexTest do
|
|||||||
use MusicLibraryWeb.ConnCase
|
use MusicLibraryWeb.ConnCase
|
||||||
|
|
||||||
import MusicLibrary.Fixtures.RecordSets
|
import MusicLibrary.Fixtures.RecordSets
|
||||||
import Phoenix.LiveViewTest
|
|
||||||
|
|
||||||
alias MusicLibrary.RecordSets
|
alias MusicLibrary.RecordSets
|
||||||
|
|
||||||
@@ -39,7 +38,8 @@ defmodule MusicLibraryWeb.RecordSetLive.IndexTest do
|
|||||||
record_set(%{name: "Zulu Set"})
|
record_set(%{name: "Zulu Set"})
|
||||||
record_set(%{name: "Alpha Set"})
|
record_set(%{name: "Alpha Set"})
|
||||||
|
|
||||||
{:ok, _view, html} = live(conn, ~p"/record-sets?order=alphabetical")
|
session = conn |> visit(~p"/record-sets?order=alphabetical")
|
||||||
|
html = Phoenix.LiveViewTest.render(session.view)
|
||||||
|
|
||||||
alpha_pos = :binary.match(html, "Alpha Set")
|
alpha_pos = :binary.match(html, "Alpha Set")
|
||||||
zulu_pos = :binary.match(html, "Zulu Set")
|
zulu_pos = :binary.match(html, "Zulu Set")
|
||||||
@@ -50,25 +50,20 @@ defmodule MusicLibraryWeb.RecordSetLive.IndexTest do
|
|||||||
|
|
||||||
describe "Create set" do
|
describe "Create set" do
|
||||||
test "creates a set with valid data", %{conn: conn} do
|
test "creates a set with valid data", %{conn: conn} do
|
||||||
{:ok, view, _html} = live(conn, ~p"/record-sets/new")
|
conn
|
||||||
|
|> visit(~p"/record-sets/new")
|
||||||
view
|
|> fill_in("Name", with: "Brand New Set")
|
||||||
|> form("#record-set-form", record_set: %{name: "Brand New Set"})
|
|> click_button("Save Set")
|
||||||
|> render_submit()
|
|
||||||
|
|
||||||
assert [set] = RecordSets.search_record_sets("Brand New Set")
|
assert [set] = RecordSets.search_record_sets("Brand New Set")
|
||||||
assert set.name == "Brand New Set"
|
assert set.name == "Brand New Set"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "shows validation errors with invalid data", %{conn: conn} do
|
test "shows validation errors with invalid data", %{conn: conn} do
|
||||||
{:ok, view, _html} = live(conn, ~p"/record-sets/new")
|
conn
|
||||||
|
|> visit(~p"/record-sets/new")
|
||||||
html =
|
|> click_button("Save Set")
|
||||||
view
|
|> assert_has("[data-part='error']", "can't be blank")
|
||||||
|> form("#record-set-form", record_set: %{name: ""})
|
|
||||||
|> render_change()
|
|
||||||
|
|
||||||
assert html =~ "can't be blank"
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -76,11 +71,10 @@ defmodule MusicLibraryWeb.RecordSetLive.IndexTest do
|
|||||||
test "updates set with valid data", %{conn: conn} do
|
test "updates set with valid data", %{conn: conn} do
|
||||||
set = record_set(%{name: "Old Name"})
|
set = record_set(%{name: "Old Name"})
|
||||||
|
|
||||||
{:ok, view, _html} = live(conn, ~p"/record-sets/#{set}/edit")
|
conn
|
||||||
|
|> visit(~p"/record-sets/#{set}/edit")
|
||||||
view
|
|> fill_in("Name", with: "Updated Name")
|
||||||
|> form("#record-set-form", record_set: %{name: "Updated Name"})
|
|> click_button("Save Set")
|
||||||
|> render_submit()
|
|
||||||
|
|
||||||
updated = RecordSets.get_record_set!(set.id)
|
updated = RecordSets.get_record_set!(set.id)
|
||||||
assert updated.name == "Updated Name"
|
assert updated.name == "Updated Name"
|
||||||
|
|||||||
Reference in New Issue
Block a user