summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPNUITests/Pages/SelectLocationPage.swift
blob: b7fed438a4cffce074c9ff3f68f9a1df5d34bf5f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
//  SelectLocationPage.swift
//  MullvadVPNUITests
//
//  Created by Niklas Berglund on 2024-01-11.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import Foundation
import XCTest

class SelectLocationPage: Page {
    @discardableResult override init(_ app: XCUIApplication) {
        super.init(app)

        self.pageElement = app.otherElements[.selectLocationView]
        waitForPageToBeShown()
    }

    @discardableResult func tapLocationCell(withName name: String) -> Self {
        app.tables[AccessibilityIdentifier.selectLocationTableView].cells.staticTexts[name].tap()
        return self
    }

    @discardableResult func tapCountryLocationCellExpandButton(withName name: String) -> Self {
        let cell = app.cells.containing(.any, identifier: name)
        let expandButton = cell.buttons[AccessibilityIdentifier.expandButton]
        expandButton.tap()
        return self
    }

    @discardableResult func tapCountryLocationCellExpandButton(withIndex: Int) -> Self {
        let cell = app.cells.containing(.any, identifier: AccessibilityIdentifier.countryLocationCell.asString)
            .element(boundBy: withIndex)
        let expandButton = cell.buttons[AccessibilityIdentifier.expandButton]
        expandButton.tap()
        return self
    }

    @discardableResult func tapCityLocationCellExpandButton(withIndex: Int) -> Self {
        let cell = app.cells.containing(.any, identifier: AccessibilityIdentifier.cityLocationCell.asString)
            .element(boundBy: withIndex)
        let expandButton = cell.buttons[AccessibilityIdentifier.expandButton]
        expandButton.tap()
        return self
    }

    @discardableResult func tapRelayLocationCell(withIndex: Int) -> Self {
        let cell = app.cells.containing(.any, identifier: AccessibilityIdentifier.relayLocationCell.asString)
            .element(boundBy: withIndex)
        cell.tap()
        return self
    }

    @discardableResult func tapLocationCellExpandButton(withName name: String) -> Self {
        let table = app.tables[AccessibilityIdentifier.selectLocationTableView]
        let matchingCells = table.cells.containing(.any, identifier: name)
        let buttons = matchingCells.buttons
        let expandButton = buttons[AccessibilityIdentifier.expandButton]

        expandButton.tap()

        return self
    }

    @discardableResult func tapLocationCellCollapseButton(withName name: String) -> Self {
        let table = app.tables[AccessibilityIdentifier.selectLocationTableView]
        let matchingCells = table.cells.containing(.any, identifier: name)
        let buttons = matchingCells.buttons
        let collapseButton = buttons[AccessibilityIdentifier.collapseButton]

        collapseButton.tap()

        return self
    }

    @discardableResult func tapCustomListEllipsisButton() -> Self {
        // This wait should not be needed, but is due to the issues we are having with the ellipsis button
        _ = app.buttons[.openCustomListsMenuButton].waitForExistence(timeout: BaseUITestCase.shortTimeout)

        let customListEllipsisButtons = app.buttons
            .matching(identifier: AccessibilityIdentifier.openCustomListsMenuButton.asString).allElementsBoundByIndex

        // This is a workaround for an issue we have with the ellipsis showing up multiple times in the accessibility hieararchy even though in the view hierarchy there is only one
        // Only the actually visual one is hittable, so only the visible button will be tapped
        for ellipsisButton in customListEllipsisButtons where ellipsisButton.isHittable {
            ellipsisButton.tap()
            return self
        }

        XCTFail("Found no hittable custom list ellipsis button")

        return self
    }

    @discardableResult func tapAddNewCustomList() -> Self {
        let addNewCustomListButton = app.buttons[AccessibilityIdentifier.addNewCustomListButton]
        addNewCustomListButton.tap()
        return self
    }

    @discardableResult func editExistingCustomLists() -> Self {
        let editCustomListsButton = app.buttons[AccessibilityIdentifier.editCustomListButton]
        editCustomListsButton.tap()
        return self
    }

    @discardableResult func cellWithIdentifier(identifier: String) -> XCUIElement {
        app.tables[AccessibilityIdentifier.selectLocationTableView].cells[identifier]
    }

    @discardableResult func tapFilterButton() -> Self {
        app.buttons[AccessibilityIdentifier.selectLocationFilterButton].tap()
        return self
    }

    @discardableResult func tapDoneButton() -> Self {
        app.buttons[AccessibilityIdentifier.closeSelectLocationButton].tap()
        return self
    }

    func locationCellIsExpanded(_ name: String) -> Bool {
        let matchingCells = app.cells.containing(.any, identifier: name)
        return matchingCells.buttons[AccessibilityIdentifier.expandButton].exists ? false : true
    }

    func verifyEditCustomListsButtonIs(enabled: Bool) {
        let editCustomListsButton = app.buttons[AccessibilityIdentifier.editCustomListButton]
        XCTAssertTrue(editCustomListsButton.isEnabled == enabled)
    }
}