passepartout-apple/Passepartout/Library/Sources/UILibrary/L10n/PassepartoutKit+L10n.swift
Davide 962361cb9f
Automate screenshots via UI tests (#960)
Ready for screenshots generation, except for the tests themselves and
the TV target.

- More customizations while UI testing
  - Act as full version user in IAPManager
  - Override layout with default to .grid if isBigDevice
  - Show module names in profile list/grid
- Improve mock Profile/ProfileManager
  - Meaningful profile names
  - iCloud/TV icons
  - Initial modules
- Improve XCTest extensions
  - Screenshot destination (attachment/temporary)
  - Screenshot target (window/sheet)
  - Print saved temporary URL at the end (may help with CI)
  - Append device name to screenshot filename
- Tests
- Refactor actions with the [Page Object
pattern](https://swiftwithmajid.com/2021/03/24/ui-testing-using-page-object-pattern-in-swift/)
  - Perform iPad screenshots in landscape
  - Split simple flow tests and screenshots
  - Add "Connect to" test

Closes #681
2024-11-28 15:51:03 +01:00

243 lines
6.1 KiB
Swift

//
// PassepartoutKit+L10n.swift
// Passepartout
//
// Created by Davide De Rosa on 2/19/24.
// Copyright (c) 2024 Davide De Rosa. All rights reserved.
//
// https://github.com/passepartoutvpn
//
// This file is part of Passepartout.
//
// Passepartout is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Passepartout is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Passepartout. If not, see <http://www.gnu.org/licenses/>.
//
import CommonLibrary
import CommonUtils
import Foundation
import PassepartoutKit
extension Profile {
public var localizedPreview: ProfilePreview {
ProfilePreview(
id: id,
name: name,
subtitle: localizedDescription(optionalStyle: .moduleTypes)
)
}
}
extension Profile: StyledOptionalLocalizableEntity {
public enum OptionalStyle {
case moduleTypes
case connectionType
case nonConnectionTypes
}
public func localizedDescription(optionalStyle: OptionalStyle) -> String? {
switch optionalStyle {
case .moduleTypes:
return activeModules
.nilIfEmpty?
.map(\.moduleType.localizedDescription)
.sorted()
.joined(separator: ", ")
case .connectionType:
return firstConnectionModule(ifActive: true)?
.moduleType
.localizedDescription
case .nonConnectionTypes:
return activeModules
.filter {
!($0 is ConnectionModule)
}
.nilIfEmpty?
.map(\.moduleType.localizedDescription)
.sorted()
.joined(separator: ", ")
}
}
}
extension TunnelStatus: LocalizableEntity {
public var localizedDescription: String {
let V = Strings.Entities.TunnelStatus.self
switch self {
case .inactive:
return V.inactive
case .activating:
return V.activating
case .active:
return V.active
case .deactivating:
return V.deactivating
}
}
}
extension DataCount: LocalizableEntity {
public var localizedDescription: String {
let down = received.descriptionAsDataUnit
let up = sent.descriptionAsDataUnit
return "\(down)\(up)"
}
}
extension Address.Family: LocalizableEntity {
public var localizedDescription: String {
switch self {
case .v4:
return Strings.Unlocalized.ipv4
case .v6:
return Strings.Unlocalized.ipv6
}
}
}
extension IPSettings: StyledOptionalLocalizableEntity {
public enum OptionalStyle {
case address
case defaultGateway
}
public func localizedDescription(optionalStyle: OptionalStyle) -> String? {
switch optionalStyle {
case .address:
return addressDescription
case .defaultGateway:
return defaultGatewayDescription
}
}
private var addressDescription: String? {
subnet?.address.rawValue
}
private var defaultGatewayDescription: String? {
includedRoutes
.first(where: \.isDefault)?
.gateway?
.rawValue
}
}
extension Route: LocalizableEntity {
public var localizedDescription: String {
if let dest = destination?.rawValue {
if let gw = gateway?.rawValue {
return "\(dest)\(gw)"
} else {
return dest
}
} else if let gw = gateway?.rawValue {
return "default → \(gw)"
}
return "default → *"
}
}
extension OnDemandModule.Policy: LocalizableEntity {
public var localizedDescription: String {
switch self {
case .any:
return Strings.Entities.OnDemand.Policy.any
case .excluding:
return Strings.Entities.OnDemand.Policy.excluding
case .including:
return Strings.Entities.OnDemand.Policy.including
}
}
}
extension ProviderID: @retroactive CustomDebugStringConvertible {
public var debugDescription: String {
rawValue
}
}
extension VPNServer {
public var region: String {
[provider.countryCode.localizedAsRegionCode, provider.area]
.compactMap { $0 }
.joined(separator: " - ")
}
public var address: String {
if let hostname {
return hostname
}
if let ipAddresses {
return ipAddresses
.compactMap {
guard let address = Address(data: $0) else {
return nil
}
return address.description
}
.joined(separator: ", ")
}
return ""
}
}
extension OpenVPN.Credentials.OTPMethod: StyledLocalizableEntity {
public enum Style {
case entity
case approachDescription
}
public func localizedDescription(style: Style) -> String {
switch style {
case .entity:
let V = Strings.Entities.Openvpn.OtpMethod.self
switch self {
case .none:
return V.none
case .append:
return V.append
case .encode:
return V.encode
}
case .approachDescription:
let V = Strings.Modules.Openvpn.Credentials.OtpMethod.Approach.self
switch self {
case .none:
return ""
case .append:
return V.append
case .encode:
return V.encode
}
}
}
}