Skip to content

Commit

Permalink
Fixed test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardarella committed Jan 16, 2024
1 parent ef9d27e commit 1141e4d
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 97 deletions.
2 changes: 1 addition & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ config :live_view_native_test,
%{path: "/template", module: LiveViewNativeTest.TemplateLive}
]

config :phoenix, :plug_init_mode, :runtime
config :phoenix, :plug_init_mode, :runtime
8 changes: 4 additions & 4 deletions lib/live_view_native/renderer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ defmodule LiveViewNative.Renderer do
else
quote do
def unquote(name)(var!(assigns)) do
target = LiveViewNative.Utils.get_target(var!(assigns))
apply(__MODULE__, unquote(name), [var!(assigns), %{target: target}])
interface = LiveViewNative.Utils.get_interface(var!(assigns))
apply(__MODULE__, unquote(name), [var!(assigns), interface])
end
end
end
Expand Down Expand Up @@ -123,7 +123,7 @@ defmodule LiveViewNative.Renderer do
quote do
@file unquote(template)
@external_resource unquote(template)
def unquote(name)(var!(assigns), _) do
def unquote(name)(var!(assigns), _interface) do
unquote(ast)
end
end
Expand All @@ -132,7 +132,7 @@ defmodule LiveViewNative.Renderer do
quote do
@file unquote(template)
@external_resource unquote(template)
def unquote(name)(var!(assigns), %{target: unquote(target)}) do
def unquote(name)(var!(assigns), %{"target" => unquote(target)}) do
unquote(ast)
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/live_view_native/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ defmodule LiveViewNative.Utils do
def get_format(%Socket{private: %{connect_params: %{"_format" => format}}}), do: format
def get_format(_socket), do: "html"

def get_target(%{socket: %Socket{private: %{connect_info: %{params: %{"target" => target}}}}}), do: target
def get_target(%{conn: %Plug.Conn{params: %{"target" => target}}}), do: target
def get_target(_socket), do: nil
def get_interface(%{socket: %Socket{private: %{connect_info: %{params: %{"_interface" => interface}}}}}), do: interface
def get_interface(%{conn: %Plug.Conn{params: %{"_interface" => interface}}}), do: interface
def get_interface(_socket), do: %{}

def stringify_format(format) when is_binary(format), do: format
def stringify_format(format) when is_atom(format), do: Atom.to_string(format)
Expand Down
9 changes: 4 additions & 5 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule LiveViewNative.MixProject do
use Mix.Project

@version "0.2.0"
@version "0.3.0-alpha.1"

def project do
[
Expand All @@ -16,7 +16,6 @@ defmodule LiveViewNative.MixProject do
aliases: aliases(),
deps: deps(),
test_coverage: [tool: ExCoveralls],
consolidate_protocols: Mix.env() != :test,
docs: docs()
]
end
Expand Down Expand Up @@ -53,8 +52,8 @@ defmodule LiveViewNative.MixProject do
{:makeup_eex, ">= 0.1.1", only: :dev, runtime: false},
{:owl, "~> 0.8", runtime: false},
{:deep_merge, "~> 1.0"},
# {:live_view_native_test, path: "../live_view_native_test", only: :test}
{:live_view_native_test, github: "liveview-native/live_view_native_test", only: :test}
{:live_view_native_test, path: "../live_view_native_test", only: :test}
# {:live_view_native_test, github: "liveview-native/live_view_native_test", only: :test}
]
end

