From 401b98e8d4b74ac6db7a74a163fe7af051408814 Mon Sep 17 00:00:00 2001 From: Guido Tripaldi Date: Tue, 2 Apr 2019 14:01:29 +0200 Subject: [PATCH 1/7] Adds a workaround for cohabitation with LiveView --- lib/drab/client.ex | 114 +++++++++++++++++++++++---------------------- 1 file changed, 58 insertions(+), 56 deletions(-) diff --git a/lib/drab/client.ex b/lib/drab/client.ex index 0054c28..947160d 100644 --- a/lib/drab/client.ex +++ b/lib/drab/client.ex @@ -150,62 +150,64 @@ defmodule Drab.Client do @spec generate_drab_js(Plug.Conn.t(), boolean, Keyword.t()) :: String.t() defp generate_drab_js(conn, connect?, assigns) do - controller = Phoenix.Controller.controller_module(conn) - - if enables_drab?(controller) do - commander = commander_for(controller) - view = view_for(controller) - endpoint = Phoenix.Controller.endpoint_module(conn) - action = Phoenix.Controller.action_name(conn) - - controller_and_action = - Phoenix.Token.sign( - conn, - "controller_and_action", - controller: controller, - commander: commander, - view: view, - action: action, - assigns: assigns - ) - - broadcast_topic = - topic(commander.__drab__().broadcasting, controller, conn.request_path, action) - - templates = DrabModule.all_templates_for(commander.__drab__().modules) - - access_session = - Enum.uniq( - commander.__drab__().access_session ++ Drab.Config.get(endpoint, :access_session) - ) - - session = - access_session - |> Enum.map(fn x -> {x, Plug.Conn.get_session(conn, x)} end) - |> Enum.into(%{}) - - session_token = Drab.Core.tokenize_store(conn, session) - - bindings = [ - controller_and_action: controller_and_action, - endpoint: endpoint, - commander: commander, - templates: templates, - drab_session_token: session_token, - broadcast_topic: broadcast_topic, - connect: connect?, - client_lib_version: @client_lib_version - ] - - js = render_template(endpoint, "drab.js", bindings) - - Phoenix.HTML.raw(""" - - """) - else - "" + if !conn.assigns[:live_view_module] do + controller = Phoenix.Controller.controller_module(conn) + + if enables_drab?(controller) do + commander = commander_for(controller) + view = view_for(controller) + endpoint = Phoenix.Controller.endpoint_module(conn) + action = Phoenix.Controller.action_name(conn) + + controller_and_action = + Phoenix.Token.sign( + conn, + "controller_and_action", + controller: controller, + commander: commander, + view: view, + action: action, + assigns: assigns + ) + + broadcast_topic = + topic(commander.__drab__().broadcasting, controller, conn.request_path, action) + + templates = DrabModule.all_templates_for(commander.__drab__().modules) + + access_session = + Enum.uniq( + commander.__drab__().access_session ++ Drab.Config.get(endpoint, :access_session) + ) + + session = + access_session + |> Enum.map(fn x -> {x, Plug.Conn.get_session(conn, x)} end) + |> Enum.into(%{}) + + session_token = Drab.Core.tokenize_store(conn, session) + + bindings = [ + controller_and_action: controller_and_action, + endpoint: endpoint, + commander: commander, + templates: templates, + drab_session_token: session_token, + broadcast_topic: broadcast_topic, + connect: connect?, + client_lib_version: @client_lib_version + ] + + js = render_template(endpoint, "drab.js", bindings) + + Phoenix.HTML.raw(""" + + """) + else + "" + end end end From 71826025cab98d31bf0782ff49d244bf8d524664 Mon Sep 17 00:00:00 2001 From: Guido Tripaldi Date: Tue, 9 Apr 2019 18:48:39 +0200 Subject: [PATCH 2/7] Better workaround for cohabitation with LiveView --- lib/drab/client.ex | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/drab/client.ex b/lib/drab/client.ex index 947160d..9912dfe 100644 --- a/lib/drab/client.ex +++ b/lib/drab/client.ex @@ -148,16 +148,36 @@ defmodule Drab.Client do @spec api_version() :: String.t() def api_version(), do: @client_lib_version + @spec get_controller_module(Plug.Conn.t()) :: atom() | nil + defp get_controller_module(conn) do + try do + Phoenix.Controller.controller_module(conn) + rescue + KeyError -> + nil + end + end + + @spec get_controller_action_name(Plug.Conn.t()) :: atom() | nil + defp get_controller_action_name(conn) do + try do + Phoenix.Controller.action_name(conn) + rescue + KeyError -> nil + end + end + @spec generate_drab_js(Plug.Conn.t(), boolean, Keyword.t()) :: String.t() defp generate_drab_js(conn, connect?, assigns) do - if !conn.assigns[:live_view_module] do - controller = Phoenix.Controller.controller_module(conn) + if (controller = get_controller_module(conn)) do + # controller = Phoenix.Controller.controller_module(conn) if enables_drab?(controller) do commander = commander_for(controller) view = view_for(controller) endpoint = Phoenix.Controller.endpoint_module(conn) - action = Phoenix.Controller.action_name(conn) + # action = Phoenix.Controller.action_name(conn) + action = get_controller_action_name(conn) controller_and_action = Phoenix.Token.sign( From 96b3171464117c5a5e23b9c4f5413f253e2f8eb2 Mon Sep 17 00:00:00 2001 From: Guido Tripaldi Date: Wed, 14 Aug 2019 17:22:00 +0200 Subject: [PATCH 3/7] Removes old commented code --- lib/drab/client.ex | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/drab/client.ex b/lib/drab/client.ex index 9912dfe..40f3af0 100644 --- a/lib/drab/client.ex +++ b/lib/drab/client.ex @@ -170,13 +170,10 @@ defmodule Drab.Client do @spec generate_drab_js(Plug.Conn.t(), boolean, Keyword.t()) :: String.t() defp generate_drab_js(conn, connect?, assigns) do if (controller = get_controller_module(conn)) do - # controller = Phoenix.Controller.controller_module(conn) - if enables_drab?(controller) do commander = commander_for(controller) view = view_for(controller) endpoint = Phoenix.Controller.endpoint_module(conn) - # action = Phoenix.Controller.action_name(conn) action = get_controller_action_name(conn) controller_and_action = From f21dd64a1fdeb66d267b6fc59c2eb70c8459b185 Mon Sep 17 00:00:00 2001 From: Guido Tripaldi Date: Thu, 15 Aug 2019 11:01:26 +0200 Subject: [PATCH 4/7] Updates Travis environment configuration --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index b221e8a..200aa41 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,9 +16,11 @@ before_install: elixir: - 1.6.6 - 1.7.4 + - 1.8.2 otp_release: - 20.0 - 21.0 + - 22.0 env: - MIX_ENV=test From 37b89d081643a54664f9a04c36f8a59ea9bd103c Mon Sep 17 00:00:00 2001 From: Guido Tripaldi Date: Thu, 15 Aug 2019 17:01:34 +0200 Subject: [PATCH 5/7] Adds lv_cohabitation test --- assets/package-lock.json | 3 + config/test.exs | 5 +- mix.exs | 6 +- mix.lock | 18 +++-- package.json | 1 + test/integration/lv_cohabitation_test.exs | 73 +++++++++++++++++++ test/support/lib/drab_test_app/endpoint.ex | 3 +- test/support/router.ex | 5 ++ .../commanders/lv_cohabitation_commander.ex | 13 ++++ .../controllers/lv_cohabitation_controller.ex | 14 ++++ test/support/web/live/lv_cohabitation_live.ex | 32 ++++++++ test/support/web/static/js/app.js | 4 + .../lv_cohabitation/index_drab.html.drab | 8 ++ .../lv_cohabitation/index_lv.html.leex | 8 ++ .../support/web/views/lv_cohabitation_view.ex | 5 ++ test/support/web/web.ex | 3 + 16 files changed, 189 insertions(+), 12 deletions(-) create mode 100644 assets/package-lock.json create mode 100644 test/integration/lv_cohabitation_test.exs create mode 100644 test/support/web/commanders/lv_cohabitation_commander.ex create mode 100644 test/support/web/controllers/lv_cohabitation_controller.ex create mode 100644 test/support/web/live/lv_cohabitation_live.ex create mode 100644 test/support/web/templates/lv_cohabitation/index_drab.html.drab create mode 100644 test/support/web/templates/lv_cohabitation/index_lv.html.leex create mode 100644 test/support/web/views/lv_cohabitation_view.ex diff --git a/assets/package-lock.json b/assets/package-lock.json new file mode 100644 index 0000000..48e341a --- /dev/null +++ b/assets/package-lock.json @@ -0,0 +1,3 @@ +{ + "lockfileVersion": 1 +} diff --git a/config/test.exs b/config/test.exs index 25e4c33..1f533ac 100644 --- a/config/test.exs +++ b/config/test.exs @@ -4,7 +4,10 @@ use Mix.Config # you can enable the server option below. config :drab, DrabTestApp.Endpoint, http: [port: 4001], - server: true + server: true, + live_view: [ + signing_salt: "+iGXfLGYMPyowoZribxgrSyeaPz9D/v2" + ] # Print only warnings and errors during test config :logger, level: :warn diff --git a/mix.exs b/mix.exs index 7630716..f73d873 100644 --- a/mix.exs +++ b/mix.exs @@ -49,7 +49,7 @@ defmodule Drab.Mixfile do defp deps do [ - {:phoenix, "~> 1.2"}, + {:phoenix, "~> 1.4.8"}, {:phoenix_html, "~> 2.13"}, {:phoenix_pubsub, "~> 1.0"}, {:phoenix_live_reload, "~> 1.0", only: :dev}, @@ -63,7 +63,9 @@ defmodule Drab.Mixfile do {:floki, ">= 0.20.2"}, {:dialyxir, "~> 1.0.0-rc.2", only: [:dev, :test], runtime: false}, # {:credo, "~> 0.9.3", only: [:dev, :test], runtime: false}, - {:jason, "~> 1.0"} + {:jason, "~> 1.0"}, + + {:phoenix_live_view, github: "phoenixframework/phoenix_live_view", only: [:test]} ] end diff --git a/mix.lock b/mix.lock index f9a3a7c..c9432ab 100644 --- a/mix.lock +++ b/mix.lock @@ -1,8 +1,8 @@ %{ "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"}, "certifi": {:hex, :certifi, "2.4.2", "75424ff0f3baaccfd34b1214184b6ef616d89e420b258bb0a5ea7d7bc628f7f0", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"}, - "cowboy": {:hex, :cowboy, "1.1.2", "61ac29ea970389a88eca5a65601460162d370a70018afe6f949a29dca91f3bb0", [:rebar3], [{:cowlib, "~> 1.0.2", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.3.2", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"}, - "cowlib": {:hex, :cowlib, "1.0.2", "9d769a1d062c9c3ac753096f868ca121e2730b9a377de23dec0f7e08b1df84ee", [:make], [], "hexpm"}, + "cowboy": {:hex, :cowboy, "2.6.3", "99aa50e94e685557cad82e704457336a453d4abcb77839ad22dbe71f311fcc06", [:rebar3], [{:cowlib, "~> 2.7.3", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.7.1", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"}, + "cowlib": {:hex, :cowlib, "2.7.3", "a7ffcd0917e6d50b4d5fb28e9e2085a0ceb3c97dea310505f7460ff5ed764ce9", [:rebar3], [], "hexpm"}, "credo": {:hex, :credo, "0.9.3", "76fa3e9e497ab282e0cf64b98a624aa11da702854c52c82db1bf24e54ab7c97a", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:poison, ">= 0.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, "deppie": {:hex, :deppie, "1.1.2", "6e90b0baf70055ee85b5d87c1649f39acb05df3c24d4d46f90a4a03b8e57619f", [:mix], [{:global_flags, "~> 1.0", [hex: :global_flags, repo: "hexpm", optional: false]}], "hexpm"}, "dialyxir": {:hex, :dialyxir, "1.0.0-rc.4", "71b42f5ee1b7628f3e3a6565f4617dfb02d127a0499ab3e72750455e986df001", [:mix], [{:erlex, "~> 0.1", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm"}, @@ -27,15 +27,17 @@ "mochiweb": {:hex, :mochiweb, "2.18.0", "eb55f1db3e6e960fac4e6db4e2db9ec3602cc9f30b86cd1481d56545c3145d2e", [:rebar3], [], "hexpm"}, "nimble_parsec": {:hex, :nimble_parsec, "0.4.0", "ee261bb53214943679422be70f1658fff573c5d0b0a1ecd0f18738944f818efe", [:mix], [], "hexpm"}, "parse_trans": {:hex, :parse_trans, "3.3.0", "09765507a3c7590a784615cfd421d101aec25098d50b89d7aa1d66646bc571c1", [:rebar3], [], "hexpm"}, - "phoenix": {:hex, :phoenix, "1.4.0", "56fe9a809e0e735f3e3b9b31c1b749d4b436e466d8da627b8d82f90eaae714d2", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}], "hexpm"}, - "phoenix_html": {:hex, :phoenix_html, "2.13.1", "fa8f034b5328e2dfa0e4131b5569379003f34bc1fafdaa84985b0b9d2f12e68b", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}, + "phoenix": {:hex, :phoenix, "1.4.9", "746d098e10741c334d88143d3c94cab1756435f94387a63441792e66ec0ee974", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.8.1 or ~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 1.0 or ~> 2.0", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm"}, + "phoenix_html": {:hex, :phoenix_html, "2.13.3", "850e292ff6e204257f5f9c4c54a8cb1f6fbc16ed53d360c2b780a3d0ba333867", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}, "phoenix_live_reload": {:hex, :phoenix_live_reload, "1.2.0", "3bb31a9fbd40ffe8652e60c8660dffd72dd231efcdf49b744fb75b9ef7db5dd2", [:mix], [{:file_system, "~> 0.2.1 or ~> 0.3", [hex: :file_system, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}], "hexpm"}, - "phoenix_pubsub": {:hex, :phoenix_pubsub, "1.1.1", "6668d787e602981f24f17a5fbb69cc98f8ab085114ebfac6cc36e10a90c8e93c", [:mix], [], "hexpm"}, - "plug": {:hex, :plug, "1.7.1", "8516d565fb84a6a8b2ca722e74e2cd25ca0fc9d64f364ec9dbec09d33eb78ccd", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}], "hexpm"}, - "plug_cowboy": {:hex, :plug_cowboy, "1.0.0", "2e2a7d3409746d335f451218b8bb0858301c3de6d668c3052716c909936eb57a", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}, + "phoenix_live_view": {:git, "https://github.com/phoenixframework/phoenix_live_view.git", "0de12cc2666105d2e82d11c008043bc450197179", []}, + "phoenix_pubsub": {:hex, :phoenix_pubsub, "1.1.2", "496c303bdf1b2e98a9d26e89af5bba3ab487ba3a3735f74bf1f4064d2a845a3e", [:mix], [], "hexpm"}, + "plug": {:hex, :plug, "1.8.3", "12d5f9796dc72e8ac9614e94bda5e51c4c028d0d428e9297650d09e15a684478", [:mix], [{:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm"}, + "plug_cowboy": {:hex, :plug_cowboy, "2.1.0", "b75768153c3a8a9e8039d4b25bb9b14efbc58e9c4a6e6a270abff1cd30cbe320", [:mix], [{:cowboy, "~> 2.5", [hex: :cowboy, repo: "hexpm", optional: false]}, {:plug, "~> 1.7", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}, "plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm"}, "poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm"}, - "ranch": {:hex, :ranch, "1.3.2", "e4965a144dc9fbe70e5c077c65e73c57165416a901bd02ea899cfd95aa890986", [:rebar3], [], "hexpm"}, + "ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm"}, "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.4", "f0eafff810d2041e93f915ef59899c923f4568f4585904d010387ed74988e77b", [:make, :mix, :rebar3], [], "hexpm"}, + "telemetry": {:hex, :telemetry, "0.4.0", "8339bee3fa8b91cb84d14c2935f8ecf399ccd87301ad6da6b71c09553834b2ab", [:rebar3], [], "hexpm"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.4.1", "d869e4c68901dd9531385bb0c8c40444ebf624e60b6962d95952775cac5e90cd", [:rebar3], [], "hexpm"}, } diff --git a/package.json b/package.json index 9748c87..022ec31 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "dependencies": { "phoenix": "file:deps/phoenix", "phoenix_html": "file:deps/phoenix_html", + "phoenix_live_view": "file:deps/phoenix_live_view", "jquery": ">= 3.1.1", "bootstrap": "~3.3.7" }, diff --git a/test/integration/lv_cohabitation_test.exs b/test/integration/lv_cohabitation_test.exs new file mode 100644 index 0000000..2604554 --- /dev/null +++ b/test/integration/lv_cohabitation_test.exs @@ -0,0 +1,73 @@ +defmodule DrabTestApp.LVCohabitationTest do + import Drab.Live + use DrabTestApp.IntegrationCase + + # setup do + # index_drab() |> navigate_to() + # # wait for the Drab to initialize + # find_element(:id, "page_loaded_indicator") + # [socket: drab_socket()] + # end + + + describe "LV Cohabitation" do + + # Check Drab page updated by COmmander + test "A Drab page should mutate assigns" do + navigate_to_drab_page() + socket = drab_socket() + + # mutate assign + assert poke(socket, status: "initialised") == {:ok, 1} + + # Process.sleep(500) + + # check mutation + assert peek(socket, :status) == {:ok, "initialised"} + end + + # Check LV page rendered by Controller + test "A LV page rendered trough a Controller should be available" do + navigate_to_lv_page() + assert true + end + + # Check LV page direct render + test "A direct rendered LV page should be available" do + navigate_to_live_page() + assert true + end + end + + # Helpers + + defp navigate_to_drab_page() do + DrabTestApp.Endpoint + |> cohabitation_url(:index_drab, id: 42) + |> navigate_to() + + # # Drab onload is async, so wait a little bitncfor its completionxw + # Process.sleep(500) + + find_element(:id, "page_loaded_indicator") + find_element(:id, "muted_assign_indicator_42") + end + + defp navigate_to_lv_page() do + DrabTestApp.Endpoint + |> cohabitation_url(:index_lv, id: 42) + |> navigate_to() + + find_element(:id, "page_loaded_indicator") + find_element(:id, "muted_assign_indicator_42") + end + + defp navigate_to_live_page() do + DrabTestApp.Endpoint + |> cohabitation_live_url(DrabTestApp.LVCohabitationLive, id: 42) + |> navigate_to() + + find_element(:id, "muted_assign_indicator_42") + end + +end diff --git a/test/support/lib/drab_test_app/endpoint.ex b/test/support/lib/drab_test_app/endpoint.ex index f8cd9ec..8b72496 100644 --- a/test/support/lib/drab_test_app/endpoint.ex +++ b/test/support/lib/drab_test_app/endpoint.ex @@ -2,7 +2,8 @@ defmodule DrabTestApp.Endpoint do @moduledoc false use Phoenix.Endpoint, otp_app: :drab - + + socket "/live", Phoenix.LiveView.Socket socket("/socket", DrabTestApp.UserSocket) # Serve at "/" the static files from "priv/static" directory. diff --git a/test/support/router.ex b/test/support/router.ex index bd607a8..ade6331 100644 --- a/test/support/router.ex +++ b/test/support/router.ex @@ -7,6 +7,7 @@ defmodule DrabTestApp.Router do plug(:accepts, ["html"]) plug(:fetch_session) plug(:fetch_flash) + plug Phoenix.LiveView.Flash plug(:protect_from_forgery) plug(:put_secure_browser_headers) end @@ -49,6 +50,10 @@ defmodule DrabTestApp.Router do get("/tests/live/broadcasting", LiveController, :broadcasting, as: :broadcasting) get("/tests/element", ElementController, :index, as: :element) + + get("/tests/cohabitation_drab", LVCohabitationController, :index_drab, as: :cohabitation) + get("/tests/cohabitation_lv", LVCohabitationController, :index_lv, as: :cohabitation) + live("/tests/cohabitation_live", LVCohabitationLive, as: :cohabitation_live) end # Other scopes may use custom stacks. diff --git a/test/support/web/commanders/lv_cohabitation_commander.ex b/test/support/web/commanders/lv_cohabitation_commander.ex new file mode 100644 index 0000000..49337c5 --- /dev/null +++ b/test/support/web/commanders/lv_cohabitation_commander.ex @@ -0,0 +1,13 @@ +defmodule DrabTestApp.LVCohabitationCommander do + @moduledoc false + + use Drab.Commander + + onload(:page_loaded) + + def page_loaded(socket) do + DrabTestApp.IntegrationCase.add_page_loaded_indicator(socket) + DrabTestApp.IntegrationCase.add_pid(socket) + end + +end diff --git a/test/support/web/controllers/lv_cohabitation_controller.ex b/test/support/web/controllers/lv_cohabitation_controller.ex new file mode 100644 index 0000000..e5ce9fd --- /dev/null +++ b/test/support/web/controllers/lv_cohabitation_controller.ex @@ -0,0 +1,14 @@ +defmodule DrabTestApp.LVCohabitationController do + @moduledoc false + + use DrabTestApp.Web, :controller + require Logger + + def index_drab(conn, params) do + render(conn, "index_drab.html", status: "unititialised", id: params["id"]) + end + + def index_lv(conn, params) do + live_render(conn, DrabTestApp.LVCohabitationLive , session: %{status: "unititialised", id: params["id"]}) + end +end diff --git a/test/support/web/live/lv_cohabitation_live.ex b/test/support/web/live/lv_cohabitation_live.ex new file mode 100644 index 0000000..d39d03a --- /dev/null +++ b/test/support/web/live/lv_cohabitation_live.ex @@ -0,0 +1,32 @@ +defmodule DrabTestApp.LVCohabitationLive do + use Phoenix.LiveView + + def render(assigns) do + DrabTestApp.LVCohabitationView.render("index_lv.html", assigns) + end + + def mount(session, socket) do + socket = + if id = session[:id] do + socket + |> assign(id: session.id) + |> assign(status: "uninitialised") + else + socket + end + {:ok, socket} + end + + def handle_params(params, _uri, socket) do + socket = + if id = params["id"] do + socket + |> assign(id: id) + |> assign(status: "uninitialised") + else + socket + end + {:noreply, socket} + end + +end diff --git a/test/support/web/static/js/app.js b/test/support/web/static/js/app.js index e7549b9..5584bbd 100644 --- a/test/support/web/static/js/app.js +++ b/test/support/web/static/js/app.js @@ -19,3 +19,7 @@ import "phoenix_html" // paths "./socket" or full ones "web/static/js/socket". // import socket from "./socket" + +import LiveSocket from "phoenix_live_view" +let liveSocket = new LiveSocket("/live") +liveSocket.connect() \ No newline at end of file diff --git a/test/support/web/templates/lv_cohabitation/index_drab.html.drab b/test/support/web/templates/lv_cohabitation/index_drab.html.drab new file mode 100644 index 0000000..e5084cb --- /dev/null +++ b/test/support/web/templates/lv_cohabitation/index_drab.html.drab @@ -0,0 +1,8 @@ + + +
+
+ +
+ +

