summaryrefslogtreecommitdiffhomepage
path: root/ios/MullvadVPNUITests/CustomListsTests.swift
blob: f387aafe160a9c0b85077e1ad50ebeed4bc071d6 (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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//
//  CustomListsTests.swift
//  MullvadVPNUITests
//
//  Created by Marco Nikic on 2024-04-17.
//  Copyright © 2025 Mullvad VPN AB. All rights reserved.
//

import XCTest

class CustomListsTests: LoggedInWithTimeUITestCase {
    func testCreateCustomListPersistAfterAppRestarts() throws {
        TunnelControlPage(app)
            .tapSelectLocationButton()

        let customListName = createCustomListName()
        createCustomList(named: customListName)
        // Custom lists are persisted across app sessions, guarantee that the next test starts in a clean state
        addTeardownBlock {
            self.deleteCustomList(named: customListName)
        }

        app.terminate()
        app.launch()

        TunnelControlPage(app)
            .tapSelectLocationButton()

        SelectLocationPage(app)
            .tapWhereStatusBarShouldBeToScrollToTopMostPosition()

        XCTAssertTrue(app.staticTexts[customListName].exists)
    }

    func testDeleteCustomList() throws {
        TunnelControlPage(app)
            .tapSelectLocationButton()

        let customListName = createCustomListName()
        createCustomList(named: customListName)
        deleteCustomList(named: customListName)

        SelectLocationPage(app)
            .tapWhereStatusBarShouldBeToScrollToTopMostPosition()

        XCTAssertFalse(app.staticTexts[customListName].exists)
    }

    func testEditCustomListLocations() throws {
        TunnelControlPage(app)
            .tapSelectLocationButton()

        let customListName = createCustomListName()
        createCustomList(named: customListName)

        addTeardownBlock {
            self.deleteCustomList(named: customListName)
        }

        startEditingCustomList(named: customListName)

        EditCustomListLocationsPage(app)
            .scrollToLocationWith(identifier: BaseUITestCase.testsDefaultCountryIdentifier)
            .toggleLocationCheckmarkWith(identifier: BaseUITestCase.testsDefaultCountryIdentifier)
            .tapBackButton()

        CustomListPage(app)
            .tapSaveListButton()

        ListCustomListsPage(app)
            .tapDoneButton()

        XCTAssertTrue(app.staticTexts[customListName].exists)
    }

    func testAddSingleLocationToCustomList() throws {
        TunnelControlPage(app)
            .tapSelectLocationButton()

        let customListName = createCustomListName()
        createCustomList(named: customListName)

        addTeardownBlock {
            self.deleteCustomList(named: customListName)
        }

        startEditingCustomList(named: customListName)

        EditCustomListLocationsPage(app)
            .scrollToLocationWith(identifier: BaseUITestCase.testsDefaultCountryIdentifier)
            .unfoldLocationwith(identifier: BaseUITestCase.testsDefaultCountryIdentifier)
            .unfoldLocationwith(identifier: BaseUITestCase.testsDefaultCityIdentifier)
            .toggleLocationCheckmarkWith(identifier: BaseUITestCase.testsDefaultRelayName)
            .tapBackButton()

        CustomListPage(app)
            .tapSaveListButton()

        ListCustomListsPage(app)
            .tapDoneButton()

        SelectLocationPage(app)
            .tapLocationCellExpandButton(withName: customListName)
        let customListLocationName = "\(customListName)-\(BaseUITestCase.testsDefaultRelayName)"
        let customListLocationCell = SelectLocationPage(app).cellWithIdentifier(identifier: customListLocationName)
        XCTAssertTrue(customListLocationCell.exists)
    }

    func createCustomList(named name: String) {
        SelectLocationPage(app)
            .tapWhereStatusBarShouldBeToScrollToTopMostPosition()
            .tapCustomListEllipsisButton()
            .tapAddNewCustomList()

        // When creating a new custom list, the "create" button should be disabled until the list has a name at minimum
        CustomListPage(app)
            .verifyCreateButtonIs(enabled: false)
            .renameCustomList(name: name)
            .verifyCreateButtonIs(enabled: true)
            .tapCreateListButton()
    }

    func startEditingCustomList(named customListName: String) {
        SelectLocationPage(app)
            .tapWhereStatusBarShouldBeToScrollToTopMostPosition()
            .tapCustomListEllipsisButton()
            .editExistingCustomLists()

        ListCustomListsPage(app)
            .selectCustomListToEdit(named: customListName)

        CustomListPage(app)
            .addOrEditLocations()

        EditCustomListLocationsPage(app)
    }

    func deleteCustomList(named customListName: String) {
        SelectLocationPage(app)
            .tapWhereStatusBarShouldBeToScrollToTopMostPosition()
            .tapCustomListEllipsisButton()
            .editExistingCustomLists()

        ListCustomListsPage(app)
            .selectCustomListToEdit(named: customListName)

        CustomListPage(app)
            .deleteCustomList(named: customListName)
    }

    /// Creates a unique name for a custom list
    ///
    /// The name will be used as an accessibility identifier
    /// Those are lower case and case sensitive.
    func createCustomListName() -> String {
        let customListOriginalName = UUID().uuidString
        let index = customListOriginalName.index(customListOriginalName.startIndex, offsetBy: 30)
        return String(customListOriginalName.prefix(upTo: index)).lowercased()
    }
}