|
2 | 2 |
|
3 | 3 | if opal?
|
4 | 4 | describe 'the React DSL' do
|
5 |
| - it "will treat the component class name as a first class component name" # Foo() |
6 |
| - it "can add class names by the haml .class notation" # Foo.my_class |
7 |
| - it "can use the 'class' keyword for classes" # Foo(class: "my-class") |
8 |
| - it "will turn the last string in a block into a span" # Foo { "hello there" } |
9 |
| - it "has a .span short hand String method" # "hello there".span |
10 |
| - it "has a .br short hand String method" |
11 |
| - it "has a .td short hand String method" |
12 |
| - it "has a .para short hand String method" |
13 |
| - it "can generate a unrendered node using the .as_node method" # div { "hello" }.as_node |
14 |
| - it "can use the dangerously_set_inner_HTML param" # div { dangerously_set_inner_HTML: "<div>danger</div>" } |
| 5 | + |
| 6 | + it "will turn the last string in a block into a element" do |
| 7 | + stub_const 'Foo', Class.new |
| 8 | + Foo.class_eval do |
| 9 | + include React::Component |
| 10 | + def render |
| 11 | + div { "hello" } |
| 12 | + end |
| 13 | + end |
| 14 | + |
| 15 | + expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div>hello</div>') |
| 16 | + end |
| 17 | + |
| 18 | + it "has a .span short hand String method" do |
| 19 | + stub_const 'Foo', Class.new |
| 20 | + Foo.class_eval do |
| 21 | + include React::Component |
| 22 | + def render |
| 23 | + div { "hello".span; "goodby".span } |
| 24 | + end |
| 25 | + end |
| 26 | + |
| 27 | + expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div><span>hello</span><span>goodby</span></div>') |
| 28 | + end |
| 29 | + |
| 30 | + it "has a .br short hand String method" do |
| 31 | + stub_const 'Foo', Class.new |
| 32 | + Foo.class_eval do |
| 33 | + include React::Component |
| 34 | + def render |
| 35 | + div { "hello".br } |
| 36 | + end |
| 37 | + end |
| 38 | + |
| 39 | + expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div><span>hello<br></span></div>') |
| 40 | + end |
| 41 | + |
| 42 | + it "has a .td short hand String method" do |
| 43 | + stub_const 'Foo', Class.new |
| 44 | + Foo.class_eval do |
| 45 | + include React::Component |
| 46 | + def render |
| 47 | + table { tr { "hello".td } } |
| 48 | + end |
| 49 | + end |
| 50 | + |
| 51 | + expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<table><tr><td>hello</td></tr></table>') |
| 52 | + end |
| 53 | + |
| 54 | + it "has a .para short hand String method" do |
| 55 | + stub_const 'Foo', Class.new |
| 56 | + Foo.class_eval do |
| 57 | + include React::Component |
| 58 | + def render |
| 59 | + div { "hello".para } |
| 60 | + end |
| 61 | + end |
| 62 | + |
| 63 | + expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div><p>hello</p></div>') |
| 64 | + end |
| 65 | + |
| 66 | + it "will treat the component class name as a first class component name" do |
| 67 | + stub_const 'Mod::Bar', Class.new |
| 68 | + Mod::Bar.class_eval do |
| 69 | + include React::Component |
| 70 | + def render |
| 71 | + "a man walks into a bar" |
| 72 | + end |
| 73 | + end |
| 74 | + stub_const 'Foo', Class.new(React::Component::Base) |
| 75 | + Foo.class_eval do |
| 76 | + def render |
| 77 | + Mod::Bar() |
| 78 | + end |
| 79 | + end |
| 80 | + |
| 81 | + expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span>a man walks into a bar</span>') |
| 82 | + end |
| 83 | + |
| 84 | + it "can add class names by the haml .class notation" do |
| 85 | + stub_const 'Mod::Bar', Class.new(React::Component::Base) |
| 86 | + Mod::Bar.class_eval do |
| 87 | + collect_other_params_as :attributes |
| 88 | + def render |
| 89 | + "a man walks into a bar".span(attributes) |
| 90 | + end |
| 91 | + end |
| 92 | + stub_const 'Foo', Class.new(React::Component::Base) |
| 93 | + Foo.class_eval do |
| 94 | + def render |
| 95 | + Mod::Bar().the_class |
| 96 | + end |
| 97 | + end |
| 98 | + |
| 99 | + expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span class="the-class">a man walks into a bar</span>') |
| 100 | + end |
| 101 | + |
| 102 | + it "can use the 'class' keyword for classes" do |
| 103 | + stub_const 'Foo', Class.new |
| 104 | + Foo.class_eval do |
| 105 | + include React::Component |
| 106 | + def render |
| 107 | + span(class: "the-class") { "hello" } |
| 108 | + end |
| 109 | + end |
| 110 | + |
| 111 | + expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span class="the-class">hello</span>') |
| 112 | + end |
| 113 | + |
| 114 | + it "can generate a unrendered node using the .as_node method" do # div { "hello" }.as_node |
| 115 | + stub_const 'Foo', Class.new #(React::Component::Base) |
| 116 | + Foo.class_eval do |
| 117 | + include React::Component |
| 118 | + def render |
| 119 | + span { "hello".span.as_node.class.name }.as_node.render |
| 120 | + end |
| 121 | + end |
| 122 | + |
| 123 | + expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span>React::Element</span>') |
| 124 | + end |
| 125 | + |
| 126 | + it "can use the dangerously_set_inner_HTML param" do |
| 127 | + stub_const 'Foo', Class.new |
| 128 | + Foo.class_eval do |
| 129 | + include React::Component |
| 130 | + def render |
| 131 | + div(dangerously_set_inner_HTML: { __html: "Hello Goodby" }) |
| 132 | + end |
| 133 | + end |
| 134 | + |
| 135 | + expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div>Hello Goodby</div>') |
| 136 | + end |
15 | 137 | end
|
16 | 138 | end
|
0 commit comments