init commit
This commit is contained in:
14
test/here_i_am_web/controllers/error_html_test.exs
Normal file
14
test/here_i_am_web/controllers/error_html_test.exs
Normal file
@@ -0,0 +1,14 @@
|
||||
defmodule HereIAmWeb.ErrorHTMLTest do
|
||||
use HereIAmWeb.ConnCase, async: true
|
||||
|
||||
# Bring render_to_string/4 for testing custom views
|
||||
import Phoenix.Template
|
||||
|
||||
test "renders 404.html" do
|
||||
assert render_to_string(HereIAmWeb.ErrorHTML, "404", "html", []) == "Not Found"
|
||||
end
|
||||
|
||||
test "renders 500.html" do
|
||||
assert render_to_string(HereIAmWeb.ErrorHTML, "500", "html", []) == "Internal Server Error"
|
||||
end
|
||||
end
|
12
test/here_i_am_web/controllers/error_json_test.exs
Normal file
12
test/here_i_am_web/controllers/error_json_test.exs
Normal file
@@ -0,0 +1,12 @@
|
||||
defmodule HereIAmWeb.ErrorJSONTest do
|
||||
use HereIAmWeb.ConnCase, async: true
|
||||
|
||||
test "renders 404" do
|
||||
assert HereIAmWeb.ErrorJSON.render("404.json", %{}) == %{errors: %{detail: "Not Found"}}
|
||||
end
|
||||
|
||||
test "renders 500" do
|
||||
assert HereIAmWeb.ErrorJSON.render("500.json", %{}) ==
|
||||
%{errors: %{detail: "Internal Server Error"}}
|
||||
end
|
||||
end
|
8
test/here_i_am_web/controllers/page_controller_test.exs
Normal file
8
test/here_i_am_web/controllers/page_controller_test.exs
Normal file
@@ -0,0 +1,8 @@
|
||||
defmodule HereIAmWeb.PageControllerTest do
|
||||
use HereIAmWeb.ConnCase
|
||||
|
||||
test "GET /", %{conn: conn} do
|
||||
conn = get(conn, ~p"/")
|
||||
assert html_response(conn, 200) =~ "Peace of mind from prototype to production"
|
||||
end
|
||||
end
|
113
test/here_i_am_web/live/device_live_test.exs
Normal file
113
test/here_i_am_web/live/device_live_test.exs
Normal file
@@ -0,0 +1,113 @@
|
||||
defmodule HereIAmWeb.DeviceLiveTest do
|
||||
use HereIAmWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import HereIAm.DevicesFixtures
|
||||
|
||||
@create_attrs %{ip_address: "some ip_address", audio: "some audio"}
|
||||
@update_attrs %{ip_address: "some updated ip_address", audio: "some updated audio"}
|
||||
@invalid_attrs %{ip_address: nil, audio: nil}
|
||||
|
||||
defp create_device(_) do
|
||||
device = device_fixture()
|
||||
%{device: device}
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
setup [:create_device]
|
||||
|
||||
test "lists all devices", %{conn: conn, device: device} do
|
||||
{:ok, _index_live, html} = live(conn, ~p"/devices")
|
||||
|
||||
assert html =~ "Listing Devices"
|
||||
assert html =~ device.ip_address
|
||||
end
|
||||
|
||||
test "saves new device", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/devices")
|
||||
|
||||
assert index_live |> element("a", "New Device") |> render_click() =~
|
||||
"New Device"
|
||||
|
||||
assert_patch(index_live, ~p"/devices/new")
|
||||
|
||||
assert index_live
|
||||
|> form("#device-form", device: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
assert index_live
|
||||
|> form("#device-form", device: @create_attrs)
|
||||
|> render_submit()
|
||||
|
||||
assert_patch(index_live, ~p"/devices")
|
||||
|
||||
html = render(index_live)
|
||||
assert html =~ "Device created successfully"
|
||||
assert html =~ "some ip_address"
|
||||
end
|
||||
|
||||
test "updates device in listing", %{conn: conn, device: device} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/devices")
|
||||
|
||||
assert index_live |> element("#devices-#{device.id} a", "Edit") |> render_click() =~
|
||||
"Edit Device"
|
||||
|
||||
assert_patch(index_live, ~p"/devices/#{device}/edit")
|
||||
|
||||
assert index_live
|
||||
|> form("#device-form", device: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
assert index_live
|
||||
|> form("#device-form", device: @update_attrs)
|
||||
|> render_submit()
|
||||
|
||||
assert_patch(index_live, ~p"/devices")
|
||||
|
||||
html = render(index_live)
|
||||
assert html =~ "Device updated successfully"
|
||||
assert html =~ "some updated ip_address"
|
||||
end
|
||||
|
||||
test "deletes device in listing", %{conn: conn, device: device} do
|
||||
{:ok, index_live, _html} = live(conn, ~p"/devices")
|
||||
|
||||
assert index_live |> element("#devices-#{device.id} a", "Delete") |> render_click()
|
||||
refute has_element?(index_live, "#devices-#{device.id}")
|
||||
end
|
||||
end
|
||||
|
||||
describe "Show" do
|
||||
setup [:create_device]
|
||||
|
||||
test "displays device", %{conn: conn, device: device} do
|
||||
{:ok, _show_live, html} = live(conn, ~p"/devices/#{device}")
|
||||
|
||||
assert html =~ "Show Device"
|
||||
assert html =~ device.ip_address
|
||||
end
|
||||
|
||||
test "updates device within modal", %{conn: conn, device: device} do
|
||||
{:ok, show_live, _html} = live(conn, ~p"/devices/#{device}")
|
||||
|
||||
assert show_live |> element("a", "Edit") |> render_click() =~
|
||||
"Edit Device"
|
||||
|
||||
assert_patch(show_live, ~p"/devices/#{device}/show/edit")
|
||||
|
||||
assert show_live
|
||||
|> form("#device-form", device: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
assert show_live
|
||||
|> form("#device-form", device: @update_attrs)
|
||||
|> render_submit()
|
||||
|
||||
assert_patch(show_live, ~p"/devices/#{device}")
|
||||
|
||||
html = render(show_live)
|
||||
assert html =~ "Device updated successfully"
|
||||
assert html =~ "some updated ip_address"
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user