Skip to content

Commit 582bd95

Browse files
author
mojganii
committed
Fix off-screen element detection issue
1 parent 074f525 commit 582bd95

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

ios/MullvadVPN/View controllers/VPNSettings/VPNSettingsDataSource.swift

+9
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ final class VPNSettingsDataSource: UITableViewDiffableDataSource<
457457
header.accessibilityIdentifier = .wireGuardPortsCell
458458
header.titleLabel.text = title
459459
header.accessibilityCustomActionName = title
460+
header.isExpanded = isExpanded(.wireGuardPorts)
460461
header.infoButtonHandler = { [weak self] in
461462
if let self {
462463
self.delegate?.showInfo(for: .wireGuardPorts)
@@ -500,6 +501,7 @@ final class VPNSettingsDataSource: UITableViewDiffableDataSource<
500501
header.accessibilityIdentifier = .wireGuardObfuscationCell
501502
header.titleLabel.text = title
502503
header.accessibilityCustomActionName = title
504+
header.isExpanded = isExpanded(.wireGuardObfuscation)
503505
header.didCollapseHandler = { [weak self] header in
504506
guard let self else { return }
505507

@@ -529,6 +531,7 @@ final class VPNSettingsDataSource: UITableViewDiffableDataSource<
529531
header.accessibilityIdentifier = .udpOverTCPPortCell
530532
header.titleLabel.text = title
531533
header.accessibilityCustomActionName = title
534+
header.isExpanded = isExpanded(.wireGuardObfuscationPort)
532535
header.didCollapseHandler = { [weak self] header in
533536
guard let self else { return }
534537

@@ -558,6 +561,7 @@ final class VPNSettingsDataSource: UITableViewDiffableDataSource<
558561
header.accessibilityIdentifier = .quantumResistantTunnelCell
559562
header.titleLabel.text = title
560563
header.accessibilityCustomActionName = title
564+
header.isExpanded = isExpanded(.quantumResistance)
561565
header.didCollapseHandler = { [weak self] header in
562566
guard let self else { return }
563567

@@ -593,6 +597,11 @@ final class VPNSettingsDataSource: UITableViewDiffableDataSource<
593597

594598
return nil
595599
}
600+
601+
private func isExpanded(_ section: Section) -> Bool {
602+
let snapshot = snapshot()
603+
return snapshot.numberOfItems(inSection: section) != 0
604+
}
596605
}
597606

598607
extension VPNSettingsDataSource: VPNSettingsCellEventHandler {

ios/MullvadVPNUITests/Pages/VPNSettingsPage.swift

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ class VPNSettingsPage: Page {
1515
}
1616

1717
private func cellExpandButton(_ cellAccessiblityIdentifier: AccessibilityIdentifier) -> XCUIElement {
18-
let table = app.tables[AccessibilityIdentifier.vpnSettingsTableView]
19-
let matchingCells = table.otherElements.containing(.any, identifier: cellAccessiblityIdentifier.rawValue)
18+
let tableView = app.tables[AccessibilityIdentifier.vpnSettingsTableView]
19+
let matchingCells = tableView.otherElements[cellAccessiblityIdentifier.rawValue]
2020
let expandButton = matchingCells.buttons[AccessibilityIdentifier.expandButton]
21-
21+
let lastCell = tableView.cells.allElementsBoundByIndex.last!
22+
tableView.scrollUpToElement(element: lastCell)
2223
return expandButton
2324
}
2425

ios/MullvadVPNUITests/XCUIElement+Extensions.swift

+17
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,21 @@ extension XCUIElement {
1616
_ = XCTWaiter().wait(for: [expectation], timeout: timeout)
1717
return !exists
1818
}
19+
20+
func scrollUpToElement(element: XCUIElement) {
21+
while !element.visible() {
22+
swipeUp()
23+
}
24+
}
25+
26+
func scrollDownToElement(element: XCUIElement) {
27+
while !element.visible() {
28+
swipeDown()
29+
}
30+
}
31+
32+
func visible() -> Bool {
33+
guard self.exists && !self.frame.isEmpty else { return false }
34+
return XCUIApplication().windows.element(boundBy: 0).frame.contains(self.frame)
35+
}
1936
}

0 commit comments

Comments
 (0)