Skip to content

Commit

Permalink
Add time left properly displayed test
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasberglund authored and mojganii committed Apr 12, 2024
1 parent 228827f commit a880d13
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions ios/MullvadVPN/Classes/AccessbilityIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public enum AccessibilityIdentifier: String {
case quantumResistantTunnelCell

// Labels
case accountPagePaidUntilLabel
case headerDeviceNameLabel
case connectionStatusConnectedLabel
case connectionStatusNotConnectedLabel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class AccountExpiryRow: UIView {
valueLabel.translatesAutoresizingMaskIntoConstraints = false
valueLabel.font = UIFont.systemFont(ofSize: 17)
valueLabel.textColor = .white
valueLabel.accessibilityIdentifier = .accountPagePaidUntilLabel
return valueLabel
}()

Expand Down
12 changes: 12 additions & 0 deletions ios/MullvadVPNUITests/AccountTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,16 @@ class AccountTests: LoggedOutUITestCase {
XCTAssertEqual(try MullvadAPIWrapper().getDevices(newAccountNumber).count, 0)
try MullvadAPIWrapper().deleteAccount(newAccountNumber)
}

func testTimeLeft() throws {
login(accountNumber: hasTimeAccountNumber)

let accountExpiry = try MullvadAPIWrapper().getAccountExpiry(hasTimeAccountNumber)

HeaderBar(app)
.tapAccountButton()

AccountPage(app)
.verifyPaidUntil(accountExpiry)
}
}
6 changes: 4 additions & 2 deletions ios/MullvadVPNUITests/Networking/MullvadAPIWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ class MullvadAPIWrapper {
}
}

func getAccountExpiry(_ account: String) throws -> UInt64 {
func getAccountExpiry(_ account: String) throws -> Date {
do {
return try mullvadAPI.getExpiry(forAccount: account)
let accountExpiryTimestamp = Double(try mullvadAPI.getExpiry(forAccount: account))
let accountExpiryDate = Date(timeIntervalSince1970: accountExpiryTimestamp)
return accountExpiryDate
} catch {
throw MullvadAPIError.requestError
}
Expand Down
25 changes: 25 additions & 0 deletions ios/MullvadVPNUITests/Pages/AccountPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,29 @@ class AccountPage: Page {
app.buttons[AccessibilityIdentifier.deleteButton.rawValue].tap()
return self
}

@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)

return self
}
}

0 comments on commit a880d13

Please sign in to comment.