-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_spec.rb
77 lines (63 loc) · 1.81 KB
/
basic_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
require "spec_helper"
RSpec.describe "Basic component" do
class BasicComponent < RailsReactComponents::Component
prop :name
prop :email, on: :user
prop :nick, delegate: :user # alias
prop :is_ready, as: :user_ready, include_blank: false
prop :this_will_be_camelized
def name
"Franek Kimono"
end
def is_ready
ready? ? 1 : ""
end
def ready?
true
end
def this_will_be_camelized
"camelized!"
end
end
describe "#props" do
it "returns initialized props hash" do
component = BasicComponent.new(user: user)
expect(component.props).to eq(
{
name: "Franek Kimono",
email: "[email protected]",
nick: "Rocky",
user_ready: 1,
thisWillBeCamelized: "camelized!"
}
)
end
context "when prop with include_blank is blank" do
it "does not return it in props" do
component = BasicComponent.new(user: user)
allow(component).to receive(:ready?) { false }
expect(component.props).to_not have_key(:userReady)
expect(component.props).to_not have_key(:is_ready)
end
end
context "when camelize_props is false" do
it "does not camelize prop names" do
RailsReactComponents.config do |config|
config.camelize_props = false
end
component = BasicComponent.new(user: user)
expect(component.props).to_not have_key(:thisWillBeCamelized)
expect(component.props).to have_key(:this_will_be_camelized)
end
end
end
describe "#component" do
it "returns class name" do
component = BasicComponent.new(user: user)
expect(component.component).to eq "BasicComponent"
end
end
def user
@user ||= double(:user, email: "[email protected]", nick: "Rocky")
end
end