Skip to content

Commit daea3f8

Browse files
author
mojganii
committed
Fix off-screen element detection issue
1 parent 2136989 commit daea3f8

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-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

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

0 commit comments

Comments
 (0)