Skip to content

Commit

Permalink
Added test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardarella committed Jan 14, 2024
1 parent f690a94 commit 1fc76f0
Show file tree
Hide file tree
Showing 16 changed files with 166 additions and 14 deletions.
13 changes: 13 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# This file is responsible for configuring your application
# and its dependencies with the aid of the Config module.
#
# This configuration file is loaded before any dependency and
# is restricted to this project.

# General application configuration
import Config

config :logger, :level, :debug
config :logger, :backends, []

import_config "#{config_env()}.exs"
23 changes: 23 additions & 0 deletions config/test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Config

config :live_view_native, plugins: [
LiveViewNative.HTML
]

# config :phoenix_template, format_encoders: [
# html: Phoenix.HTML.Engine
# ]

# config :phoenix, template_engines: [
# heex: LiveViewNative.Engine
# ]

config :live_view_native_test,
formats: [:html],
otp_app: :live_view_native_html,
routes: [
%{path: "/inline", module: LiveViewNativeTest.HTML.InlineLive},
%{path: "/template", module: LiveViewNativeTest.HTML.TemplateLive}
]

config :phoenix, :plug_init_mode, :runtime
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ defmodule LiveViewNativeHtml.MixProject do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
# {:live_view_native, path: "../live_view_native"},
{:floki, ">= 0.30.0", only: :test},
# {:live_view_native, path: "../live_view_native", override: true},
{:live_view_native, github: "liveview-native/live_view_native"},
# {:phoenix_live_view, path: "../phoenix_live_view", override: true},
{:phoenix_live_view, github: "phoenixframework/phoenix_live_view", ref: "476d1cd288474d7acb33424a74b304b4e9495ff1", override: true},
Expand Down
7 changes: 2 additions & 5 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
"cowboy": {:hex, :cowboy, "2.10.0", "ff9ffeff91dae4ae270dd975642997afe2a1179d94b1887863e43f681a203e26", [:make, :rebar3], [{:cowlib, "2.12.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "3afdccb7183cc6f143cb14d3cf51fa00e53db9ec80cdcd525482f5e99bc41d6b"},
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"},
"cowlib": {:hex, :cowlib, "2.12.1", "a9fa9a625f1d2025fe6b462cb865881329b5caff8f1854d1cbc9f9533f00e1e1", [:make, :rebar3], [], "hexpm", "163b73f6367a7341b33c794c4e88e7dbfe6498ac42dcd69ef44c5bc5507c8db0"},
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
"deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"},
"ecto": {:hex, :ecto, "3.11.1", "4b4972b717e7ca83d30121b12998f5fcdc62ba0ed4f20fd390f16f3270d85c3e", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "ebd3d3772cd0dfcd8d772659e41ed527c28b2a8bde4b00fe03e0463da0f1983b"},
"floki": {:hex, :floki, "0.35.2", "87f8c75ed8654b9635b311774308b2760b47e9a579dabf2e4d5f1e1d42c39e0b", [:mix], [], "hexpm", "6b05289a8e9eac475f644f09c2e4ba7e19201fd002b89c28c1293e7bd16773d9"},
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},
"live_view_native": {:git, "https://github.com/liveview-native/live_view_native.git", "324f355f60a757384b3d46d6d3abb5abbeed5794", []},
"live_view_native_platform": {:hex, :live_view_native_platform, "0.2.0-beta.2", "8cd8eb8d18e2250bc497f1e0a5338430783ec97bf9f64b148df4bfb267c32ec4", [:mix], [{:ecto, "~> 3.8", [hex: :ecto, repo: "hexpm", optional: false]}, {:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: false]}], "hexpm", "2ee4626999348e643736e5993aa6f1458754e4c73b58b84197f2b446eb48ce50"},
"live_view_native": {:git, "https://github.com/liveview-native/live_view_native.git", "ef9d27e8220c399c4c19acfffdddd8c808f26ec4", []},
"live_view_native_test": {:git, "https://github.com/liveview-native/live_view_native_test.git", "2a6f551c571a6575ba1dc74368171b0f9f667578", []},
"mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"},
"owl": {:hex, :owl, "0.8.0", "0ef925cb784311093d4e3734822960cbdbdb13b095d748bb5bc82abcd5b56732", [:mix], [], "hexpm", "0a5586ceb1a12f4bbda90e330c20e6ea034552335d09466c10e4218c98977529"},
"phoenix": {:hex, :phoenix, "1.7.10", "02189140a61b2ce85bb633a9b6fd02dff705a5f1596869547aeb2b2b95edd729", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "cf784932e010fd736d656d7fead6a584a4498efefe5b8227e9f383bf15bb79d0"},
"phoenix_html": {:hex, :phoenix_html, "3.3.3", "380b8fb45912b5638d2f1d925a3771b4516b9a78587249cabe394e0a5d579dc9", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "923ebe6fec6e2e3b3e569dfbdc6560de932cd54b000ada0208b5f45024bdd76c"},
"phoenix_html": {:hex, :phoenix_html, "4.0.0", "4857ec2edaccd0934a923c2b0ba526c44a173c86b847e8db725172e9e51d11d6", [:mix], [], "hexpm", "cee794a052f243291d92fa3ccabcb4c29bb8d236f655fb03bcbdc3a8214b8d13"},
"phoenix_live_view": {:git, "https://github.com/phoenixframework/phoenix_live_view.git", "476d1cd288474d7acb33424a74b304b4e9495ff1", [ref: "476d1cd288474d7acb33424a74b304b4e9495ff1"]},
"phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.3", "3168d78ba41835aecad272d5e8cd51aa87a7ac9eb836eabc42f6e57538e3731d", [:mix], [], "hexpm", "bba06bc1dcfd8cb086759f0edc94a8ba2bc8896d5331a1e2c2902bf8e36ee502"},
"phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"},
Expand Down
8 changes: 0 additions & 8 deletions test/live_view_native/html_test.exs

