spec/unit/screen_helpers_spec.rb in ProMotion-1.0.4 vs spec/unit/screen_helpers_spec.rb in ProMotion-1.1.0.rc1
- old
+ new
@@ -16,22 +16,44 @@
it "should set attributes before adding a subview" do
@screen.add @subview, backgroundColor: UIColor.redColor
@screen.view.subviews.first.backgroundColor.should == UIColor.redColor
end
+ it "should set attributes using a symbol" do
+ @screen.add @subview, :subview_styles
+ @screen.view.subviews.first.backgroundColor.should == UIColor.greenColor
+ end
+
it "should let you remove a view" do
@screen.view.addSubview @subview
@screen.remove @subview
@screen.view.subviews.count.should == 0
end
+ it "should let you remove an array of subviews" do
+ subview_a = UIView.alloc.initWithFrame CGRectZero
+ subview_b = UIView.alloc.initWithFrame CGRectZero
+ @screen.view.addSubview subview_a
+ @screen.view.addSubview subview_b
+ @screen.remove [subview_a, subview_b]
+ @screen.view.subviews.count.should == 0
+ end
+
it "should add a subview to another element" do
sub_subview = UIView.alloc.initWithFrame CGRectZero
@screen.add_to @subview, sub_subview
@subview.subviews.include?(sub_subview).should == true
end
+ it "should add an array of subviews to another element" do
+ sub_subview_a = UIView.alloc.initWithFrame CGRectZero
+ sub_subview_b = UIView.alloc.initWithFrame CGRectZero
+ @screen.add_to @subview, [sub_subview_a, sub_subview_b]
+ @subview.subviews.include?(sub_subview_a).should == true
+ @subview.subviews.include?(sub_subview_b).should == true
+ end
+
it "should add a subview to another element with attributes" do
sub_subview = UIView.alloc.initWithFrame CGRectZero
@screen.add_to @subview, sub_subview, { backgroundColor: UIColor.redColor }
@subview.subviews.last.backgroundColor.should == UIColor.redColor
end
@@ -42,42 +64,31 @@
before do
@screen = HomeScreen.new(nav_bar: true)
end
- it "should add a left nav bar button" do
- @screen.set_nav_bar_button :left, title: "Save", action: :save_something, type: UIBarButtonItemStyleDone
- @screen.navigationItem.leftBarButtonItem.class.should == UIBarButtonItem
- end
- it "should add a right nav bar button" do
- @screen.set_nav_bar_button :right, title: "Cancel", action: :return_to_some_other_screen, type: UIBarButtonItemStylePlain
- @screen.navigationItem.rightBarButtonItem.class.should == UIBarButtonItem
- end
+ [:left, :right, :back].each do |placement|
+ buttonItemMethod = :"#{placement}BarButtonItem"
- it "should add an image right nav bar button" do
- image = UIImage.imageNamed("list.png")
- @screen.set_nav_bar_button :right, image: image, action: :return_to_some_other_screen, type: UIBarButtonItemStylePlain
- @screen.navigationItem.rightBarButtonItem.image.class.should == UIImage
- @screen.navigationItem.rightBarButtonItem.image.should == image
- end
+ it "should add a #{placement} nav bar button" do
+ @screen.set_nav_bar_button placement, title: "Save", action: :save_something, type: UIBarButtonItemStyleDone
+ @screen.navigationItem.send(buttonItemMethod).class.should == UIBarButtonItem
+ end
- it "should add an image left nav bar button" do
- image = UIImage.imageNamed("list.png")
- @screen.set_nav_bar_button :left, image: image, action: :return_to_some_other_screen, type: UIBarButtonItemStylePlain
- @screen.navigationItem.leftBarButtonItem.image.class.should == UIImage
- @screen.navigationItem.leftBarButtonItem.image.should == image
- end
+ it "should add an image #{placement} nav bar button" do
+ image = UIImage.imageNamed("list.png")
+ @screen.set_nav_bar_button placement, image: image, action: :return_to_some_other_screen, type: UIBarButtonItemStylePlain
+ @screen.navigationItem.send(buttonItemMethod).image.class.should == UIImage
+ @screen.navigationItem.send(buttonItemMethod).image.should == image
+ end
- it "should add a left UIBarButtonItem" do
- @screen.set_nav_bar_button :left, system_item: :edit
- @screen.navigationItem.leftBarButtonItem.class.should == UIBarButtonItem
- end
+ it "should add a #{placement} UIBarButtonItem" do
+ @screen.set_nav_bar_button placement, system_item: :add
+ @screen.navigationItem.send(buttonItemMethod).class.should == UIBarButtonItem
+ end
- it "should add a right UIBarButtonItem" do
- @screen.set_nav_bar_button :right, system_item: :add
- @screen.navigationItem.rightBarButtonItem.class.should == UIBarButtonItem
end
end
describe "screen navigation" do
@@ -86,13 +97,13 @@
@screen.on_load
@second_vc = UIViewController.alloc.initWithNibName(nil, bundle:nil)
end
it "#push_view_controller should use the default navigation controller if not provided" do
- vcs = @screen.navigation_controller.viewControllers
+ vcs = @screen.navigationController.viewControllers
@screen.push_view_controller @second_vc
- @screen.navigation_controller.viewControllers.count.should == vcs.count + 1
+ @screen.navigationController.viewControllers.count.should == vcs.count + 1
end
it "#push_view_controller should use a provided navigation controller" do
second_nav_controller = UINavigationController.alloc.initWithRootViewController @screen
@screen.push_view_controller @second_vc, second_nav_controller
@@ -151,11 +162,11 @@
animated.should == true
end
screen = @screen.open BasicScreen, modal: true
screen.should.be.kind_of BasicScreen
end
-
+
it "should present a modal screen if open_modal is used" do
@screen.mock!(:present_modal_view_controller) do |screen, animated|
screen.should.be.instance_of BasicScreen
animated.should == true
end
@@ -183,22 +194,20 @@
screen = @screen.open BasicScreen, in_tab: 'my_tab'
screen.should.be.kind_of BasicScreen
end
it "should pop onto navigation controller if current screen is on nav stack already" do
- @screen.mock!(:push_view_controller) { |vc| vc.should.be.instance_of BasicScreen }
+ @screen.mock!(:push_view_controller) { |vc, n, a| vc.should.be.instance_of BasicScreen }
screen = @screen.open BasicScreen
screen.should.be.kind_of BasicScreen
end
-
+
it "should ignore its own navigation controller if current screen has a navigation controller" do
basic = BasicScreen.new(nav_bar: true) # creates a dangling nav_bar that will be discarded.
screen = @screen.open basic
screen.should.be.kind_of BasicScreen
basic.navigationController.should == @screen.navigationController
- basic.navigation_controller.should == @screen.navigationController
- @screen.navigation_controller.should == @screen.navigationController
end
it "should open the provided view controller as root view if no other conditions are met" do
parent_screen = HomeScreen.new
new_screen = BasicScreen.new
@@ -250,10 +259,10 @@
@screen.send(:close, animated: false)
end
it "#close should pop from the navigation controller" do
- @screen.navigation_controller.mock!(:popViewControllerAnimated) { |animated| animated.should == true }
+ @screen.navigationController.mock!(:popViewControllerAnimated) { |animated| animated.should == true }
@screen.close
end
it "#send_on_return shouldn't pass args to parent screen if there are none" do
parent_screen = HomeScreen.new