Passing tests for new accessoryview paradigm.

This commit is contained in:
Mark Rickert
2013-06-08 12:11:26 -04:00
parent c11c342398
commit e3d1b37063
4 changed files with 53 additions and 38 deletions

View File

@@ -49,4 +49,31 @@ describe "ProMotion::TestTableScreen functionality" do
@controller.tableView(@controller.tableView, numberOfRowsInSection:0).should == 5
end
it "should call a method when the switch is flipped" do
@controller.scroll_to_bottom
wait 0.5 do
tap "switch_1"
@controller.tap_counter.should == 1
end
end
it "should call the method with arguments when the switch is flipped" do
@controller.scroll_to_bottom
wait 0.5 do
tap "switch_2"
@controller.tap_counter.should == 3
end
end
it "should call the method with arguments when the switch is flipped and when the cell is tapped" do
@controller.scroll_to_bottom
wait 0.5 do
tap "switch_3"
@controller.tap_counter.should == 3
tap "Switch With Cell Tap, Switch Action And Parameters"
@controller.tap_counter.should == 13
end
end
end

View File

@@ -1,20 +1,22 @@
class TestTableScreen < ProMotion::SectionedTableScreen
attr_accessor :tap_counter
def promotion_table_data
@promotion_table_data
end
def on_load
@tap_counter ||= 0
self.tap_counter = 0
end
def table_data
@data ||= [{
title: "Your Account",
cells: [
{ title: "Increment", action: :increment_counter_by, arguments: { number: 3 } },
{ title: "Increment", action: :increment_counter_by, arguments: {number: 3} },
{ title: "Add New Row", action: :add_tableview_row },
{ title: "Delete the row below", action: :delete_cell, arguments: {section: 0, row:3 } },
{ title: "Delete the row below", action: :delete_cell, arguments: {section: 0, row:3} },
{ title: "Just another blank row" },
{ title: "Delete the row below with an animation", action: :delete_cell, arguments: {animated: true, section: 0, row:5 } },
{ title: "Just another blank row" }
@@ -36,45 +38,30 @@ class TestTableScreen < ProMotion::SectionedTableScreen
}, {
title: "Cell Accessory Tests",
cells: [{
title: "Basic Switch",
accessory: :switch
}, {
title: "Switch With Action",
accessory: {
view: :switch,
action: :tap_counter
action: :increment_counter,
accessibility_label: "switch_1"
} ,
}, {
title: "Switch With Action And Parameters",
accessory: {
view: :switch,
action: :increment_counter_by,
arguments: { number: 3 }
arguments: { number: 3 },
accessibility_label: "switch_2"
} ,
}, {
title: "Custom View",
accessory: custom_accessory_view
}, {
title: "Custom View With Action",
accessory:{
view: custom_accessory_view,
action: :tap_counter
},
}, {
title: "Custom View With Action And Parameters",
accessory: {
view: :switch,
action: :increment_counter_by,
arguments: { number: 3 }
},
}, {
title: "Switch With Cell Tap, Switch Action And Parameters",
accessory:{
view: :switch,
action: :increment_counter_by,
arguments: { number: 3 },
accessibility_label: "switch_3"
},
action: :increment_counter_by, accessory_arguments: { number: 10 }
action: :increment_counter_by,
arguments: { number: 10 }
}]
}]
end
@@ -99,16 +86,12 @@ class TestTableScreen < ProMotion::SectionedTableScreen
end
end
def increment_counter(args={})
@tap_counter += 1
def increment_counter
self.tap_counter = self.tap_counter + 1
end
def increment_counter_by(args={})
@tap_counter = @tap_counter + args[:number]
end
def tap_counter
@tap_counter
self.tap_counter = self.tap_counter + args[:number]
end
def custom_accessory_view
@@ -117,4 +100,11 @@ class TestTableScreen < ProMotion::SectionedTableScreen
}
end
def scroll_to_bottom
if table_view.contentSize.height > table_view.frame.size.height
offset = CGPointMake(0, table_view.contentSize.height - table_view.frame.size.height)
table_view.setContentOffset(offset, animated:false)
end
end
end

View File

@@ -15,6 +15,7 @@ describe "table screens" do
@screen.tableView(@screen.tableView, numberOfRowsInSection:0).should == 6
@screen.tableView(@screen.tableView, numberOfRowsInSection:1).should == 2
@screen.tableView(@screen.tableView, numberOfRowsInSection:2).should == 4
@screen.tableView(@screen.tableView, numberOfRowsInSection:3).should == 3
end
it "should return a UITableViewCell" do
@@ -30,10 +31,8 @@ describe "table screens" do
end
it "should display all images properly no matter how they were initialized" do
section = @screen.promotion_table_data.sections.count - 1 # All the cells we want to test are in the last section
@screen.tableView(@screen.tableView, numberOfRowsInSection:section).times do |i|
index_path = NSIndexPath.indexPathForRow(i, inSection: section)
@screen.tableView(@screen.tableView, numberOfRowsInSection:2).times do |i|
index_path = NSIndexPath.indexPathForRow(i, inSection:2)
@screen.tableView(@screen.tableView, cellForRowAtIndexPath: index_path).imageView.should.be.kind_of UIImageView

View File

@@ -13,8 +13,7 @@ describe "PM::TableViewCellModule" do
layer: { masks_to_bounds: true },
background_color: UIColor.redColor,
selection_style: UITableViewCellSelectionStyleGray,
accessory: :switch, # currently only :switch is supported
accessory_checked: true, # whether it's "checked" or not
accessory:{view: :switch, value: true}, # currently only :switch is supported
image: { image: UIImage.imageNamed("list"), radius: 15 },
subviews: [ UIView.alloc.initWithFrame(CGRectZero), UILabel.alloc.initWithFrame(CGRectZero) ] # arbitrary views added to the cell
}