Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Upload support in LiveViewNativeTest #219

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- LVN.concat/2
- :interface- special attribute support in tags
- async_result/1
- render_upload support in LiveViewNativeTest

### Changed

Expand Down
2 changes: 1 addition & 1 deletion lib/live_view_native.ex
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ defmodule LiveViewNative do
template_engine: config[:template_engine],
stylesheet: config[:stylesheet],
stylesheet_rules_parser: config[:stylesheet_rules_parser],
client: config[:client]
test_client: config[:test_client]

def __lvn_client__, do: true
end
Expand Down
9 changes: 5 additions & 4 deletions lib/live_view_native/test/client_proxy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ defmodule LiveViewNativeTest.ClientProxy do
defp maybe_put_container(state, %{} = _resp), do: state

defp build_client_view(%ClientProxy{} = proxy) do
%{id: id, ref: ref, topic: topic, module: module, endpoint: endpoint, pid: pid} = proxy
%View{id: id, pid: pid, proxy: {ref, topic, self()}, module: module, endpoint: endpoint}
%{id: id, ref: ref, topic: topic, module: module, endpoint: endpoint, pid: pid, client: client} = proxy
%View{id: id, pid: pid, proxy: {ref, topic, self()}, module: module, endpoint: endpoint, client: client}
end

defp mount_view(state, view, url, redirect_url) do
Expand Down Expand Up @@ -856,13 +856,14 @@ defmodule LiveViewNativeTest.ClientProxy do
|> put_reply(ref, view.pid, from, callback)
end

defp build_child(%ClientProxy{ref: ref, proxy: proxy, endpoint: endpoint, connect_params: connect_params}, attrs) do
defp build_child(%ClientProxy{ref: ref, proxy: proxy, endpoint: endpoint, connect_params: connect_params, client: client}, attrs) do
attrs_with_defaults =
Keyword.merge(attrs,
ref: ref,
proxy: proxy,
endpoint: endpoint,
connect_params: Map.take(connect_params, ["_format", "_interface"]),
client: client,
topic: "lv:#{Keyword.fetch!(attrs, :id)}"
)

Expand Down Expand Up @@ -1145,7 +1146,7 @@ defmodule LiveViewNativeTest.ClientProxy do
{:error, _, _} = error -> error
end

type == :change and tag in ~w(input select textarea) ->
type == :change and tag in tags.changeables ->
{:ok, form_defaults(node, Query.decode_init()) |> Query.decode_done()}

true ->
Expand Down
7 changes: 4 additions & 3 deletions lib/live_view_native/test/structs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ defmodule LiveViewNativeTest.View do
pid: nil,
proxy: nil,
endpoint: nil,
target: nil
target: nil,
client: nil
end

defmodule LiveViewNativeTest.Element do
Expand Down Expand Up @@ -68,9 +69,9 @@ defmodule LiveViewNativeTest.Upload do
cid: nil

@doc false
def new(pid, %Phoenix.LiveViewTest.View{} = view, form_selector, name, entries, cid) do
def new(pid, %LiveViewNativeTest.View{} = view, form_selector, name, entries, cid) do
populated_entries = Enum.map(entries, fn entry -> populate_entry(entry) end)
selector = "#{form_selector} input[type=\"file\"][name=\"#{name}\"]"
selector = "#{form_selector} #{view.client.tags.upload_input}[type=\"file\"][name=\"#{name}\"]"