This file was deleted.

27 changes: 27 additions & 0 deletions test/live_view_native_html/integrations/inline_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
defmodule LiveViewNative.HTML.InlineRenderTest do
use ExUnit.Case, async: false

import Phoenix.ConnTest
import Plug.Conn, only: [put_req_header: 3]
import Phoenix.LiveViewTest

@endpoint LiveViewNativeTest.Endpoint

setup do
{:ok, conn: Plug.Test.init_test_session(build_conn(), %{})}
end

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

assert lv |> element("#override-container #inline") |> render() =~ "Inline HTML Override Render 100"
end

test "can render the override html format with mobile target", %{conn: conn} do
conn = put_req_header(conn, "accept", "text/html")
{:ok, lv, _html} = live(conn, "/inline?target=mobile")

assert lv |> element("#mobile-inline") |> render() =~ "Mobile Target Inline HTML Override Render 100"
end
end
27 changes: 27 additions & 0 deletions test/live_view_native_html/integrations/template_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
defmodule LiveViewNative.HTML.TemplateRenderTest do
use ExUnit.Case, async: false

import Phoenix.ConnTest
import Plug.Conn, only: [put_req_header: 3]
import Phoenix.LiveViewTest

@endpoint LiveViewNativeTest.Endpoint

setup do
{:ok, conn: Plug.Test.init_test_session(build_conn(), %{})}
end

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

assert lv |> element("#override-container #template") |> render() =~ "Template HTML Override Render 100"
end

test "can render the override html format with mobile target", %{conn: conn} do
conn = put_req_header(conn, "accept", "text/html")
{:ok, lv, _html} = live(conn, "/template?target=mobile")

assert lv |> element("#mobile-template") |> render() =~ "Mobile Target Template HTML Override Render 100"
end
end
8 changes: 8 additions & 0 deletions test/support/components/layouts.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule LiveViewNativeTest.HTML.Layouts do
use Phoenix.Component

import Phoenix.Controller,
only: [get_csrf_token: 0]

embed_templates "layouts/*"
end
1 change: 1 addition & 0 deletions test/support/components/layouts/app.html.heex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div id="html-container"><%= @inner_content %></div>
1 change: 1 addition & 0 deletions test/support/components/layouts/override.html.heex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div id="override-container"><%= @inner_content %></div>
2 changes: 2 additions & 0 deletions test/support/components/layouts/root.html.heex
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<meta name="csrf-token" content={get_csrf_token()} />
<%= @inner_content %>
1 change: 1 addition & 0 deletions test/support/live/html/template_live.html+mobile.heex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div id="mobile-template">Mobile Target Template HTML Override Render <%= @count %></div>
1 change: 1 addition & 0 deletions test/support/live/html/template_live.html.heex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<div id="template">Template HTML Override Render <%= @count %></div>
34 changes: 34 additions & 0 deletions test/support/live/html_inline_live.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
defmodule LiveViewNativeTest.HTML.InlineLive.HTML do
use LiveViewNative.Component,
format: :html,
as: :render

def render(assigns, %{target: "mobile"}) do
~H"""
<div id="mobile-inline">Mobile Target Inline HTML Override Render <%= @count %></div>
"""
end

def render(assigns, _interface) do
~H"""
<div id="inline">Inline HTML Override Render <%= @count %></div>
"""
end
end

defmodule LiveViewNativeTest.HTML.InlineLive do
use Phoenix.LiveView,
layout: {LiveViewNativeTest.HTML.Layouts, :app}

use LiveViewNative.LiveView,
formats: [:html],
layouts: [
html: {LiveViewNativeTest.HTML.Layouts, :override}
]

def mount(_params, _session, socket) do
{:ok, assign(socket, :count, 100)}
end

def render(assigns), do: ~H""
end
22 changes: 22 additions & 0 deletions test/support/live/html_template_live.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
defmodule LiveViewNativeTest.HTML.TemplateLive.HTML do
use LiveViewNative.Component,
format: :html,
as: :render
end

defmodule LiveViewNativeTest.HTML.TemplateLive do
use Phoenix.LiveView,
layout: {LiveViewNativeTest.HTML.Layouts, :app}

use LiveViewNative.LiveView,
formats: [:html],
layouts: [
html: {LiveViewNativeTest.HTML.Layouts, :override}
]

def mount(_params, _session, socket) do
{:ok, assign(socket, :count, 100)}
end

def render(assigns), do: ~H""
end
2 changes: 2 additions & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
{:ok, _} = LiveViewNativeTest.Endpoint.start_link()

ExUnit.start()

0 comments on commit 1fc76f0

Please sign in to comment.