Skip to content

Commit

Permalink
Merge pull request #620 from ryanlntn/unitize-specs
Browse files Browse the repository at this point in the history
Unitize functional screen specs
  • Loading branch information
jamonholmgren committed Jan 30, 2015
2 parents e177764 + abe428d commit 5e86255
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 143 deletions.
105 changes: 13 additions & 92 deletions spec/functional/func_screen_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,66 +10,6 @@ def controller
@controller.navigationController
end

it "should have a navigation bar" do
wait 0.5 do
view("Functional").should.be.kind_of UINavigationItemView
end
end

it "should allow a string title" do
views(UINavigationItemView).include?(UIImageView).should.not.be.true
end

it "should allow setting a left nav bar button" do
@controller.set_nav_bar_button :left, title: "Cool", action: :triggered_button
tap("Cool")
@controller.button_was_triggered.should.be.true
end

it "should allow setting a right nav bar button" do
@controller.set_nav_bar_button :right, title: "Cool2", action: :triggered_button
tap("Cool2")
@controller.button_was_triggered.should.be.true
end

it "should allow opening another screen in the same nav bar and have a back button that is operational" do
@controller.open BasicScreen

wait 0.5 do

view("Basic").should.be.kind_of UINavigationItemView
view("Functional").should.be.kind_of UINavigationItemButtonView

tap("Functional")
wait 0.5 do
view("Functional").should.be.kind_of UINavigationItemView
end

end

end

it "should push another screen with animation by default" do
basic = @controller.open BasicScreen
wait 0.5 do
basic.animation_ts.should.be > 0.2
end
end

it "should push another screen with animation when animated: true" do
basic = @controller.open BasicScreen, animated: true
wait 0.5 do
basic.animation_ts.should.be > 0.2
end
end

it "should push another screen without animation when animated: false" do
basic = @controller.open BasicScreen, animated: false
wait 0.5 do
basic.animation_ts.should.be < 0.2
end
end

it "should call the on_back method on the root controller when navigating back" do
presented_screen = PresentScreen.new
@controller.open presented_screen, animated: false
Expand All @@ -89,39 +29,21 @@ def controller
@controller.on_back_fired.should == true
end

it "should allow opening and closing a modal screen" do
@basic = BasicScreen.new(nav_bar: true)
wait 0.1 do
@controller.open_modal @basic

wait 0.6 do

view("Basic").should.be.kind_of UINavigationItemView
@basic.close

wait 0.6 do
@basic = nil
view("Functional").should.be.kind_of UINavigationItemView
end

end
end
end

it "should fire the will_present, on_present, will_dismiss, and on_dismiss_methods" do
@presented_screen = PresentScreen.new
@controller.open @presented_screen
wait 0.6 do
@controller.open @presented_screen, animated: false

wait 0.01 do
@presented_screen.will_present_fired.should == true
@presented_screen.on_present_fired.should == true

@presented_screen.will_dismiss_fired.should.not == true
@presented_screen.on_dismiss_fired.should.not == true

@presented_screen.reset
@presented_screen.close animated: false

@presented_screen.close
wait 0.6 do
wait 0.01 do
@presented_screen.will_dismiss_fired.should == true
@presented_screen.on_dismiss_fired.should == true

Expand All @@ -136,21 +58,20 @@ def controller
it "should pop to the root view controller" do
@root_vc = @controller.navigationController.visibleViewController
@controller.navigationController.viewControllers.count.should == 1
@controller.open BasicScreen.new
wait 0.6 do
@controller.open BasicScreen.new
wait 0.6 do
@controller.open BasicScreen.new
wait 0.6 do
@controller.open BasicScreen.new, animated: false
wait 0.01 do
@controller.open BasicScreen.new, animated: false
wait 0.01 do
@controller.open BasicScreen.new, animated: false
wait 0.01 do
@controller.navigationController.viewControllers.count.should == 4
@controller.close to_screen: :root
wait 0.6 do
@controller.close to_screen: :root, animated: false
wait 0.01 do
@controller.navigationController.viewControllers.count.should == 1
@controller.navigationController.topViewController.should == @root_vc
end
end
end
end
end

end
2 changes: 1 addition & 1 deletion spec/functional/func_split_screen_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def controller
it "should override the default swipe action, that reveals the menu" do
rotate_device to: :portrait, button: :bottom

@alt_controller = @app.open_split_screen @master, @detail, swipe: false
@alt_controller = @app.open_split_screen @master, @detail, swipe: false, animated: false
@app.home_screen.presentsWithGesture.should == false
end
end
Expand Down
98 changes: 49 additions & 49 deletions spec/functional/func_table_screen_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,22 @@ def table_label_class
table_screen.navigationController.should.be.kind_of(UINavigationController)
end

it "should increment the tap counter on tap" do
tap("Increment")
table_screen.tap_counter.should == 3
end
unless ENV['TRAVIS']
it "should increment the tap counter on tap" do
tap("Increment")
table_screen.tap_counter.should == 3
end

it "should add a new table cell on tap" do
tap("Add New Row")
view("Dynamically Added").class.to_s.should == table_label_class
end
it "should add a new table cell on tap" do
tap("Add New Row")
view("Dynamically Added").class.to_s.should == table_label_class
end

it "should do nothing when no action specified" do
tap("Just another blank row")
table_screen.should == table_screen
end
it "should do nothing when no action specified" do
tap("Just another blank row")
table_screen.should == table_screen
end

unless ENV['TRAVIS']
it "should increment the tap counter by one on tap" do
tap("Increment One")
table_screen.tap_counter.should == 1
Expand All @@ -48,53 +48,53 @@ def table_label_class
it "should delete the specified row from the table view on tap" do
table_screen.tableView(table_screen.tableView, numberOfRowsInSection:0).should == 7
tap("Delete the row below")
wait 0.11 do
wait 0.01 do
table_screen.tableView(table_screen.tableView, numberOfRowsInSection:0).should == 6
end
end
end