@status: <%= inspect @status %>

diff --git a/test/support/web/templates/lv_cohabitation/index_lv.html.leex b/test/support/web/templates/lv_cohabitation/index_lv.html.leex new file mode 100644 index 0000000..2ec1d37 --- /dev/null +++ b/test/support/web/templates/lv_cohabitation/index_lv.html.leex @@ -0,0 +1,8 @@ + + +
+
+ +
+ +

@status: <%= inspect @status %>

diff --git a/test/support/web/views/lv_cohabitation_view.ex b/test/support/web/views/lv_cohabitation_view.ex new file mode 100644 index 0000000..e073c41 --- /dev/null +++ b/test/support/web/views/lv_cohabitation_view.ex @@ -0,0 +1,5 @@ +defmodule DrabTestApp.LVCohabitationView do + @moduledoc false + + use DrabTestApp.Web, :view +end diff --git a/test/support/web/web.ex b/test/support/web/web.ex index 74e8fb7..f303f08 100644 --- a/test/support/web/web.ex +++ b/test/support/web/web.ex @@ -13,6 +13,7 @@ defmodule DrabTestApp.Web do import DrabTestApp.Router.Helpers import DrabTestApp.Gettext + import Phoenix.LiveView.Controller, only: [live_render: 3] end end @@ -29,12 +30,14 @@ defmodule DrabTestApp.Web do import DrabTestApp.Router.Helpers import DrabTestApp.ErrorHelpers import DrabTestApp.Gettext + import Phoenix.LiveView, only: [live_render: 2, live_render: 3, live_link: 1, live_link: 2] end end def router do quote do use Phoenix.Router + import Phoenix.LiveView.Router end end From 41466528a10bcbfb3e148ecde44fae39b48043d1 Mon Sep 17 00:00:00 2001 From: Guido Tripaldi Date: Fri, 6 Sep 2019 10:59:40 +0200 Subject: [PATCH 6/7] Updates Travis configuration --- .travis.yml | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 200aa41..550d89d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,13 +14,32 @@ before_install: - sudo apt-get install chromium-chromedriver elixir: - - 1.6.6 - - 1.7.4 - - 1.8.2 + - 1.6 + - 1.7 + - 1.8 + - 1.9 otp_release: - - 20.0 + - 20.3 - 21.0 - 22.0 +matrix: + exclude: + - elixir: 1.6 + otp_release: 21.0 + - elixir: 1.6 + otp_release: 22.0 + - elixir: 1.7 + otp_release: 19.3 + - elixir: 1.7 + otp_release: 20.3 + - elixir: 1.8 + otp_release: 19.3 + - elixir: 1.8 + otp_release: 20.3 + - elixir: 1.9 + otp_release: 19.3 + - elixir: 1.9 + otp_release: 20.3 env: - MIX_ENV=test From 67414a525ab082a96fd9389b4e9089af59e1a3c7 Mon Sep 17 00:00:00 2001 From: Guido Tripaldi Date: Fri, 6 Sep 2019 15:10:36 +0200 Subject: [PATCH 7/7] Updates Travis configuration elixir/erlang versions combination from LiveView --- .travis.yml | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 550d89d..dc9d202 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,32 +14,27 @@ before_install: - sudo apt-get install chromium-chromedriver elixir: - - 1.6 - 1.7 - 1.8 - - 1.9 + otp_release: + - 19.3 - 20.3 - 21.0 - - 22.0 + - 22.0.1 + matrix: exclude: - - elixir: 1.6 - otp_release: 21.0 - - elixir: 1.6 - otp_release: 22.0 - elixir: 1.7 otp_release: 19.3 - elixir: 1.7 otp_release: 20.3 + - elixir: 1.7 + otp_release: 22.0.1 - elixir: 1.8 otp_release: 19.3 - elixir: 1.8 otp_release: 20.3 - - elixir: 1.9 - otp_release: 19.3 - - elixir: 1.9 - otp_release: 20.3 env: - MIX_ENV=test