Merge pull request #130 from squidpunch/moar-tests

Adds tests; fixes styler bug
This commit is contained in:
Gant Laborde
2014-10-19 19:57:01 -05:00
4 changed files with 90 additions and 25 deletions

View File

@@ -297,7 +297,7 @@ module RubyMotionQuery
@view.setEnabled value
end
def enabled
@view.enabled
@view.isEnabled
end
def scale=(amount)

View File

@@ -84,11 +84,10 @@ describe 'app' do
controller.dismissViewControllerAnimated(false, completion: nil)
end
# Disabling, this works, but isn't working in tests, TODO, fix
#it 'should return current_view_controller when root controller is UINavigationController with multiple controllers' do
#cur = rmq.app.current_view_controller
#cur.class.should == MainController
#end
it 'should return current_view_controller when root controller is UINavigationController with multiple controllers' do
cur = rmq.app.current_view_controller
cur.class.should == MainController
end
it 'should return current_view_controller when root controller is UITabController with multiple controllers' do
tabbar = UITabBarController.alloc.init

View File

@@ -14,15 +14,20 @@ describe 'font' do
@rmq.font.family_list.grep(/Helvetica/).length.should > 0
end
it 'should return a list of fonts for one family ' do
it 'should return a list of fonts for one family' do
@rmq.font.for_family('Arial').grep(/Arial/).length.should > 0
end
it 'should return a system fone given a size' do
it 'should return a system font given a size' do
@rmq.font.system(11).is_a?(UIFont).should == true
end
#TODO test font_with_name
#TODO test named fonts
it 'should return font with name' do
@rmq.font.with_name('American Typewriter', 11).is_a?(UIFont).should == true
end
it "should return fonts that have been named" do
@rmq.font.add_named('awesome_font', 'American Typewriter', 12)
@rmq.font.awesome_font.is_a?(UIFont).should.be.true
end
end

View File

@@ -42,24 +42,15 @@ class SyleSheetForUIViewStylerTests < RubyMotionQuery::Stylesheet
st.center = st.superview.center
st.center_x = 50
st.center_y = 60
st.enabled = true
st.enabled = false
st.hidden = false
st.z_position = 66
st.opaque = false
st.clips_to_bounds = false
st.hidden = true
st.content_mode = UIViewContentModeBottomLeft
st.background_color = color.red
# TODO test background_image
st.scale = 1.5
st.rotation = 45
st.tint_color = color.blue
st.corner_radius = 5
st.alpha = 1.0
end
end
shared 'styler' do
@@ -110,14 +101,33 @@ shared 'styler' do
view.layer.zPosition.should == 99
end
# TODO, test super_height and super_width
it "should return the super height and width" do
super_view = @vc.rmq.append(UIView).style { |st| st.frame = {h: 10, w: 20 } }.get
rmq(super_view).append(@view_klass, :ui_view_kitchen_sink).style do |st|
@super_height = st.super_height
@super_width = st.super_width
end
@super_height.should == 10
@super_width.should == 20
end
it 'should apply a style with every UIViewStyler wrapper method' do
view = @vc.rmq.append(@view_klass, :ui_view_kitchen_sink).get
view = @vc.rmq.append!(@view_klass, :ui_view_kitchen_sink)
view.tap do |v|
# TODO check all the values set in ui_view_kitchen_sink
1.should == 1
view.backgroundColor.should == rmq.color.red
view.isHidden.should.be.true
view.tintColor.should == rmq.color.blue
view.layer.cornerRadius.should == 5
view.center.should == CGPointMake(50, 60)
view.center.x.should == 50
view.center.y.should == 60
view.isEnabled.should.be.false
view.layer.zPosition.should == 66
view.contentMode.should == UIViewContentModeBottomLeft
end
end
end
@@ -196,6 +206,12 @@ describe 'ui_view_styler' do
view.accessibilityLabel.should == value
end
it "should set the background image properly" do
image = rmq.image.resource('logo')
view = @vc.rmq.append(UIView).style { |st| st.background_image = image }.get
view.backgroundColor.should == UIColor.colorWithPatternImage(image)
end
it "should set the border width" do
view = @vc.rmq.append(UIView).style { |st| st.border_width= 12}.get
view.layer.borderWidth.should == 12
@@ -249,4 +265,49 @@ describe 'ui_view_styler' do
components[2].to_i.should == 1
components[3].to_i.should == 1
end
it "should set the value for alpha" do
view = @vc.rmq.append!(@view_klass, :ui_view_kitchen_sink)
view.alpha.should == 1.0
end
it "should set the value for opaque" do
view = @vc.rmq.append!(@view_klass, :ui_view_kitchen_sink)
view.layer.isOpaque.should.be.false
end
it "should set the value for clip to bounds" do
view = @vc.rmq.append(@view_klass).style do |st|
st.clips_to_bounds = false
end.get
view.clipsToBounds.should.be.false
end
it "should set the value for scale" do
view = @vc.rmq.append(@view_klass).style do |st|
st.scale = 1.5
end.get
view.transform.should == CGAffineTransformMakeScale(1.5, 1.5)
end
it "should set the value for rotation" do
view = @vc.rmq.append(@view_klass).style do |st|
st.rotation = 45
end.get
radians = 45 * Math::PI / 180
view.transform.should == CGAffineTransformMakeRotation(radians)
end
it "should return the correct value of enabled from the styler" do
view = UIView.alloc.init
view.setEnabled(false)
rmq(view).style { |st| @value = st.enabled }
@value.should.be.false
end
end