From a937e804ebc059c9d4c5fe0d8e2a4cc986da24a5 Mon Sep 17 00:00:00 2001 From: Mark Rickert Date: Sat, 1 Jun 2013 12:10:57 -0400 Subject: [PATCH] Working functional test for deleting a row in a table view --- spec/functional/func_table_screen_spec.rb | 26 ++++++++++++++--------- spec/helpers/table_screen.rb | 6 ++++++ spec/unit/tables/table_screen_spec.rb | 2 +- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/spec/functional/func_table_screen_spec.rb b/spec/functional/func_table_screen_spec.rb index c68a047..200158b 100644 --- a/spec/functional/func_table_screen_spec.rb +++ b/spec/functional/func_table_screen_spec.rb @@ -1,6 +1,6 @@ describe "ProMotion::TestTableScreen functionality" do tests PM::TestTableScreen - + # Override controller to properly instantiate def controller rotate_device to: :portrait, button: :bottom @@ -8,33 +8,39 @@ describe "ProMotion::TestTableScreen functionality" do @controller.on_load @controller.main_controller end - + after do @controller = nil end - + it "should have a navigation bar" do @controller.navigationController.should.be.kind_of(UINavigationController) end - + it "should increment the tap counter on tap" do tap("Increment") @controller.tap_counter.should == 3 end - + it "should add a new table cell on tap" do tap("Add New Row") view("Dynamically Added").class.should == UILabel end - + it "should do nothing when no action specified" do tap("Just another blank row") @controller.should == @controller end - - it "should increment the tap counter by one on tap" do + + it "should increment the tap counter by one on tap" do tap("Increment One") @controller.tap_counter.should == 1 end - -end \ No newline at end of file + + it "should delete the specified row from the table view on tap" do + @controller.tableView(@controller.tableView, numberOfRowsInSection:0).should == 4 + tap("Delete the row below") + @controller.tableView(@controller.tableView, numberOfRowsInSection:0).should == 3 + end + +end diff --git a/spec/helpers/table_screen.rb b/spec/helpers/table_screen.rb index 2a7ddba..906e341 100644 --- a/spec/helpers/table_screen.rb +++ b/spec/helpers/table_screen.rb @@ -14,6 +14,7 @@ class TestTableScreen < ProMotion::SectionedTableScreen cells: [ { title: "Increment", action: :increment_counter_by, arguments: { number: 3 } }, { title: "Add New Row", action: :add_tableview_row, accessibilityLabel: "Add New Row" }, + { title: "Delete the row below", action: :delete_row, arguments: {section: 0, row:3 }, accessibilityLabel: "Delete the row below" }, { title: "Just another blank row" } ] }, { @@ -44,6 +45,11 @@ class TestTableScreen < ProMotion::SectionedTableScreen update_table_data end + def delete_row(args={}) + @data[args[:section]][:cells].delete_at args[:row] + update_table_data +end + def increment_counter(args={}) @tap_counter += 1 end diff --git a/spec/unit/tables/table_screen_spec.rb b/spec/unit/tables/table_screen_spec.rb index fdf6944..a2e1b02 100644 --- a/spec/unit/tables/table_screen_spec.rb +++ b/spec/unit/tables/table_screen_spec.rb @@ -12,7 +12,7 @@ describe "table screens" do end it "should have proper cell numbers" do - @screen.tableView(@screen.tableView, numberOfRowsInSection:0).should == 3 + @screen.tableView(@screen.tableView, numberOfRowsInSection:0).should == 4 @screen.tableView(@screen.tableView, numberOfRowsInSection:1).should == 2 @screen.tableView(@screen.tableView, numberOfRowsInSection:2).should == 4 end