This repository was archived by the owner on Oct 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathopal_jquery_extensions_spec.rb
94 lines (87 loc) · 2.8 KB
/
opal_jquery_extensions_spec.rb
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
require 'spec_helper'
describe 'opal-jquery extensions', js: true do
describe 'Element' do
xit 'will reuse the wrapper component class for the same Element' do
evaluate_ruby do
class Foo < React::Component::Base
param :name
def render
"hello #{params.name}"
end
def self.rec_cnt
@@rec_cnt ||= 0
end
before_unmount do
@@rec_cnt ||= 0
@@rec_cnt += 1
end
end
end
expect_evaluate_ruby do
test_div = Element.new(:div)
test_div.render { Foo(name: 'fred') }
test_div.render { Foo(name: 'freddy') }
[ Element[test_div].find('span').html, Foo.rec_cnt]
end.to eq(['hello freddy', 0])
end
it 'renders a top level component using render with a block' do
expect_evaluate_ruby do
class Foo < React::Component::Base
param :name
def render
"hello #{params.name}"
end
end
test_div = Element.new(:div)
test_div.render { Foo(name: 'fred') }
Element[test_div].find('span').html
end.to eq('hello fred')
end
it 'renders a top level component using render with a container and params ' do
expect_evaluate_ruby do
test_div = Element.new(:div)
test_div.render(:span, id: :render_test_span) { 'hello' }
Element[test_div].find('#render_test_span').html
end.to eq('hello')
end
it 'will find the DOM node given a react element' do
expect_evaluate_ruby do
class Foo < React::Component::Base
def render
div { 'hello' }
end
end
Element[React::Test::Utils.render_component_into_document(Foo)].html
end.to eq('hello')
end
it "accepts plain js object as selector" do
evaluate_ruby do
Element[JS.call(:eval, "(function () { return window; })();")]
end
expect(page.driver.browser.manage.logs.get(:browser).map { |m| m.message.gsub(/\\n/, "\n") }.to_a.join("\n"))
.not_to match(/Exception|Error/)
end
it "can dynamically mount components" do
on_client do
class DynoMount < Hyperloop::Component
render(DIV) { 'I got rendered' }
end
end
mount 'MountPoint' do
class MountPoint < Hyperloop::Component
render(DIV) do
# simulate what react-rails render_component output
DIV(
'data-react-class' => 'React.TopLevelRailsComponent',
'data-react-props' => '{"render_params": {}, "component_name": "DynoMount", "controller": ""}'
)
end
end
end
evaluate_ruby do
Element['body'].mount_components
end
expect(page).to have_content('I got rendered')
end
end
end