blob: 821b35e5398f0ac6efa918f2b9ec8c645989434a (
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
|
//
// AccountPage.swift
// MullvadVPNUITests
//
// Created by Niklas Berglund on 2024-01-23.
// Copyright © 2025 Mullvad VPN AB. All rights reserved.
//
import Foundation
import XCTest
class AccountPage: Page {
@discardableResult override init(_ app: XCUIApplication) {
super.init(app)
self.pageElement = app.otherElements[.accountView]
waitForPageToBeShown()
}
@discardableResult func tapRedeemVoucherButton() -> Self {
app.buttons[AccessibilityIdentifier.redeemVoucherButton.asString].tap()
return self
}
@discardableResult func tapAdd30DaysTimeButton() -> Self {
app.buttons[AccessibilityIdentifier.purchaseButton.asString].tap()
return self
}
@discardableResult func tapRestorePurchasesButton() -> Self {
app.buttons[AccessibilityIdentifier.restorePurchasesButton.asString].tap()
return self
}
@discardableResult func tapLogOutButton() -> Self {
app.buttons[AccessibilityIdentifier.logoutButton.asString].tap()
return self
}
@discardableResult func tapDeleteAccountButton() -> Self {
app.buttons[AccessibilityIdentifier.deleteButton.asString].tap()
return self
}
@discardableResult func tapDeviceManagementButton() -> Self {
app.buttons[AccessibilityIdentifier.deviceManagementButton.asString].tap()
return self
}
func getDeviceName() throws -> String {
let deviceNameLabel = app.otherElements[AccessibilityIdentifier.accountPageDeviceNameLabel]
return try XCTUnwrap(deviceNameLabel.value as? String, "Failed to read device name from label")
}
@discardableResult func verifyPaidUntil(_ date: Date) -> Self {
// Strip seconds from date, since the app don't display seconds
let calendar = Calendar.current
var components = calendar.dateComponents([.year, .month, .day, .hour, .minute], from: date)
components.second = 0
guard let strippedDate = calendar.date(from: components) else {
XCTFail("Failed to remove seconds from date")
return self
}
let paidUntilLabelText = app.staticTexts[AccessibilityIdentifier.accountPagePaidUntilLabel].label
let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .medium
dateFormatter.timeStyle = .short
guard let paidUntilLabelDate = dateFormatter.date(from: paidUntilLabelText) else {
XCTFail("Failed to convert presented date to Date object")
return self
}
XCTAssertEqual(strippedDate, paidUntilLabelDate, "Paid until date correct")
return self
}
func waitForLogoutSpinnerToDisappear() {
let spinnerDisappeared = app.otherElements[.logOutSpinnerAlertView]
.waitForNonExistence(timeout: BaseUITestCase.extremelyLongTimeout)
XCTAssertTrue(spinnerDisappeared, "Log out spinner disappeared")
}
}
|