extract test component module to a support file

This commit is contained in:
Mitchell Hanberg 2019-05-11 23:25:57 -04:00
parent 6161d31614
commit 4cdc0de71b
2 changed files with 67 additions and 66 deletions

View file

@ -2,72 +2,6 @@ defmodule Dsl.HtmlTest do
use ExUnit.Case, async: true
use Dsl
defmodule Component do
defcomponent :flex do
div(class: "flex")
end
defcomponent :takes_children do
div do
div(id: "static-child-1")
@children
div(id: "static-child-2")
end
end
defcomponent :arbitrary_code do
num = 1..10 |> Enum.reduce(0, fn x, sum -> x + sum end)
div do
text(num)
end
end
defcomponent :uses_conditionals do
if @condition do
div()
else
span()
end
end
defcomponent :arbitrary_data do
for item <- @lists do
div do
text(inspect(item))
end
end
end
defcomponent :safe do
div()
end
defcomponent :safe_with_prop do
div id: "safe-with-prop" do
text(@prop)
div do
span do
for x <- @lists do
div(do: text(x))
end
end
end
end
end
defcomponent :variable_as_prop do
div id: @bob
end
defcomponent :variable_as_prop_with_block do
div id: @bob do
@children
end
end
end
describe "non-void elements" do
test "renders two divs" do
{:safe, result} =

67
test/support/component.ex Normal file
View file

@ -0,0 +1,67 @@
defmodule Component do
import Dsl
defcomponent :flex do
div(class: "flex")
end
defcomponent :takes_children do
div do
div(id: "static-child-1")
@children
div(id: "static-child-2")
end
end
defcomponent :arbitrary_code do
num = 1..10 |> Enum.reduce(0, fn x, sum -> x + sum end)
div do
text(num)
end
end
defcomponent :uses_conditionals do
if @condition do
div()
else
span()
end
end
defcomponent :arbitrary_data do
for item <- @lists do
div do
text(inspect(item))
end
end
end
defcomponent :safe do
div()
end
defcomponent :safe_with_prop do
div id: "safe-with-prop" do
text(@prop)
div do
span do
for x <- @lists do
div(do: text(x))
end
end
end
end
end
defcomponent :variable_as_prop do
div id: @bob
end
defcomponent :variable_as_prop_with_block do
div id: @bob do
@children
end
end
end