Skip to content

Commit

Permalink
Fix view visibility check failing on cells in scrolled table view (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tunous authored Aug 1, 2021
1 parent 4175566 commit 6c9bf50
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Sources/Hammer/Utilties/Subviews.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ extension EventGenerator {
return currentView == self.window
}

guard superview.bounds.isVisible(view.frame, visibility: visibility) else {
let adjustedBounds = view.convert(view.bounds, to: superview)
guard superview.bounds.isVisible(adjustedBounds, visibility: visibility) else {
return false
}

Expand Down
46 changes: 46 additions & 0 deletions Tests/HammerTests/TableViewControllerTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// ScrollableViewControllerTests.swift
// HammerTests
//
// Created by Łukasz Rutkowski on 28/07/2021.
//

import Foundation
import Hammer
import XCTest

final class TableViewControllerTests: XCTestCase {

func testFindViewAfterScrolling() throws{
let viewController = TableViewController()
let eventGenerator = try EventGenerator(viewController: viewController)
try eventGenerator.waitUntilVisible("accessibilityId_0-1", timeout: 1)

viewController.tableView.scrollToRow(at: IndexPath(row: 40, section: 0), at: .bottom, animated: false)
XCTAssertTrue(eventGenerator.viewIsVisible("accessibilityId_0-35"))
}
}

final class TableViewController: UITableViewController {

override func viewDidLoad() {
super.viewDidLoad()
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "TableViewCell")
}

override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 50
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell", for: indexPath)
let id = "\(indexPath.section)-\(indexPath.row)"
cell.textLabel?.text = "title_\(id)"
cell.accessibilityIdentifier = "accessibilityId_\(id)"
return cell
}
}

0 comments on commit 6c9bf50

Please sign in to comment.