/
react_phoenix_test.exs
46 lines (34 loc) · 1.54 KB
/
react_phoenix_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
defmodule ReactPhoenixTest do
use ExUnit.Case
doctest ReactPhoenix
import ReactPhoenix.ClientSide
test "react_component returns a safe tuple" do
assert {:safe, _} = react_component("test")
end
test "react_component returns a renderable div" do
html = Phoenix.HTML.safe_to_string(react_component("test"))
assert String.match?(html, ~r|^<div.*></div>$|)
end
test "react_component returns a renderable div with data-react-class containing component name" do
html = Phoenix.HTML.safe_to_string(react_component("test"))
assert String.match?(html, ~r|data-react-class="test"|)
end
test "react_component returns a renderable div with data-react-props containing props list" do
html = Phoenix.HTML.safe_to_string(react_component("test", my: "props"))
expected =
"<div data-react-class=\"test\" data-react-props=\"{"my":"props"}\"></div>"
assert html == expected
end
test "react_component returns a renderable div with data-react-props containing props map" do
html = Phoenix.HTML.safe_to_string(react_component("test", %{my: "props"}))
expected =
"<div data-react-class=\"test\" data-react-props=\"{"my":"props"}\"></div>"
assert html == expected
end
test "react_component accepts a target div option" do
html = Phoenix.HTML.safe_to_string(react_component("test", %{}, target_id: "test-id"))
expected =
"<div data-react-class=\"test\" data-react-props=\"{}\" data-react-target-id=\"test-id\"></div>"
assert html == expected
end
end