pivotal-legacy / PivotalCoreKit

Shared library and test code for iOS and macOS projects
http://pivotallabs.com
Other
168 stars 85 forks source link

Support "flat index" lookups on tables and collection views #99

Open briancroom opened 9 years ago

briancroom commented 9 years ago

Recently I have been noticing that many of my specs around table views and collection views are looking for cells at particular locations, however the full (row/item)+section pair is an implementation detail, causing the tests to break horribly if choose to refactor the way that the view controller is using sections internally. I have started using a category that allows looking up cells by an integer "flat index" instead, treating all cells as if they were part of a simple list.

Does this sound like a useful thing to add to PCK as a spec helper? I'd be glad to open a PR if there is any interest.

akitchen commented 9 years ago

Hey @pivotal-brian-croom

A PR for a helper here would be welcome of course. I'm neutral on this - I tend to use a combination of visibleCells and scrollToItem* but that's the kind of hackery you're trying to remove the need for. There are also going to be questions about getting cells through the table view vs. directly from the dataSource/delegate objects. My preference is to retrieve cells through the table view as it implicitly tests the delegate/dataSource wiring, but reasonable people can disagree here.

FYI, @jeffh 's Robot lib also has an API for this, https://github.com/jeffh/Robot#table-views , but we haven't been using Robot on many projects yet