@@ -3,44 +3,85 @@ defmodule ReactPhoenix.ClientSideTest do
33 doctest ReactPhoenix.ClientSide
44 import ReactPhoenix.ClientSide
55
6- test "react_component returns a safe tuple" do
6+ test "react_component/1 returns a safe tuple" do
77 assert { :safe , _ } = react_component ( "test" )
88 end
99
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+
1216 assert String . match? ( html , ~r| ^<div.*></div>$| )
1317 end
1418
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+
1725 assert String . match? ( html , ~r| data-react-class="test"| )
1826 end
1927
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 ( )
2233
2334 expected =
2435 "<div data-react-class=\" test\" data-react-props=\" {"my":"props"}\" ></div>"
2536
2637 assert html == expected
2738 end
2839
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 ( )
3145
3246 expected =
3347 "<div data-react-class=\" test\" data-react-props=\" {"my":"props"}\" ></div>"
3448
3549 assert html == expected
3650 end
3751
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 ( )
4057
4158 expected =
4259 "<div data-react-class=\" test\" data-react-props=\" {}\" data-react-target-id=\" test-id\" ></div>"
4360
4461 assert html == expected
4562 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
4687end
0 commit comments