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 old UITableViewDelegate tap handlers in tapCell #72

Closed rgravina closed 3 years ago

rgravina commented 3 years ago

Currently Succinct calls this handler when tapCell is called.

tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none)

However, if you have implemented the older style table view handler method it is not called

    public override func selectRow(at indexPath: IndexPath?, animated: Bool, scrollPosition: UITableView.ScrollPosition) {
        // this gets called
    }

    public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        // this does not get called
    }
rgravina commented 3 years ago

Also credit to @kayleema for discovering this, not me :)

theextremeprogrammer commented 3 years ago

Thanks for this one, too @rgravina! And thanks to @kayleema as well - Kaylee please feel free to open issues and make PRs as well if you like! The more community support we can generate, the better Succinct can become! 😃

So far as I know, when I built the tapCell functionality, in order for it to work properly it was required to call both the selectRow method as well as the delegate method for didSelectRow, therefore the current implementation is as follows:

if let cell = tableView.dataSource?.tableView(tableView, cellForRowAt: indexPath) {
    if let _ = cell.findLabel(withExactText: searchText) {
        tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none)
        tableView.delegate?.tableView?(tableView, didSelectRowAt: indexPath)
    }
}

Therefore, I believe that the delegate method that you've mentioned above is already being called from tapCell. You can also verify the current code here: https://github.com/derekleerock/Succinct/blob/master/Succinct/UIViewController/UIViewController+UITableView.swift

Additionally, the documentation for this also describes the behavior:

/// - Note: This method both selects the row where matching text was found 
    as well as fires the tableview delegate method "didSelectRowAt:indexPath" 
    since this does not usually occur from a unit test.

I'd like to follow up by asking in what scenario did you find that Succinct couldn't tap the cell you wanted it to? Is it possible that there's something else causing the cell to not be tapped? Or is it possible that this is related to issue #71 where the cell's isUserInteractionEnabled is set to false?

In my experience, I've found some aspects of UITableView to be difficult to unit test, so knowing more about the scenario you have encountered will be helpful.

Tests for this portion of the code are located in the UIViewController_UITableViewSpec file, so there are some example tests there that also might be helpful to reference.

rgravina commented 3 years ago

I'm sorry, I think you're right and this wasn't the problem as the Succinct code clearly calls didSelectRowAt.... I'll take a look again tomorrow and see if I can replicate the problem that lead us to calling the delegate method ourselves. Sorry about that, I should have double checked before making an issue!

theextremeprogrammer commented 3 years ago

@rgravina I'm going to close this issue out as it seems that this is functionality that Succinct does support - but if you find otherwise please feel free to re-open (or open a new issue if you find something else).

Thanks! 🙇🏻‍♂️