851f6415fe
Integration test for slots Format integration test project Hide slots assign in temple prefixed key Won't compile temple related assigns when calling Utils.runtime_attrs Update component docs with slots usage
48 lines
1 KiB
Elixir
48 lines
1 KiB
Elixir
defmodule Temple.Parser.SlotTest do
|
|
use ExUnit.Case, async: false
|
|
alias Temple.Parser.Slot
|
|
|
|
describe "applicable?/1" do
|
|
test "runs when using the `c` ast with a block" do
|
|
ast =
|
|
quote do
|
|
slot :header, value: "yolo"
|
|
end
|
|
|
|
assert Slot.applicable?(ast)
|
|
end
|
|
end
|
|
|
|
describe "run/2" do
|
|
test "adds a node to the buffer" do
|
|
raw_ast =
|
|
quote do
|
|
slot :header, value: "yolo"
|
|
end
|
|
|
|
ast = Slot.run(raw_ast)
|
|
|
|
assert %Slot{
|
|
name: :header,
|
|
args: [value: "yolo"]
|
|
} == ast
|
|
end
|
|
end
|
|
|
|
describe "Temple.Generator.to_eex/1" do
|
|
test "emits eex for a slot" do
|
|
raw_ast =
|
|
quote do
|
|
slot :header, value: Form.form_for(changeset, action)
|
|
end
|
|
|
|
result =
|
|
raw_ast
|
|
|> Slot.run()
|
|
|> Temple.Generator.to_eex()
|
|
|
|
assert result |> :erlang.iolist_to_binary() ==
|
|
~s|<%= @__temple_slots__.header.(Enum.into([value: Form.form_for(changeset, action)], %{})) %>|
|
|
end
|
|
end
|
|
end
|