@@ -3,44 +3,85 @@ defmodule ReactPhoenix.ClientSideTest do
3
3
doctest ReactPhoenix.ClientSide
4
4
import ReactPhoenix.ClientSide
5
5
6
- test "react_component returns a safe tuple" do
6
+ test "react_component/1 returns a safe tuple" do
7
7
assert { :safe , _ } = react_component ( "test" )
8
8
end
9
9
10
- test "react_component returns a renderable div" do
11
- html = Phoenix.HTML . safe_to_string ( react_component ( "test" ) )
10
+ test "react_component/1 returns a renderable div" do
11
+ html =
12
+ "test"
13
+ |> react_component ( )
14
+ |> Phoenix.HTML . safe_to_string ( )
15
+
12
16
assert String . match? ( html , ~r| ^<div.*></div>$| )
13
17
end
14
18
15
- test "react_component returns a renderable div with data-react-class containing component name" do
16
- html = Phoenix.HTML . safe_to_string ( react_component ( "test" ) )
19
+ test "react_component/1 returns a renderable div with data-react-class containing component name" do
20
+ html =
21
+ "test"
22
+ |> react_component ( )
23
+ |> Phoenix.HTML . safe_to_string ( )
24
+
17
25
assert String . match? ( html , ~r| data-react-class="test"| )
18
26
end
19
27
20
- test "react_component returns a renderable div with data-react-props containing props list" do
21
- html = Phoenix.HTML . safe_to_string ( react_component ( "test" , my: "props" ) )
28
+ test "react_component/2 returns a renderable div with data-react-props containing props list" do
29
+ html =
30
+ "test"
31
+ |> react_component ( my: "props" )
32
+ |> Phoenix.HTML . safe_to_string ( )
22
33
23
34
expected =
24
35
"<div data-react-class=\" test\" data-react-props=\" {"my":"props"}\" ></div>"
25
36
26
37
assert html == expected
27
38
end
28
39
29
- test "react_component returns a renderable div with data-react-props containing props map" do
30
- html = Phoenix.HTML . safe_to_string ( react_component ( "test" , % { my: "props" } ) )
40
+ test "react_component/2 returns a renderable div with data-react-props containing props map" do
41
+ html =
42
+ "test"
43
+ |> react_component ( % { my: "props" } )
44
+ |> Phoenix.HTML . safe_to_string ( )
31
45
32
46
expected =
33
47
"<div data-react-class=\" test\" data-react-props=\" {"my":"props"}\" ></div>"
34
48
35
49
assert html == expected
36
50
end
37
51
38
- test "react_component accepts a target div option" do
39
- html = Phoenix.HTML . safe_to_string ( react_component ( "test" , % { } , target_id: "test-id" ) )
52
+ test "react_component/3 accepts a target div option" do
53
+ html =
54
+ "test"
55
+ |> react_component ( % { } , target_id: "test-id" )
56
+ |> Phoenix.HTML . safe_to_string ( )
40
57
41
58
expected =
42
59
"<div data-react-class=\" test\" data-react-props=\" {}\" data-react-target-id=\" test-id\" ></div>"
43
60
44
61
assert html == expected
45
62
end
63
+
64
+ test "react_component/3 accepts a html_element option" do
65
+ html =
66
+ "test"
67
+ |> react_component ( % { } , html_element: :span )
68
+ |> Phoenix.HTML . safe_to_string ( )
69
+
70
+ expected =
71
+ "<span data-react-class=\" test\" data-react-props=\" {}\" data-react-target-id=\" \" ></span>"
72
+
73
+ assert html == expected
74
+ end
75
+
76
+ test "react_component/3 passes on extra options to the html element" do
77
+ html =
78
+ "test"
79
+ |> react_component ( % { } , class: "row" , id: "content" )
80
+ |> Phoenix.HTML . safe_to_string ( )
81
+
82
+ expected =
83
+ "<div class=\" row\" data-react-class=\" test\" data-react-props=\" {}\" data-react-target-id=\" \" id=\" content\" ></div>"
84
+
85
+ assert html == expected
86
+ end
46
87
end
0 commit comments