Fix UI tests for screenshots (#1168)

Outdated after reworking the UI. Some fixes were also needed because:

- [WireGuardModule requires a
configuration](https://github.com/passepartoutvpn/passepartout/pull/1164)
- [OpenVPNModule is interactive when no credentials are
set](https://github.com/passepartoutvpn/passepartout/pull/1104)
- Mock profile had a wrong category ("" → "default")
This commit is contained in:
Davide 2025-02-13 08:20:56 +01:00 committed by GitHub
parent e4333965bd
commit afee4037e2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 52 additions and 37 deletions

View File

@ -27,6 +27,7 @@ import CommonLibrary
import Foundation
import PassepartoutKit
import TipKit
import UIAccessibility
@_exported import UILibrary
public final class AppUIMain: UILibraryConfiguring {
@ -40,6 +41,9 @@ public final class AppUIMain: UILibraryConfiguring {
// for debugging
// Tips.showAllTipsForTesting()
if AppCommandLine.contains(.uiTesting) {
Tips.hideAllTipsForTesting()
}
try? Tips.configure([
.displayFrequency(.immediate)

View File

@ -50,7 +50,6 @@ struct InstalledProfileView: View, Routable {
debugChanges()
return HStack(alignment: .center) {
cardView
.uiAccessibility(.App.installedProfile)
Spacer()
toggleButton
}

View File

@ -53,6 +53,8 @@ struct ProfileCardView: View {
.font(.headline)
.themeMultiLine(true)
}
.uiAccessibility(.App.profileEdit)
tunnelView
.font(.subheadline)

View File

@ -73,9 +73,6 @@ private extension ProfileRowView {
)
.contentShape(.rect)
.foregroundStyle(.primary)
// FIXME: ###, UI tests
.uiAccessibility(.App.profileMenu)
}
var attributesView: some View {
@ -94,7 +91,6 @@ private extension ProfileRowView {
flow: flow?.connectionFlow
)
.labelsHidden()
// FIXME: ###, UI tests
.uiAccessibility(.App.profileToggle)
}
}

View File

@ -39,5 +39,6 @@ struct ProfilesHeaderView: View {
Text(Strings.Views.Verification.message)
}
}
.uiAccessibility(.App.profilesHeader)
}
}

View File

@ -50,6 +50,7 @@ extension OpenVPNModule.Builder: ModuleShortcutsProviding {
NavigationLink(value: OpenVPNView.Subroute.providerServer) {
ProviderServerRow(selectedEntity: providerSelection.entity)
}
.uiAccessibility(.Profile.providerServerLink)
}
if providerSelection != nil || configurationBuilder?.authUserPass == true {
NavigationLink(value: OpenVPNView.Subroute.credentials) {

View File

@ -86,7 +86,7 @@ private extension ActiveProfileView {
.font(.title)
.fontWeight(theme.relevantWeight)
.frame(maxWidth: .infinity, alignment: .leading)
.uiAccessibility(.App.installedProfile)
.uiAccessibility(.App.profilesHeader)
}
var statusView: some View {

View File

@ -36,6 +36,8 @@ public struct AccessibilityInfo: Equatable, Sendable {
case menuItem
case text
case toggle
}
public let id: String

View File

@ -37,10 +37,10 @@ extension AccessibilityInfo {
public static let profile = AccessibilityInfo("app.profileList.profile", .button)
}
public static let installedProfile = AccessibilityInfo("app.installedProfile", .text)
public static let profilesHeader = AccessibilityInfo("app.profilesHeader", .text)
public static let profileToggle = AccessibilityInfo("app.profileToggle", .button)
public static let profileToggle = AccessibilityInfo("app.profileToggle", .toggle)
public static let profileMenu = AccessibilityInfo("app.profileMenu", .menu)
public static let profileEdit = AccessibilityInfo("app.profileEdit", .button)
}
}

View File

@ -31,6 +31,8 @@ extension AccessibilityInfo {
public static let moduleLink = AccessibilityInfo("profile.moduleLink", .link)
public static let providerServerLink = AccessibilityInfo("profile.providerServerLink", .link)
public static let cancel = AccessibilityInfo("profile.cancel", .button)
}
}

View File

@ -13,8 +13,9 @@
buildForProfiling = "NO"
buildForArchiving = "NO"
buildForAnalyzing = "NO">
<AutocreatedTestPlanReference>
</AutocreatedTestPlanReference>
<TestPlanReference
reference = "container:Passepartout/UITests/TVScreenshots.xctestplan">
</TestPlanReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
@ -25,7 +26,8 @@
shouldUseLaunchSchemeArgsEnv = "YES">
<TestPlans>
<TestPlanReference
reference = "container:Passepartout/UITests/TVScreenshots.xctestplan">
reference = "container:Passepartout/UITests/TVScreenshots.xctestplan"
default = "YES">
</TestPlanReference>
<TestPlanReference
reference = "container:Passepartout/UITests/MainScreenshots.xctestplan">

View File

@ -56,6 +56,7 @@ extension ProfileManager {
ovpnBuilder.isInteractive = true
#endif
ovpnBuilder.providerEntity = mockHideMeEntity
ovpnBuilder.credentials = OpenVPN.Credentials.Builder(username: "foo", password: "bar").build()
moduleBuilder = ovpnBuilder
} else if var onDemandBuilder = moduleBuilder as? OnDemandModule.Builder {
#if !os(tvOS)
@ -93,6 +94,11 @@ extension ProfileManager {
}
}
if var wgBuilder = moduleBuilder as? WireGuardModule.Builder {
wgBuilder.configurationBuilder = WireGuard.Configuration.Builder(privateKey: "")
moduleBuilder = wgBuilder
}
let module = try moduleBuilder.tryBuild()
builder.modules.append(module)
}
@ -163,7 +169,7 @@ private extension ProfileManager {
serverId: "be-v4",
supportedConfigurationIdentifiers: ["OpenVPN"],
supportedPresetIds: nil,
categoryName: "",
categoryName: "default",
countryCode: "BE",
otherCountryCodes: nil,
area: nil

View File

@ -48,6 +48,8 @@ private extension XCUIElement {
return buttons
case .text:
return staticTexts
case .toggle:
return switches
}
#else
switch elementType {
@ -59,6 +61,8 @@ private extension XCUIElement {
return menuItems
case .text:
return staticTexts
case .toggle:
return checkBoxes
}
#endif
}

View File

@ -47,33 +47,23 @@ final class MainFlowTests: XCTestCase {
func testEditProfile() {
AppScreen(app: app)
.waitForProfiles()
.openProfileMenu(at: 2)
.editProfile()
.editProfile(at: 2)
}
func testEditProfileModule() {
AppScreen(app: app)
.waitForProfiles()
.openProfileMenu(at: 2)
.editProfile()
.editProfile(at: 2)
.enterModule(at: 1)
.leaveModule()
}
func testConnectToProviderServer() {
AppScreen(app: app)
.waitForProfiles()
.openProfileMenu(at: 2)
.connectToProfile()
}
#if os(iOS)
func testDiscloseProviderCountry() {
AppScreen(app: app)
.waitForProfiles()
.openProfileMenu(at: 2)
.connectToProfile()
.discloseCountry(at: 2)
.editProfile(at: 2)
.editProviderServer()
}
#endif
}

View File

@ -48,11 +48,10 @@ final class MainScreenshotTests: XCTestCase, XCUIApplicationProviding {
func testTakeScreenshots() async throws {
let root = AppScreen(app: app)
.waitForProfiles()
.enableProfile(at: 0)
.enableProfile(at: 1)
let profile = root
.openProfileMenu(at: 2)
.editProfile()
.editProfile(at: 2)
await pause()
try snapshot("03", "ProfileEditor", target: .sheet)
@ -78,8 +77,8 @@ final class MainScreenshotTests: XCTestCase, XCUIApplicationProviding {
try snapshot("01", "Connected")
app
.openProfileMenu(at: 2)
.connectToProfile()
.editProfile(at: 2)
.editProviderServer()
#if os(iOS)
.discloseCountry(at: 2)
#endif

View File

@ -33,7 +33,7 @@ struct AppScreen {
@discardableResult
func waitForProfiles() -> Self {
app.get(.App.installedProfile)
app.get(.App.profilesHeader)
return self
}
@ -45,9 +45,9 @@ struct AppScreen {
}
@discardableResult
func openProfileMenu(at index: Int) -> ProfileMenuScreen {
let profileMenu = app.get(.App.profileMenu, at: index)
func editProfile(at index: Int) -> ProfileEditorScreen {
let profileMenu = app.get(.App.profileEdit, at: index)
profileMenu.tap()
return ProfileMenuScreen(app: app)
return ProfileEditorScreen(app: app)
}
}

View File

@ -48,6 +48,13 @@ struct ProfileEditorScreen {
return self
}
@discardableResult
func editProviderServer() -> ProviderServersScreen {
let providerServerLink = app.get(.Profile.providerServerLink)
providerServerLink.tap()
return ProviderServersScreen(app: app)
}
@discardableResult
func closeProfile() -> AppScreen {
let cancelButton = app.get(.Profile.cancel)

View File

@ -35,7 +35,7 @@ struct AppScreen {
@discardableResult
func waitForProfiles() -> Self {
app.get(.App.installedProfile)
app.get(.App.profilesHeader)
return self
}