theextremeprogrammer / Succinct

UI tests at the speed of unit tests. Proper encapsulation. Architecture agnostic. Freedom to refactor.
MIT License
42 stars 7 forks source link

Support finding UISwitches within UICollectionView #52

Open theextremeprogrammer opened 4 years ago

tjarratt commented 4 years ago

Hey there, I'm interested in contributing some code for this. It seems like finding switches is already well covered here, but if there are other cases to handle, I'd be happy to contribute a PR.

Regarding collectionviews ... I'll take a look at writing a failing testcase for that and see if it's necessary. Based on how the UIViewController extensions look I'd expect to get things like UICollectionView or UIStackView for free, but it's certainly not a bad idea to have some testcases in place to cover that in case of future UIKit versions breaking previously-held assumptions.

theextremeprogrammer commented 4 years ago

Thanks @tjarratt! It'd be great to have your assistance with this! =)

The real "meat and potatoes" for Succinct is mostly happening inside of the UIView+findInSubviews.swift file where it cycles through the view hierarchy evaluating different conditions.

UICollectionView Support Currently there is some logic that also looks in the tableview if there is one - though it only checks header views and cells at the moment.

If logic were to be added for UICollectionView it would likely be included here in a similar fashion, but it would be great to have some tests around it for sure. (I have been TDD'ing all of the functionality in Succinct thus far. You can see how I've been simulating testing with UITableView objects for reference.)

There's a little bit of work that was done on collection views but it was to satisfy a very specific use case that I needed and hasn't been rolled into the above "findInSubviews" functionality yet.

UISwitch Support Switches are somewhat unique since to find them on their own wouldn't necessarily provide much value (not to mention there's really nothing to search by unless its getting a total count of UISwitch objects), so the use cases we've encountered with apps using Succinct was to have switches that are "co-located" with a UILabel. This infers that there's a UILabel and a UISwitch contained together in the same view, which we felt was a reasonable expectation to have. Another case we've tested was when a UISwitch was contained within a specific subview.

So far as I know, there are no cases where UISwitch objects have been tested inside a UITableView and since the UISwitch logic isn't able to make use of the above findInSubviews() functionality, the logic in here would most likely need to be adjusted to add table view / collection view support (sadly maintained separately from findInSubviews()). This is because the logic for finding UISwitches is dependent upon the parent or child or adjacent views as opposed to just evaluating a condition for the current view. (There may of course be a creative way around this that I'm not able to see.)

theextremeprogrammer commented 4 years ago

@tjarratt Based on our conversation, I've updated this issue to focus only on UICollectionViews and pulled out UITableView into a separate issue #59. 👍🏻