Add UI tests for optional app lock setup. (#2046)

This commit is contained in:
Doug
2023-11-08 15:33:40 +00:00
committed by GitHub
parent e04a55eaef
commit 07313926c9
42 changed files with 360 additions and 71 deletions
@@ -0,0 +1,39 @@
//
// Copyright 2023 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
import SwiftUI
class BlankFormCoordinator: CoordinatorProtocol {
func toPresentable() -> AnyView {
AnyView(BlankForm())
}
}
/// An empty Form used for UI tests, behind a sheet.
private struct BlankForm: View {
var body: some View {
Form {
Text("Nothing to see here.")
}
.compoundForm()
}
}
struct BlankForm_Previews: PreviewProvider {
static var previews: some View {
BlankForm()
}
}
@@ -42,12 +42,12 @@ class UITestsAppCoordinator: AppCoordinatorProtocol {
}
func start() {
// disabling CA animations
// Fix the app tint colour.
UIApplication.shared.connectedScenes.forEach { scene in
guard let delegate = scene.delegate as? UIWindowSceneDelegate else {
return
}
delegate.window??.layer.speed = 0
delegate.window??.tintColor = .compound.textActionPrimary
}
guard let screenID = ProcessInfo.testScreenID else { fatalError("Unable to launch with unknown screen.") }
@@ -162,15 +162,36 @@ class MockScreen: Identifiable {
let appLockService = AppLockService(keychainController: KeychainControllerMock(), appSettings: ServiceLocator.shared.settings)
let coordinator = AppLockScreenCoordinator(parameters: .init(appLockService: appLockService))
return coordinator
case .appLockSetupFlow:
case .appLockSetupFlow, .appLockSetupFlowUnlock:
let navigationStackCoordinator = NavigationStackCoordinator()
let keychainController = KeychainControllerMock()
keychainController.containsPINCodeReturnValue = false
let appLockService = AppLockService(keychainController: keychainController, appSettings: ServiceLocator.shared.settings)
// The flow expects an existing root coordinator, use the placeholder as a placeholder 😅
navigationStackCoordinator.setRootCoordinator(BlankFormCoordinator())
let keychainController = KeychainController(service: .tests, accessGroup: InfoPlistReader.main.keychainAccessGroupIdentifier)
keychainController.resetSecrets()
if id == .appLockSetupFlowUnlock {
do {
try keychainController.setPINCode("2023")
} catch {
fatalError("Failed to pre-set the PIN code")
}
}
let context = LAContextMock()
context.biometryTypeValue = UIDevice.current.isPhone ? .faceID : .touchID // (iPhone 14 & iPad 9th gen)
context.evaluatePolicyReturnValue = true
context.evaluatedPolicyDomainStateValue = "😎".data(using: .utf8)
let appLockService = AppLockService(keychainController: keychainController,
appSettings: ServiceLocator.shared.settings,
context: context)
let coordinator = AppLockSetupFlowCoordinator(presentingFlow: .settings,
appLockService: appLockService,
navigationStackCoordinator: navigationStackCoordinator)
coordinator.start()
retainedState.append(coordinator)
return navigationStackCoordinator
case .home:
let navigationStackCoordinator = NavigationStackCoordinator()
@@ -31,6 +31,7 @@ enum UITestsScreenIdentifier: String {
case templateScreen
case appLockScreen
case appLockSetupFlow
case appLockSetupFlowUnlock
case home
case settings
case bugReport