diff options
author | href <href@random.sh> | 2018-01-31 20:36:42 +0100 |
---|---|---|
committer | href <href@random.sh> | 2018-01-31 20:36:42 +0100 |
commit | fcb2a082346054108f3f16cffe968450cf961976 (patch) | |
tree | 8e7d2eb9eeebf854e62e08c29b147f34dfeb1881 /test |
import
Diffstat (limited to 'test')
-rw-r--r-- | test/lsg_web/controllers/page_controller_test.exs | 8 | ||||
-rw-r--r-- | test/lsg_web/views/error_view_test.exs | 21 | ||||
-rw-r--r-- | test/lsg_web/views/layout_view_test.exs | 3 | ||||
-rw-r--r-- | test/lsg_web/views/page_view_test.exs | 3 | ||||
-rw-r--r-- | test/support/channel_case.ex | 33 | ||||
-rw-r--r-- | test/support/conn_case.ex | 34 | ||||
-rw-r--r-- | test/test_helper.exs | 2 |
7 files changed, 104 insertions, 0 deletions
diff --git a/test/lsg_web/controllers/page_controller_test.exs b/test/lsg_web/controllers/page_controller_test.exs new file mode 100644 index 0000000..b7a0299 --- /dev/null +++ b/test/lsg_web/controllers/page_controller_test.exs @@ -0,0 +1,8 @@ +defmodule LSGWeb.PageControllerTest do + use LSGWeb.ConnCase + + test "GET /", %{conn: conn} do + conn = get conn, "/" + assert html_response(conn, 200) =~ "Welcome to Phoenix!" + end +end diff --git a/test/lsg_web/views/error_view_test.exs b/test/lsg_web/views/error_view_test.exs new file mode 100644 index 0000000..2aae44d --- /dev/null +++ b/test/lsg_web/views/error_view_test.exs @@ -0,0 +1,21 @@ +defmodule LSGWeb.ErrorViewTest do + use LSGWeb.ConnCase, async: true + + # Bring render/3 and render_to_string/3 for testing custom views + import Phoenix.View + + test "renders 404.html" do + assert render_to_string(LSGWeb.ErrorView, "404.html", []) == + "Page not found" + end + + test "render 500.html" do + assert render_to_string(LSGWeb.ErrorView, "500.html", []) == + "Internal server error" + end + + test "render any other" do + assert render_to_string(LSGWeb.ErrorView, "505.html", []) == + "Internal server error" + end +end diff --git a/test/lsg_web/views/layout_view_test.exs b/test/lsg_web/views/layout_view_test.exs new file mode 100644 index 0000000..5a904f8 --- /dev/null +++ b/test/lsg_web/views/layout_view_test.exs @@ -0,0 +1,3 @@ +defmodule LSGWeb.LayoutViewTest do + use LSGWeb.ConnCase, async: true +end diff --git a/test/lsg_web/views/page_view_test.exs b/test/lsg_web/views/page_view_test.exs new file mode 100644 index 0000000..26fce45 --- /dev/null +++ b/test/lsg_web/views/page_view_test.exs @@ -0,0 +1,3 @@ +defmodule LSGWeb.PageViewTest do + use LSGWeb.ConnCase, async: true +end diff --git a/test/support/channel_case.ex b/test/support/channel_case.ex new file mode 100644 index 0000000..dcaa658 --- /dev/null +++ b/test/support/channel_case.ex @@ -0,0 +1,33 @@ +defmodule LSGWeb.ChannelCase do + @moduledoc """ + This module defines the test case to be used by + channel tests. + + Such tests rely on `Phoenix.ChannelTest` and also + import other functionality to make it easier + to build common datastructures and query the data layer. + + Finally, if the test case interacts with the database, + it cannot be async. For this reason, every test runs + inside a transaction which is reset at the beginning + of the test unless the test case is marked as async. + """ + + use ExUnit.CaseTemplate + + using do + quote do + # Import conveniences for testing with channels + use Phoenix.ChannelTest + + # The default endpoint for testing + @endpoint LSGWeb.Endpoint + end + end + + + setup _tags do + :ok + end + +end diff --git a/test/support/conn_case.ex b/test/support/conn_case.ex new file mode 100644 index 0000000..9ed8e53 --- /dev/null +++ b/test/support/conn_case.ex @@ -0,0 +1,34 @@ +defmodule LSGWeb.ConnCase do + @moduledoc """ + This module defines the test case to be used by + tests that require setting up a connection. + + Such tests rely on `Phoenix.ConnTest` and also + import other functionality to make it easier + to build common datastructures and query the data layer. + + Finally, if the test case interacts with the database, + it cannot be async. For this reason, every test runs + inside a transaction which is reset at the beginning + of the test unless the test case is marked as async. + """ + + use ExUnit.CaseTemplate + + using do + quote do + # Import conveniences for testing with connections + use Phoenix.ConnTest + import LSGWeb.Router.Helpers + + # The default endpoint for testing + @endpoint LSGWeb.Endpoint + end + end + + + setup _tags do + {:ok, conn: Phoenix.ConnTest.build_conn()} + end + +end diff --git a/test/test_helper.exs b/test/test_helper.exs new file mode 100644 index 0000000..0a76a58 --- /dev/null +++ b/test/test_helper.exs @@ -0,0 +1,2 @@ +ExUnit.start() + |