%Upload{
pid: pid,
Expand Down
2 changes: 1 addition & 1 deletion lib/live_view_native/test/upload_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule LiveViewNativeTest.UploadClient do
require Logger
require Phoenix.ChannelTest

alias Phoenix.LiveViewTest.{Upload, ClientProxy}
alias LiveViewNativeTest.{Upload, ClientProxy}

def child_spec(opts) do
%{
Expand Down
4 changes: 2 additions & 2 deletions lib/live_view_native_test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ defmodule LiveViewNativeTest do

%{"_format" => format} = opts.connect_params

%{client: client} = LiveViewNative.fetch_plugin!(format)
%{test_client: client} = LiveViewNative.fetch_plugin!(format)

opts =
Map.merge(opts, %{
Expand Down Expand Up @@ -1266,7 +1266,7 @@ defmodule LiveViewNativeTest do
quote bind_quoted: [view: view, selector: form_selector, name: name, entries: entries] do
require Phoenix.ChannelTest
builder = fn -> Phoenix.ChannelTest.connect(Phoenix.LiveView.Socket, %{}) end
Phoenix.LiveViewTest.__file_input__(view, selector, name, entries, builder)
LiveViewNativeTest.__file_input__(view, selector, name, entries, builder)
end
end

Expand Down
6 changes: 3 additions & 3 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
"cowboy": {:hex, :cowboy, "2.12.0", "f276d521a1ff88b2b9b4c54d0e753da6c66dd7be6c9fca3d9418b561828a3731", [:make, :rebar3], [{:cowlib, "2.13.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "8a7abe6d183372ceb21caa2709bec928ab2b72e18a3911aa1771639bef82651e"},
"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.13.0", "db8f7505d8332d98ef50a3ef34b34c1afddec7506e4ee4dd4a3a266285d282ca", [:make, :rebar3], [], "hexpm", "e1e1284dc3fc030a64b1ad0d8382ae7e99da46c3246b815318a4b848873800a4"},
"earmark_parser": {:hex, :earmark_parser, "1.4.41", "ab34711c9dc6212dda44fcd20ecb87ac3f3fce6f0ca2f28d4a00e4154f8cd599", [:mix], [], "hexpm", "a81a04c7e34b6617c2792e291b5a2e57ab316365c2644ddc553bb9ed863ebefa"},
"earmark_parser": {:hex, :earmark_parser, "1.4.42", "f23d856f41919f17cd06a493923a722d87a2d684f143a1e663c04a2b93100682", [:mix], [], "hexpm", "6915b6ca369b5f7346636a2f41c6a6d78b5af419d61a611079189233358b8b8b"},
"ex_doc": {:hex, :ex_doc, "0.35.1", "de804c590d3df2d9d5b8aec77d758b00c814b356119b3d4455e4b8a8687aecaf", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "2121c6402c8d44b05622677b761371a759143b958c6c19f6558ff64d0aed40df"},
"expo": {:hex, :expo, "1.1.0", "f7b9ed7fb5745ebe1eeedf3d6f29226c5dd52897ac67c0f8af62a07e661e5c75", [:mix], [], "hexpm", "fbadf93f4700fb44c331362177bdca9eeb8097e8b0ef525c9cc501cb9917c960"},
"file_system": {:hex, :file_system, "1.0.1", "79e8ceaddb0416f8b8cd02a0127bdbababe7bf4a23d2a395b983c1f8b3f73edd", [:mix], [], "hexpm", "4414d1f38863ddf9120720cd976fce5bdde8e91d8283353f0e31850fa89feb9e"},
"floki": {:hex, :floki, "0.37.0", "b83e0280bbc6372f2a403b2848013650b16640cd2470aea6701f0632223d719e", [:mix], [], "hexpm", "516a0c15a69f78c47dc8e0b9b3724b29608aa6619379f91b1ffa47109b5d0dd3"},
"gettext": {:hex, :gettext, "0.26.2", "5978aa7b21fada6deabf1f6341ddba50bc69c999e812211903b169799208f2a8", [:mix], [{:expo, "~> 0.5.1 or ~> 1.0", [hex: :expo, repo: "hexpm", optional: false]}], "hexpm", "aa978504bcf76511efdc22d580ba08e2279caab1066b76bb9aa81c4a1e0a32a5"},
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
"live_view_native_test_endpoint": {:git, "https://github.com/liveview-native/live_view_native_test_endpoint.git", "29153c238498426354529ae0816e00a172247bb3", [branch: "main"]},
"live_view_native_test_endpoint": {:git, "https://github.com/liveview-native/live_view_native_test_endpoint.git", "be09319cc2def0e93a2aba79d8db7ba989560afa", [branch: "main"]},
"makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"},
"makeup_eex": {:hex, :makeup_eex, "1.0.0", "436d4c00204c250b17a775d64e197798aaf374627e6a4f2d3fd3074a8db61db4", [:mix], [{:makeup, "~> 1.2.1 or ~> 1.3", [hex: :makeup, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_html, "~> 0.1.0 or ~> 1.0", [hex: :makeup_html, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "3bb699bc519e4f509f1bf8a2e0ba0e08429edf3580053cd31a4f9c1bc5da86c8"},
"makeup_elixir": {:hex, :makeup_elixir, "1.0.0", "74bb8348c9b3a51d5c589bf5aebb0466a84b33274150e3b6ece1da45584afc82", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "49159b7d7d999e836bedaf09dcf35ca18b312230cf901b725a64f3f42e407983"},
"makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"},
"makeup_erlang": {:hex, :makeup_erlang, "1.0.1", "c7f58c120b2b5aa5fd80d540a89fdf866ed42f1f3994e4fe189abebeab610839", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "8a89a1eeccc2d798d6ea15496a6e4870b75e014d1af514b1b71fa33134f57814"},
"makeup_html": {:hex, :makeup_html, "0.1.2", "19d4050c0978a4f1618ffe43054c0049f91fe5feeb9ae8d845b5dc79c6008ae5", [:mix], [{:makeup, "~> 1.2", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "b7fb9afedd617d167e6644a0430e49c1279764bfd3153da716d4d2459b0998c5"},
"mime": {:hex, :mime, "2.0.6", "8f18486773d9b15f95f4f4f1e39b710045fa1de891fada4516559967276e4dc2", [:mix], [], "hexpm", "c9945363a6b26d747389aac3643f8e0e09d30499a138ad64fe8fd1d13d9b153e"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ defmodule LiveViewNative.LiveComponentsTest do
assert view |> element("#bumper") |> render_click() =~ "Bump: 1"

# Now click the form
assert view |> element("Form") |> render_submit() =~ "loading..."
assert view |> element("LiveForm") |> render_submit() =~ "loading..."

# Which will be reset almost immediately
assert render(view) =~ "Hello World</Button>"
Expand Down
Loading