Skip to content

Commit 1aeb1be

Browse files
committed
Fix UI tests in tvOS 15
1 parent 626d1ec commit 1aeb1be

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ jobs:
88
if: contains(github.event.head_commit.message, '[ci skip]') == false
99
env:
1010
BUNDLE_PATH: vendor/bundle
11-
DEVELOPER_DIR: /Applications/Xcode_11.7.app/Contents/Developer
1211
steps:
1312
- uses: actions/[email protected]
1413
- uses: actions/[email protected]

Example-tvOSUITests/ExampleUITests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ internal final class ExampleUITests: XCTestCase {
3939
func testInteractions() {
4040

4141
let tables = XCUIApplication().tables
42-
let existance = NSPredicate(format: "exists == true")
42+
let existence = NSPredicate(format: "exists == true")
4343
let hasFocus = NSPredicate(format: "hasFocus == true")
4444

4545
expectation(for: hasFocus, evaluatedWith: tables.cells.containing(.staticText, identifier: "Setting 1").element, handler: nil)
@@ -56,7 +56,7 @@ internal final class ExampleUITests: XCTestCase {
5656
waitForExpectations(timeout: 5, handler: nil)
5757
XCUIRemote.shared.press(.select)
5858

59-
expectation(for: hasFocus, evaluatedWith: app.alerts["Tap action"].otherElements["OK"], handler: nil)
59+
expectation(for: existence, evaluatedWith: app.alerts["Tap action"].buttons["OK"], handler: nil)
6060
waitForExpectations(timeout: 5, handler: nil)
6161
XCUIRemote.shared.press(.select)
6262

@@ -68,7 +68,7 @@ internal final class ExampleUITests: XCTestCase {
6868
waitForExpectations(timeout: 5, handler: nil)
6969
XCUIRemote.shared.press(.select)
7070

71-
expectation(for: existance, evaluatedWith: app.otherElements.containing(.staticText, identifier: "CellStyle.default").element, handler: nil)
71+
expectation(for: existence, evaluatedWith: app.otherElements.containing(.staticText, identifier: "CellStyle.default").element, handler: nil)
7272
waitForExpectations(timeout: 5, handler: nil)
7373
XCUIRemote.shared.press(.menu)
7474

@@ -80,7 +80,7 @@ internal final class ExampleUITests: XCTestCase {
8080
waitForExpectations(timeout: 5, handler: nil)
8181
XCUIRemote.shared.press(.select)
8282

83-
expectation(for: existance, evaluatedWith: app.otherElements.containing(.staticText, identifier: "CellStyle.subtitle").element, handler: nil)
83+
expectation(for: existence, evaluatedWith: app.otherElements.containing(.staticText, identifier: "CellStyle.subtitle").element, handler: nil)
8484
waitForExpectations(timeout: 5, handler: nil)
8585
XCUIRemote.shared.press(.menu)
8686

QuickTableViewController.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,9 +691,9 @@
691691
isa = PBXNativeTarget;
692692
buildConfigurationList = B54A243B2088816E00EEBA26 /* Build configuration list for PBXNativeTarget "QuickTableViewController-tvOS" */;
693693
buildPhases = (
694+
B54A24232088816D00EEBA26 /* Headers */,
694695
B54A24212088816D00EEBA26 /* Sources */,
695696
B54A24222088816D00EEBA26 /* Frameworks */,
696-
B54A24232088816D00EEBA26 /* Headers */,
697697
B54A24242088816D00EEBA26 /* Resources */,
698698
);
699699
buildRules = (

Source/QuickTableViewController.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ open class QuickTableViewController: UIViewController, UITableViewDataSource, UI
8484
tableView.estimatedRowHeight = 44
8585
tableView.dataSource = self
8686
tableView.delegate = self
87+
#if os(tvOS)
88+
tableView.remembersLastFocusedIndexPath = true
89+
#endif
8790
}
8891

8992
open override func viewWillAppear(_ animated: Bool) {
@@ -190,6 +193,18 @@ open class QuickTableViewController: UIViewController, UITableViewDataSource, UI
190193
}
191194
#endif
192195

196+
#if os(tvOS)
197+
private var currentFocusedIndexPath: IndexPath?
198+
199+
open override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) {
200+
currentFocusedIndexPath = (context.nextFocusedView as? UITableViewCell).flatMap(tableView.indexPath(for:))
201+
}
202+
203+
public func indexPathForPreferredFocusedView(in tableView: UITableView) -> IndexPath? {
204+
return currentFocusedIndexPath
205+
}
206+
#endif
207+
193208
}
194209

195210
// MARK: - SwitchCellDelegate

0 commit comments

Comments
 (0)