|
2 | 2 |
|
3 | 3 | if opal?
|
4 | 4 |
|
5 |
| -module TestMod123 |
6 |
| - class Bar < React::Component::Base |
| 5 | + module TestMod123 |
| 6 | + class Bar < React::Component::Base |
| 7 | + end |
7 | 8 | end
|
8 |
| -end |
9 | 9 |
|
10 |
| -describe 'the React DSL' do |
11 |
| - |
12 |
| - it "will turn the last string in a block into a element" do |
13 |
| - stub_const 'Foo', Class.new |
14 |
| - Foo.class_eval do |
15 |
| - include React::Component |
16 |
| - def render |
17 |
| - div { "hello" } |
| 10 | + describe 'the React DSL' do |
| 11 | + it "will turn the last string in a block into a element" do |
| 12 | + stub_const 'Foo', Class.new |
| 13 | + Foo.class_eval do |
| 14 | + include React::Component |
| 15 | + def render |
| 16 | + div { "hello" } |
| 17 | + end |
18 | 18 | end
|
19 |
| - end |
20 | 19 |
|
21 |
| - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div>hello</div>') |
22 |
| - end |
| 20 | + expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div>hello</div>') |
| 21 | + end |
23 | 22 |
|
24 |
| - it "has a .span short hand String method" do |
25 |
| - stub_const 'Foo', Class.new |
26 |
| - Foo.class_eval do |
27 |
| - include React::Component |
28 |
| - def render |
29 |
| - div { "hello".span; "goodby".span } |
| 23 | + it "has a .span short hand String method" do |
| 24 | + stub_const 'Foo', Class.new |
| 25 | + Foo.class_eval do |
| 26 | + include React::Component |
| 27 | + def render |
| 28 | + div { "hello".span; "goodby".span } |
| 29 | + end |
30 | 30 | end
|
31 |
| - end |
32 | 31 |
|
33 |
| - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div><span>hello</span><span>goodby</span></div>') |
34 |
| - end |
| 32 | + expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div><span>hello</span><span>goodby</span></div>') |
| 33 | + end |
35 | 34 |
|
36 |
| - it "has a .br short hand String method" do |
37 |
| - stub_const 'Foo', Class.new |
38 |
| - Foo.class_eval do |
39 |
| - include React::Component |
40 |
| - def render |
41 |
| - div { "hello".br } |
| 35 | + it "has a .br short hand String method" do |
| 36 | + stub_const 'Foo', Class.new |
| 37 | + Foo.class_eval do |
| 38 | + include React::Component |
| 39 | + def render |
| 40 | + div { "hello".br } |
| 41 | + end |
42 | 42 | end
|
43 |
| - end |
44 | 43 |
|
45 |
| - expect(React.render_to_static_markup(React.create_element(Foo)).gsub("<br/>", "<br>")).to eq('<div><span>hello<br></span></div>') |
46 |
| - end |
| 44 | + expect(React.render_to_static_markup(React.create_element(Foo)).gsub("<br/>", "<br>")).to eq('<div><span>hello<br></span></div>') |
| 45 | + end |
47 | 46 |
|
48 |
| - it "has a .td short hand String method" do |
49 |
| - stub_const 'Foo', Class.new |
50 |
| - Foo.class_eval do |
51 |
| - include React::Component |
52 |
| - def render |
53 |
| - table { tr { "hello".td } } |
| 47 | + it "has a .td short hand String method" do |
| 48 | + stub_const 'Foo', Class.new |
| 49 | + Foo.class_eval do |
| 50 | + include React::Component |
| 51 | + def render |
| 52 | + table { tr { "hello".td } } |
| 53 | + end |
54 | 54 | end
|
55 |
| - end |
56 | 55 |
|
57 |
| - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<table><tr><td>hello</td></tr></table>') |
58 |
| - end |
| 56 | + expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<table><tr><td>hello</td></tr></table>') |
| 57 | + end |
59 | 58 |
|
60 |
| - it "has a .para short hand String method" do |
61 |
| - stub_const 'Foo', Class.new |
62 |
| - Foo.class_eval do |
63 |
| - include React::Component |
64 |
| - def render |
65 |
| - div { "hello".para } |
| 59 | + it "has a .para short hand String method" do |
| 60 | + stub_const 'Foo', Class.new |
| 61 | + Foo.class_eval do |
| 62 | + include React::Component |
| 63 | + def render |
| 64 | + div { "hello".para } |
| 65 | + end |
66 | 66 | end
|
67 |
| - end |
68 | 67 |
|
69 |
| - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div><p>hello</p></div>') |
70 |
| - end |
| 68 | + expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div><p>hello</p></div>') |
| 69 | + end |
71 | 70 |
|
72 |
| - it "will treat the component class name as a first class component name" do |
73 |
| - stub_const 'Mod::Bar', Class.new |
74 |
| - Mod::Bar.class_eval do |
75 |
| - include React::Component |
76 |
| - def render |
77 |
| - "a man walks into a bar" |
| 71 | + it "will treat the component class name as a first class component name" do |
| 72 | + stub_const 'Mod::Bar', Class.new |
| 73 | + Mod::Bar.class_eval do |
| 74 | + include React::Component |
| 75 | + def render |
| 76 | + "a man walks into a bar" |
| 77 | + end |
78 | 78 | end
|
79 |
| - end |
80 |
| - stub_const 'Foo', Class.new(React::Component::Base) |
81 |
| - Foo.class_eval do |
82 |
| - def render |
83 |
| - Mod::Bar() |
| 79 | + stub_const 'Foo', Class.new(React::Component::Base) |
| 80 | + Foo.class_eval do |
| 81 | + def render |
| 82 | + Mod::Bar() |
| 83 | + end |
84 | 84 | end
|
85 |
| - end |
86 | 85 |
|
87 |
| - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span>a man walks into a bar</span>') |
88 |
| - end |
| 86 | + expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span>a man walks into a bar</span>') |
| 87 | + end |
89 | 88 |
|
90 |
| - it "can add class names by the haml .class notation" do |
91 |
| - # stub_const 'Mod::Barz', Class.new(React::Component::Base) |
92 |
| - TestMod123::Bar.class_eval do |
93 |
| - collect_other_params_as :attributes |
94 |
| - def render |
95 |
| - "a man walks into a bar".span(attributes) |
| 89 | + it "can add class names by the haml .class notation" do |
| 90 | + # stub_const 'Mod::Barz', Class.new(React::Component::Base) |
| 91 | + TestMod123::Bar.class_eval do |
| 92 | + collect_other_params_as :attributes |
| 93 | + def render |
| 94 | + "a man walks into a bar".span(attributes) |
| 95 | + end |
96 | 96 | end
|
97 |
| - end |
98 |
| - stub_const 'Foo', Class.new(React::Component::Base) |
99 |
| - Foo.class_eval do |
100 |
| - def render |
101 |
| - TestMod123::Bar().the_class |
| 97 | + stub_const 'Foo', Class.new(React::Component::Base) |
| 98 | + Foo.class_eval do |
| 99 | + def render |
| 100 | + TestMod123::Bar().the_class |
| 101 | + end |
102 | 102 | end
|
103 |
| - end |
104 | 103 |
|
105 |
| - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span class="the-class">a man walks into a bar</span>') |
106 |
| - end |
| 104 | + expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span class="the-class">a man walks into a bar</span>') |
| 105 | + end |
107 | 106 |
|
108 |
| - it "can use the 'class' keyword for classes" do |
109 |
| - stub_const 'Foo', Class.new |
110 |
| - Foo.class_eval do |
111 |
| - include React::Component |
112 |
| - def render |
113 |
| - span(class: "the-class") { "hello" } |
| 107 | + it "can use the 'class' keyword for classes" do |
| 108 | + stub_const 'Foo', Class.new |
| 109 | + Foo.class_eval do |
| 110 | + include React::Component |
| 111 | + def render |
| 112 | + span(class: "the-class") { "hello" } |
| 113 | + end |
114 | 114 | end
|
115 |
| - end |
116 | 115 |
|
117 |
| - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span class="the-class">hello</span>') |
118 |
| - end |
| 116 | + expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span class="the-class">hello</span>') |
| 117 | + end |
119 | 118 |
|
120 |
| - it "can generate a unrendered node using the .as_node method" do # div { "hello" }.as_node |
121 |
| - stub_const 'Foo', Class.new #(React::Component::Base) |
122 |
| - Foo.class_eval do |
123 |
| - include React::Component |
124 |
| - def render |
125 |
| - span { "hello".span.as_node.class.name }.as_node.render |
| 119 | + it "can generate a unrendered node using the .as_node method" do # div { "hello" }.as_node |
| 120 | + stub_const 'Foo', Class.new #(React::Component::Base) |
| 121 | + Foo.class_eval do |
| 122 | + include React::Component |
| 123 | + def render |
| 124 | + span { "hello".span.as_node.class.name }.as_node.render |
| 125 | + end |
126 | 126 | end
|
127 |
| - end |
128 | 127 |
|
129 |
| - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span>React::Element</span>') |
130 |
| - end |
| 128 | + expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span>React::Element</span>') |
| 129 | + end |
131 | 130 |
|
132 |
| - it "can use the dangerously_set_inner_HTML param" do |
133 |
| - stub_const 'Foo', Class.new |
134 |
| - Foo.class_eval do |
135 |
| - include React::Component |
136 |
| - def render |
137 |
| - div(dangerously_set_inner_HTML: { __html: "Hello Goodby" }) |
| 131 | + it "can use the dangerously_set_inner_HTML param" do |
| 132 | + stub_const 'Foo', Class.new |
| 133 | + Foo.class_eval do |
| 134 | + include React::Component |
| 135 | + def render |
| 136 | + div(dangerously_set_inner_HTML: { __html: "Hello Goodby" }) |
| 137 | + end |
138 | 138 | end
|
139 |
| - end |
140 | 139 |
|
141 |
| - expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div>Hello Goodby</div>') |
142 |
| - end |
| 140 | + expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div>Hello Goodby</div>') |
| 141 | + end |
143 | 142 |
|
144 |
| - it "will remove all elements passed as params from the rendering buffer" do |
145 |
| - stub_const 'X2', Class.new |
146 |
| - X2.class_eval do |
147 |
| - include React::Component |
148 |
| - param :ele |
149 |
| - def render |
150 |
| - div do |
151 |
| - ele.render |
152 |
| - ele.render |
| 143 | + it 'should convert a hash param to hyphenated html attributes if in React::HASH_ATTRIBUTES' do |
| 144 | + stub_const 'Foo', Class.new |
| 145 | + Foo.class_eval do |
| 146 | + include React::Component |
| 147 | + def render |
| 148 | + div(data: { foo: :bar }, aria: { foo_bar: :foo }) |
153 | 149 | end
|
154 | 150 | end
|
| 151 | + |
| 152 | + expect(React.render_to_static_markup(React.create_element(Foo))) |
| 153 | + .to eq('<div data-foo="bar" aria-foo-bar="foo"></div>') |
155 | 154 | end
|
156 |
| - stub_const 'Test', Class.new |
157 |
| - Test.class_eval do |
158 |
| - include React::Component |
159 |
| - def render |
160 |
| - X2(ele: b { "hello" }) |
| 155 | + |
| 156 | + it 'should not convert a hash param to hyphenated html attributes if not in React::HASH_ATTRIBUTES' do |
| 157 | + stub_const 'Foo', Class.new |
| 158 | + Foo.class_eval do |
| 159 | + include React::Component |
| 160 | + def render |
| 161 | + div(title: { bar: :foo }) |
| 162 | + end |
161 | 163 | end
|
| 164 | + |
| 165 | + expect(React.render_to_static_markup(React.create_element(Foo))) |
| 166 | + .to eq('<div title="{"bar"=>"foo"}"></div>') |
162 | 167 | end
|
163 | 168 |
|
164 |
| - expect(React.render_to_static_markup(React.create_element(Test))).to eq('<div><b>hello</b><b>hello</b></div>') |
| 169 | + it "will remove all elements passed as params from the rendering buffer" do |
| 170 | + stub_const 'X2', Class.new |
| 171 | + X2.class_eval do |
| 172 | + include React::Component |
| 173 | + param :ele |
| 174 | + def render |
| 175 | + div do |
| 176 | + ele.render |
| 177 | + ele.render |
| 178 | + end |
| 179 | + end |
| 180 | + end |
| 181 | + stub_const 'Test', Class.new |
| 182 | + Test.class_eval do |
| 183 | + include React::Component |
| 184 | + def render |
| 185 | + X2(ele: b { "hello" }) |
| 186 | + end |
| 187 | + end |
| 188 | + |
| 189 | + expect(React.render_to_static_markup(React.create_element(Test))).to eq('<div><b>hello</b><b>hello</b></div>') |
| 190 | + end |
165 | 191 | end
|
166 | 192 | end
|
167 |
| -end |
|
0 commit comments