Skip to content

Commit caf75aa

Browse files
authored
Remove phx-update=append/prepend in tests (#3724)
This has been deprecated long before v1.0 and, while we kept some support to ease migration, it is time to push away from it.
1 parent af998ff commit caf75aa

File tree

2 files changed

+3
-131
lines changed

2 files changed

+3
-131
lines changed

lib/phoenix_live_view/test/dom.ex

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -439,51 +439,9 @@ defmodule Phoenix.LiveViewTest.DOM do
439439
end
440440
end
441441

442-
defp apply_phx_update(type, html_tree, {tag, attrs, appended_children} = node, _streams)
443-
when type in ["append", "prepend"] do
444-
container_id = attribute(node, "id")
445-
verify_phx_update_id!(type, container_id, node)
446-
children_before = apply_phx_update_children(html_tree, container_id)
447-
existing_ids = apply_phx_update_children_id(type, children_before)
448-
new_ids = apply_phx_update_children_id(type, appended_children)
449-
450-
content_changed? =
451-
new_ids != existing_ids
452-
453-
dup_ids =
454-
if content_changed? && new_ids do
455-
Enum.filter(new_ids, fn id -> id in existing_ids end)
456-
else
457-
[]
458-
end
459-
460-
{updated_existing_children, updated_appended} =
461-
Enum.reduce(dup_ids, {children_before, appended_children}, fn dup_id, {before, appended} ->
462-
patched_before =
463-
walk(before, fn {tag, _, _} = node ->
464-
cond do
465-
attribute(node, "id") == dup_id ->
466-
new_node = by_id!(appended, dup_id)
467-
{tag, attrs(new_node), child_nodes(new_node)}
468-
469-
true ->
470-
node
471-
end
472-
end)
473-
474-
{patched_before, Floki.filter_out(appended, "##{dup_id}")}
475-
end)
476-
477-
cond do
478-
content_changed? && type == "append" ->
479-
{tag, attrs, updated_existing_children ++ updated_appended}
480-
481-
content_changed? && type == "prepend" ->
482-
{tag, attrs, updated_appended ++ updated_existing_children}
483-
484-
!content_changed? ->
485-
{tag, attrs, updated_appended}
486-
end
442+
defp apply_phx_update(type, _html_tree, _node, _streams) when type in ["append", "prepend"] do
443+
raise ArgumentError,
444+
"phx-update=#{inspect(type)} has been deprecated before v1.0 and is no longer supported in tests"
487445
end
488446

489447
defp apply_phx_update("stream", html_tree, {tag, attrs, appended_children} = node, streams) do

test/phoenix_live_view/test/dom_test.exs

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -143,92 +143,6 @@ defmodule Phoenix.LiveViewTest.DOMTest do
143143
assert new_html =~ ~S(<div id="4">a</div>)
144144
end
145145

146-
test "inserts new elements when phx-update=append" do
147-
html = """
148-
<div data-phx-session="SESSIONMAIN"
149-
data-phx-main="true"
150-
id="phx-458">
151-
<div id="list" phx-update="append">
152-
<div id="1">a</div>
153-
<div id="2">a</div>
154-
<div id="3">a</div>
155-
</div>
156-
</div>
157-
"""
158-
159-
inner_html = """
160-
<div id="list" phx-update="append">
161-
<div id="4" class="foo">a</div>
162-
</div>
163-
"""
164-
165-
{new_html, _removed_cids} =
166-
DOM.patch_id("phx-458", DOM.parse(html), DOM.parse(inner_html), [])
167-
168-
new_html = DOM.to_html(new_html)
169-
170-
assert new_html =~ ~S(<div id="1">a</div>)
171-
assert new_html =~ ~S(<div id="2">a</div>)
172-
assert new_html =~ ~S(<div id="3">a</div><div id="4" class="foo">a</div>)
173-
end
174-
175-
test "inserts new elements when phx-update=prepend" do
176-
html = """
177-
<div data-phx-session="SESSIONMAIN"
178-
data-phx-main="true"
179-
id="phx-458">
180-
<div id="list" phx-update="append">
181-
<div id="1">a</div>
182-
<div id="2">a</div>
183-
<div id="3">a</div>
184-
</div>
185-
</div>
186-
"""
187-
188-
inner_html = """
189-
<div id="list" phx-update="prepend">
190-
<div id="4">a</div>
191-
</div>
192-
"""
193-
194-
{new_html, _removed_cids} =
195-
DOM.patch_id("phx-458", DOM.parse(html), DOM.parse(inner_html), [])
196-
197-
new_html = DOM.to_html(new_html)
198-
199-
assert new_html =~ ~S(<div id="4">a</div><div id="1">a</div>)
200-
assert new_html =~ ~S(<div id="2">a</div>)
201-
assert new_html =~ ~S(<div id="3">a</div>)
202-
end
203-
204-
test "updates existing elements when phx-update=append" do
205-
html = """
206-
<div data-phx-session="SESSIONMAIN" data-phx-main="true" id="phx-458">
207-
<div id="list" phx-update="append">
208-
<div id="1">a</div>
209-
<div id="2">a</div>
210-
<div id="3">a</div>
211-
</div>
212-
</div>
213-
"""
214-
215-
inner_html = """
216-
<div id="list" phx-update="append">
217-
<div id="1" class="foo">b</div>
218-
<div id="2">b</div>
219-
</div>
220-
"""
221-
222-
{new_html, _removed_cids} =
223-
DOM.patch_id("phx-458", DOM.parse(html), DOM.parse(inner_html), [])
224-
225-
new_html = DOM.to_html(new_html)
226-
227-
assert new_html =~ ~S(<div id="1" class="foo">b</div>)
228-
assert new_html =~ ~S(<div id="2">b</div>)
229-
assert new_html =~ ~S(<div id="3">a</div>)
230-
end
231-
232146
test "patches only container data attributes when phx-update=ignore" do
233147
html = """
234148
<div data-phx-session="SESSIONMAIN" data-phx-main="true" id="phx-458">

0 commit comments

Comments
 (0)