Expand Down Expand Up @@ -112,7 +111,7 @@ defmodule LiveViewNative.MixProject do
# Hex package configuration
defp package do
%{
maintainers: ["May Matyi"],
maintainers: ["Brian Cardarella"],
licenses: ["MIT"],
links: %{
"GitHub" => @source_url
Expand Down
10 changes: 5 additions & 5 deletions test/live_view_native/integrations/inline_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,35 @@ defmodule LiveViewNative.InlineRenderTest do
end

test "can render the fallback html inline render", %{conn: conn} do
{:ok, lv, _html} = live(conn, "/inline")
{:ok, lv, _body} = live(conn, "/inline")

assert lv |> element("#inline") |> render() =~ "original inline HTML works"
end

test "can render the gameboy format", %{conn: conn} do
conn = put_req_header(conn, "accept", "text/gameboy")
{:ok, lv, _html} = live(conn, "/inline")
{:ok, lv, _body} = live(conn, "/inline")

assert lv |> element("gameboy") |> render() =~ "Inline GameBoy Render 100"
end

test "can render the gameboy format with tv target", %{conn: conn} do
conn = put_req_header(conn, "accept", "text/gameboy")
{:ok, lv, _html} = live(conn, "/inline?target=tv")
{:ok, lv, _body} = live(conn, "/inline?_interface[target]=tv")

assert lv |> element("gameboytv") |> render() =~ "TV Target Inline GameBoy Render 100"
end

test "can render the switch format", %{conn: conn} do
conn = put_req_header(conn, "accept", "text/switch")
{:ok, lv, _html} = live(conn, "/inline")
{:ok, lv, _body} = live(conn, "/inline")

assert lv |> element("switch") |> render() =~ "Inline Switch Render 100"
end

test "can render the switch format with tv target", %{conn: conn} do
conn = put_req_header(conn, "accept", "text/switch")
{:ok, lv, _html} = live(conn, "/inline?target=tv")
{:ok, lv, _body} = live(conn, "/inline?_interface[target]=tv")

assert lv |> element("switchtv") |> render() =~ "TV Target Inline Switch Render 100"
end
Expand Down
4 changes: 2 additions & 2 deletions test/live_view_native/integrations/template_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule LiveViewNative.TemplateRenderTest do

test "can render the gameboy format with tv target", %{conn: conn} do
conn = put_req_header(conn, "accept", "text/gameboy")
{:ok, lv, _html} = live(conn, "/template?target=tv")
{:ok, lv, _html} = live(conn, "/template?_interface[target]=tv")

assert lv |> element("gameboytv") |> render() =~ "TV Target Template GameBoy Render 200"
end
Expand All @@ -40,7 +40,7 @@ defmodule LiveViewNative.TemplateRenderTest do

test "can render the switch format with tv target", %{conn: conn} do
conn = put_req_header(conn, "accept", "text/switch")
{:ok, lv, _html} = live(conn, "/template?target=tv")
{:ok, lv, _html} = live(conn, "/template?_interface[target]=tv")

assert lv |> element("switchtv") |> render() =~ "TV Target Template Switch Render 200"
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
defmodule LiveViewNative.SessionPlugTest do
defmodule LiveViewNative.LiveReloaderTest do
use ExUnit.Case

import Plug.Test
import Plug.Conn

defp conn(path) do
conn(:get, path)
|> Plug.Conn.put_private(:phoenix_endpoint, MyApp.Endpoint)
|> Plug.Conn.put_private(:phoenix_endpoint, LiveViewNativeTest.Endpoint)
end

describe "live reloader" do
test "injects live_reload for LVN requests if configured and injects at the end of the body" do
opts = LiveViewNative.SessionPlug.init([])
opts = LiveViewNative.LiveReloader.init([])

# define so it exists
:root_layout_native

conn =
conn("/")
|> Map.put(:params, %{"_lvn" => %{"format" => "native"}})
|> put_private(:phoenix_format, "html")
|> put_private(:phoenix_root_layout, %{
"html" => {TestLayout, :root_layout}
})
|> LiveViewNative.SessionPlug.call(opts)
|> Map.put(:query_string, "_format=gameboy")
|> LiveViewNative.LiveReloader.call(opts)
|> send_resp(200, "<Text>Hello, Elixir</Text>")

assert to_string(conn.resp_body) ==
Expand Down
59 changes: 0 additions & 59 deletions test/live_view_native/live_session_test.exs

This file was deleted.

4 changes: 0 additions & 4 deletions test/live_view_native_test.exs

This file was deleted.

4 changes: 2 additions & 2 deletions test/support/live/inline_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule LiveViewNativeTest.InlineLive.GameBoy do
as: :render,
layout: {LiveViewNativeTest.GameBoyLayouts, :app}

def render(assigns, %{target: "tv"}) do
def render(assigns, %{"target" => "tv"}) do
~LVN"""
<GameBoyTV>TV Target Inline GameBoy Render <%= @count %></GameBoyTV>
"""
Expand All @@ -23,7 +23,7 @@ defmodule LiveViewNativeTest.InlineLive.Switch do
as: :render,
layout: {LiveViewNativeTest.SwitchLayouts, :app}

def render(assigns, %{target: "tv"}) do
def render(assigns, %{"target" => "tv"}) do
~LVN"""
<SwitchTV>TV Target Inline Switch Render <%= @count %></SwitchTV>
"""
Expand Down

0 comments on commit 1141e4d

Please sign in to comment.