/
layout_spec.rb
169 lines (130 loc) · 4.65 KB
/
layout_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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
describe "SimpleView::Layout" do
class DummyController
include SimpleView::Layout
end
describe "#setup" do
it "should execute the block within view's scope" do
view = UIView.alloc.initWithFrame(CGRectZero)
DummyController.new.setup view do
view.frame = CGRectMake(0, 0, 10, 10)
end
view.frame.should == CGRectMake(0, 0, 10, 10)
end
end
describe "#add" do
before do
@controller = DummyController.new
end
it "should add view with options" do
alpha = 0.5
backgroundColor = UIColor.redColor
view = @controller.add_view UIView, top: 0, left: 0, width: 10, height: 10, alpha: alpha, backgroundColor: backgroundColor
view.frame.should == CGRectMake(0, 0, 10, 10)
view.alpha.should == alpha
view.backgroundColor.should == backgroundColor
end
describe "#add with predefined styles" do
it "should add view with default style" do
SimpleView::Styles.define UIView, backgroundColor: UIColor.redColor
view = @controller.add_view UIView
view.backgroundColor.should == UIColor.redColor
end
it "should add view with custom style" do
SimpleView::Styles.define :blue, backgroundColor: UIColor.blueColor
view = @controller.add_view UIView, styles: :blue
view.backgroundColor.should == UIColor.blueColor
end
it "should add view with multiple custom styles" do
SimpleView::Styles.define :blue, backgroundColor: UIColor.blueColor
SimpleView::Styles.define :alpha, alpha: 0.5
view = @controller.add_view UIView, styles: [:blue, :alpha]
view.backgroundColor.should == UIColor.blueColor
view.alpha.should == 0.5
end
it "should add view with custom style overriding default style" do
SimpleView::Styles.define UIView, backgroundColor: UIColor.redColor
SimpleView::Styles.define :blue, backgroundColor: UIColor.blueColor
view = @controller.add_view UIView, styles: :blue
view.backgroundColor.should == UIColor.blueColor
end
end
it "should add view to superview" do
super_view = UIView.alloc.init
@controller.setup super_view do
@controller.add_view UIView
end
super_view.subviews.first.class.should == UIView
end
end
describe "shorthand methods" do
before do
@controller = DummyController.new
end
it "should create UIActionSheet" do
@controller.action_sheet.class.should == UIActionSheet
end
it "should create UIActivityIndicatorView" do
@controller.activity_indicator_view.class.should == UIActivityIndicatorView
end
it "should create UIButton" do
@controller.button.class.should == UIRoundedRectButton
end
it "should create UIDatePicker" do
@controller.date_picker.class.should == UIDatePicker
end
it "should create UIImageView" do
@controller.image_view.class.should == UIImageView
end
it "should create UILabel" do
@controller.label.class.should == UILabel
end
it "should create UIPageControl" do
@controller.page_control.class.should == UIPageControl
end
it "should create UIPickerView" do
@controller.picker_view.class.should == UIPickerView
end
it "should create UIProgressView" do
@controller.progress_view.class.should == UIProgressView
end
it "should create UIScrollView" do
@controller.scroll_view.class.should == UIScrollView
end
it "should create UISearchBar" do
@controller.search_bar.class.should == UISearchBar
end
it "should create UISegmentedControl" do
@controller.segmented_control.class.should == UISegmentedControl
end
it "should create UISlider" do
@controller.slider.class.should == UISlider
end
it "should create UIStepper" do
@controller.stepper.class.should == UIStepper
end
it "should create UISwitch" do
@controller.switch.class.should == UISwitch
end
it "should create UITabBar" do
@controller.tab_bar.class.should == UITabBar
end
it "should create UITableView" do
@controller.table_view.class.should == UITableView
end
it "should create UITableViewCell" do
@controller.table_view_cell.class.should == UITableViewCell
end
it "should create UITextField" do
@controller.text_field.class.should == UITextField
end
it "should create UITextView" do
@controller.text_view.class.should == UITextView
end
it "should create UIToolbar" do
@controller.toolbar.class.should == UIToolbar
end
it "should create UIWebView" do
@controller.web_view.class.should == UIWebView
end
end
end