Skip to content

Commit c26aa2f

Browse files
Add time left properly displayed test
1 parent ba779e9 commit c26aa2f

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

ios/MullvadVPN/Classes/AccessbilityIdentifier.swift

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public enum AccessibilityIdentifier: String {
5252
case quantumResistantTunnelCell
5353

5454
// Labels
55+
case accountPagePaidUntilLabel
5556
case headerDeviceNameLabel
5657
case connectionStatusLabel
5758
case welcomeAccountNumberLabel

ios/MullvadVPN/View controllers/Account/AccountExpiryRow.swift

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ class AccountExpiryRow: UIView {
6262
valueLabel.translatesAutoresizingMaskIntoConstraints = false
6363
valueLabel.font = UIFont.systemFont(ofSize: 17)
6464
valueLabel.textColor = .white
65+
valueLabel.accessibilityIdentifier = .accountPagePaidUntilLabel
6566
return valueLabel
6667
}()
6768

ios/MullvadVPNUITests/AccountTests.swift

+12
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,16 @@ class AccountTests: LoggedOutUITestCase {
8989
XCTAssertEqual(try MullvadAPIWrapper().getDevices(newAccountNumber).count, 0)
9090
try MullvadAPIWrapper().deleteAccount(newAccountNumber)
9191
}
92+
93+
func testTimeLeft() throws {
94+
login(accountNumber: hasTimeAccountNumber)
95+
96+
let accountExpiry = try MullvadAPIWrapper().getAccountExpiry(hasTimeAccountNumber)
97+
98+
HeaderBar(app)
99+
.tapAccountButton()
100+
101+
AccountPage(app)
102+
.verifyPaidUntil(accountExpiry)
103+
}
92104
}

ios/MullvadVPNUITests/Networking/MullvadAPIWrapper.swift

+4-2
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ class MullvadAPIWrapper {
8888
}
8989
}
9090

91-
func getAccountExpiry(_ account: String) throws -> UInt64 {
91+
func getAccountExpiry(_ account: String) throws -> Date {
9292
do {
93-
return try mullvadAPI.getExpiry(forAccount: account)
93+
let accountExpiryTimestamp = Double(try mullvadAPI.getExpiry(forAccount: account))
94+
let accountExpiryDate = Date(timeIntervalSince1970: accountExpiryTimestamp)
95+
return accountExpiryDate
9496
} catch {
9597
throw MullvadAPIError.requestError
9698
}

ios/MullvadVPNUITests/Pages/AccountPage.swift

+26
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,30 @@ class AccountPage: Page {
4141
app.buttons[AccessibilityIdentifier.deleteButton.rawValue].tap()
4242
return self
4343
}
44+
45+
@discardableResult func verifyPaidUntil(_ date: Date) -> Self {
46+
// Strip seconds from date, since the app don't display seconds
47+
let calendar = Calendar.current
48+
var components = calendar.dateComponents([.year, .month, .day, .hour, .minute], from: date)
49+
components.second = 0
50+
guard let strippedDate = calendar.date(from: components) else {
51+
XCTFail("Failed to remove seconds from date")
52+
return self
53+
}
54+
55+
let paidUntilLabelText = app.staticTexts[AccessibilityIdentifier.accountPagePaidUntilLabel].label
56+
let dateFormatter = DateFormatter()
57+
dateFormatter.dateFormat = "d MMM yyyy 'at' H:mm"
58+
59+
guard let paidUntilLabelDate = dateFormatter.date(from: paidUntilLabelText) else {
60+
XCTFail("Failed to convert presented date to Date object")
61+
return self
62+
}
63+
64+
print(paidUntilLabelDate)
65+
66+
XCTAssertEqual(strippedDate, paidUntilLabelDate)
67+
68+
return self
69+
}
4470
}

0 commit comments

Comments
 (0)