Skip to content

Commit

Permalink
Drop HTML module
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismccord committed Sep 22, 2023
1 parent 9fd04a7 commit 42c8df1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 53 deletions.
33 changes: 33 additions & 0 deletions lib/phoenix_live_view/test/dom.ex
Original file line number Diff line number Diff line change
Expand Up @@ -569,4 +569,37 @@ defmodule Phoenix.LiveViewTest.DOM do

{tag, new_attrs, children}
end

defmacro sigil_X({:<<>>, _, [binary]}, []) when is_binary(binary) do
Macro.escape(parse_sorted!(binary))
end

defmacro sigil_x(term, []) do
quote do
unquote(__MODULE__).parse_sorted!(unquote(term))
end
end

def t2h(template) do
template
|> Phoenix.LiveViewTest.rendered_to_string()
|> parse_sorted!()
end

@doc"""
Parses HTML into Floki format with sorted attributes.
"""
def parse_sorted!(value) do
value
|> Floki.parse_fragment!()
|> Enum.map(&normalize_attribute_order/1)
end

defp normalize_attribute_order({node_type, attributes, content}),
do: {node_type, Enum.sort(attributes), Enum.map(content, &normalize_attribute_order/1)}

defp normalize_attribute_order(values) when is_list(values),
do: Enum.map(values, &normalize_attribute_order/1)

defp normalize_attribute_order(value), do: value
end
2 changes: 1 addition & 1 deletion test/phoenix_component/components_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule Phoenix.LiveView.ComponentsTest do

import Phoenix.HTML.Form
import Phoenix.Component
import Phoenix.LiveViewTest.HTML
import Phoenix.LiveViewTest.DOM, only: [t2h: 1, sigil_X: 2, sigil_x: 2]

defp render(template) do
template
Expand Down
2 changes: 1 addition & 1 deletion test/phoenix_component/declarative_assigns_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule Phoenix.ComponentDeclarativeAssignsTest do
use ExUnit.Case, async: true

import Phoenix.LiveViewTest
import Phoenix.LiveViewTest.HTML
import Phoenix.LiveViewTest.DOM, only: [t2h: 1, sigil_X: 2]
use Phoenix.Component

defp render_template(mod, func, assigns) do
Expand Down
51 changes: 0 additions & 51 deletions test/support/html.ex

This file was deleted.

0 comments on commit 42c8df1

Please sign in to comment.