it "should delete the specified row from the table view on tap with an animation" do
table_screen.tableView(table_screen.tableView, numberOfRowsInSection:0).should == 7
tap("Delete the row below with an animation")
wait 0.11 do
table_screen.tableView(table_screen.tableView, numberOfRowsInSection:0).should == 6
it "should delete the specified row from the table view on tap with an animation" do
table_screen.tableView(table_screen.tableView, numberOfRowsInSection:0).should == 7
tap("Delete the row below with an animation")
wait 0.01 do
table_screen.tableView(table_screen.tableView, numberOfRowsInSection:0).should == 6
end
end
end

# TODO: Why is it so complicated to find the delete button??
it "should use editing_style to delete the table row" do
table_screen.tableView(table_screen.tableView, numberOfRowsInSection:0).should == 7
table_screen.cell_was_deleted.should != true
flick("Just another deletable blank row", to: :left)

wait 0.11 do
# Tap the delete button
view('Just another deletable blank row').superview.superview.subviews.each do |subview|
if subview.class.to_s == confirmation_class
tap subview
wait 0.11 do
table_screen.tableView(table_screen.tableView, numberOfRowsInSection:0).should == 6
table_screen.cell_was_deleted.should == true
# TODO: Why is it so complicated to find the delete button??
it "should use editing_style to delete the table row" do
table_screen.tableView(table_screen.tableView, numberOfRowsInSection:0).should == 7
table_screen.cell_was_deleted.should != true
flick("Just another deletable blank row", to: :left)

wait 0.01 do
# Tap the delete button
view('Just another deletable blank row').superview.superview.subviews.each do |subview|
if subview.class.to_s == confirmation_class
tap subview
wait 0.01 do
table_screen.tableView(table_screen.tableView, numberOfRowsInSection:0).should == 6
table_screen.cell_was_deleted.should == true
end
end
end
end
end
end

it "should not allow deleting if on_cell_delete returns `false`" do
table_screen.tableView(table_screen.tableView, numberOfRowsInSection:0).should == 7
table_screen.cell_was_deleted.should != true
flick("A non-deletable blank row", to: :left)

wait 0.11 do
# Tap the delete button
view('A non-deletable blank row').superview.superview.subviews.each do |subview|
if subview.class == confirmation_class
tap subview
wait 0.11 do
table_screen.tableView(table_screen.tableView, numberOfRowsInSection:0).should == 7
table_screen.cell_was_deleted.should != false
it "should not allow deleting if on_cell_delete returns `false`" do
table_screen.tableView(table_screen.tableView, numberOfRowsInSection:0).should == 7
table_screen.cell_was_deleted.should != true
flick("A non-deletable blank row", to: :left)

wait 0.01 do
# Tap the delete button
view('A non-deletable blank row').superview.superview.subviews.each do |subview|
if subview.class == confirmation_class
tap subview
wait 0.01 do
table_screen.tableView(table_screen.tableView, numberOfRowsInSection:0).should == 7
table_screen.cell_was_deleted.should != false
end
end
end
end
Expand Down
49 changes: 48 additions & 1 deletion spec/unit/screen_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
end

it "should store title" do
HomeScreen.title.should == 'Home'
HomeScreen.title.should == "Home"
end

it "should set default title on new instances" do
Expand Down Expand Up @@ -74,6 +74,42 @@
@screen.should_autorotate.should == true
end

it "should allow opening and closing a modal screen" do
parent_screen = BasicScreen.new(nav_bar: true)
parent_screen.mock!(:"presentViewController:animated:completion:") do |controller, animated, completion|
controller.should == @screen.navigationController
end
parent_screen.open_modal @screen
parent_screen.mock!(:"dismissViewControllerAnimated:completion:") do |animated, completion|
animated.should == true
end
@screen.close
end

it "should push another screen with animation by default" do
parent_screen = BasicScreen.new(nav_bar: true)
parent_screen.navigationController.mock!(:"pushViewController:animated:") do |controller, animated|
animated.should == true
end
parent_screen.open @screen
end

it "should push another screen with animation when animated: true" do
parent_screen = BasicScreen.new(nav_bar: true)
parent_screen.navigationController.mock!(:"pushViewController:animated:") do |controller, animated|
animated.should == true
end
parent_screen.open @screen, animated: true
end

it "should push another screen without animation when animated: false" do
parent_screen = BasicScreen.new(nav_bar: true)
parent_screen.navigationController.mock!(:"pushViewController:animated:") do |controller, animated|
animated.should == false
end
parent_screen.open @screen, animated: false
end

# Issue https://github.com/clearsightstudio/ProMotion/issues/109
it "#should_autorotate should fire when shouldAutorotate fires when in a navigation bar" do
parent_screen = BasicScreen.new(nav_bar: true)
Expand Down Expand Up @@ -153,6 +189,10 @@

describe "navigation controller behavior" do

it "should have a navigation bar" do
@screen.navigationController.should.be.kind_of UINavigationController
end

it "should let the instance set the nav_controller" do
screen = HomeScreen.new nav_bar: true, nav_controller: CustomNavigationController
screen.on_load
Expand All @@ -175,6 +215,13 @@
@screen.navigationItem.leftBarButtonItem.should.not == nil
end

it "should set the given action on a left bar button item" do
@screen.navigationItem.leftBarButtonItem.action.should == :save_something
end

it "should set the given action on a right bar button item" do
@screen.navigationItem.rightBarButtonItem.action.should == :return_to_some_other_screen
end
end

describe "bar button behavior" do
Expand Down

0 comments on commit 5e86255

Please sign in to comment.