Skip to content

Commit

Permalink
Adds tests for prepare_for_reuse and ensures that it's called before …
Browse files Browse the repository at this point in the history
…on_reuse
  • Loading branch information
markrickert committed May 12, 2015
1 parent b41f005 commit 94aef5d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
8 changes: 7 additions & 1 deletion app/test_screens/test_mini_table_screen.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
class TestCell < PM::TableViewCell
attr_accessor :on_reuse_fired
attr_accessor :on_reuse_fired, :prepare_for_reuse_fired, :on_reuse_time, :prepare_for_reuse_time

def on_reuse
self.on_reuse_fired = true
self.on_reuse_time = Time.now
end

def prepare_for_reuse
self.prepare_for_reuse_fired = true
self.prepare_for_reuse_time = Time.now
end
end

Expand Down
28 changes: 27 additions & 1 deletion spec/functional/func_table_screen_cell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,33 @@ def controller
end
end

end
it "no cells have fired prepare_for_reuse before scrolling" do
ip = NSIndexPath.indexPathForRow(0, inSection: 0)
cell = table_screen.tableView(table_screen.table_view, cellForRowAtIndexPath: ip)
cell.prepare_for_reuse_fired.should.not == true
end

it "cell has fired prepare_for_reuse after scrolling" do
ip = NSIndexPath.indexPathForRow(10, inSection: 0)
table_screen.tableView.scrollToRowAtIndexPath(ip, atScrollPosition: UITableViewScrollPositionTop, animated: false)
wait 0.001 do
ip = NSIndexPath.indexPathForRow(0, inSection: 0)
table_screen.tableView.scrollToRowAtIndexPath(ip, atScrollPosition: UITableViewScrollPositionTop, animated: false)

cell = views(TestCell).first
cell.prepare_for_reuse_fired.should == true
end
end

it "should fire prepare_for_reuse before on_reuse" do
ip = NSIndexPath.indexPathForRow(10, inSection: 0)
table_screen.tableView.scrollToRowAtIndexPath(ip, atScrollPosition: UITableViewScrollPositionTop, animated: false)
wait 0.001 do
ip = NSIndexPath.indexPathForRow(0, inSection: 0)
table_screen.tableView.scrollToRowAtIndexPath(ip, atScrollPosition: UITableViewScrollPositionTop, animated: false)

cell = views(TestCell).first
cell.prepare_for_reuse_time.should < cell.on_reuse_time
end
end
end

0 comments on commit 94aef5d

Please sign in to comment.