Skip to content

Commit fbb236f

Browse files
committed
add ui tests for sign up and select first factor
1 parent b6b298d commit fbb236f

File tree

8 files changed

+55
-8
lines changed

8 files changed

+55
-8
lines changed

Tests/AuthenticatorHostApp/AuthenticatorHostApp/AuthenticatorHostApp.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ struct AuthenticatorHostApp: App {
1717
private var hidesSignUpButton = false
1818
private var initialStep = AuthenticatorInitialStep.signIn
1919
private var authSignInNextStep = AuthSignInStep.done
20+
private var passwordlessFlow: Bool = false
2021
private var shouldUsePickerForTestingSteps = true
2122

2223
var body: some Scene {
@@ -25,7 +26,8 @@ struct AuthenticatorHostApp: App {
2526
hidesSignUpButton: hidesSignUpButton,
2627
initialStep: initialStep,
2728
authSignInStep: authSignInNextStep,
28-
shouldUsePickerForTestingSteps: shouldUsePickerForTestingSteps)
29+
shouldUsePickerForTestingSteps: shouldUsePickerForTestingSteps,
30+
passwordlessFlow: passwordlessFlow)
2931
}
3032
}
3133

@@ -54,6 +56,8 @@ struct AuthenticatorHostApp: App {
5456
factory.setUserAtributes(userAttributes)
5557
case .authSignInStep(let authUITestNextStep):
5658
self.authSignInNextStep = getMockedNextStepResult(from: authUITestNextStep)
59+
case .passwordlessFlow(let isPasswordlessFlow):
60+
self.passwordlessFlow = isPasswordlessFlow
5761
}
5862
}
5963

Tests/AuthenticatorHostApp/AuthenticatorHostApp/ContentView.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,23 @@ struct ContentView: View {
100100
private let hidesSignUpButton: Bool
101101
private let initialStep: AuthenticatorInitialStep
102102
private let shouldUsePickerForTestingSteps: Bool
103+
private let signUpFields: [SignUpField]
103104

104105
init(hidesSignUpButton: Bool,
105106
initialStep: AuthenticatorInitialStep,
106107
authSignInStep: AuthSignInStep,
107-
shouldUsePickerForTestingSteps: Bool = false) {
108+
shouldUsePickerForTestingSteps: Bool = false,
109+
passwordlessFlow: Bool = false) {
108110
self.hidesSignUpButton = hidesSignUpButton
109111
self.initialStep = initialStep
110112
self.shouldUsePickerForTestingSteps = shouldUsePickerForTestingSteps
111113

114+
if passwordlessFlow {
115+
self.signUpFields = []
116+
} else {
117+
self.signUpFields = Self.defaultSignUpFields
118+
}
119+
112120
// Configure mocks for testing
113121
configureMocksForPasswordlessTesting()
114122

@@ -203,7 +211,11 @@ struct ContentView: View {
203211

204212
Authenticator(
205213
initialStep: initialStep,
206-
authenticationFlow: .userChoice(preferredAuthFactor: .password(), passkeyPrompts: .init(afterSignUp: .always, afterSignIn: .always)) // Testing UserChoice with no preferred auth factor
214+
authenticationFlow: .userChoice(
215+
preferredAuthFactor: .password(),
216+
passkeyPrompts: .init(
217+
afterSignUp: .always,
218+
afterSignIn: .always))
207219
) { state in
208220
VStack {
209221
Text("Hello, \(state.user.username)")
@@ -225,7 +237,7 @@ struct ContentView: View {
225237

226238
}
227239

228-
private var signUpFields: [SignUpField] {
240+
private static var defaultSignUpFields: [SignUpField] {
229241
return [
230242
.password(isRequired: true),
231243
.confirmPassword(isRequired: true)

Tests/AuthenticatorHostApp/AuthenticatorHostAppUITests/AuthenticatorBaseTestCase.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class AuthenticatorBaseTestCase: XCTestCase {
5858
app.launch()
5959
}
6060

61-
func launchAppAndLogin(with args: [ProcessArgument]) {
61+
func launchAppAndLogin(with args: [ProcessArgument], shouldEnterPassword: Bool = true) {
6262

6363
// Launch Application
6464
launchApp(with: args)
@@ -69,9 +69,11 @@ class AuthenticatorBaseTestCase: XCTestCase {
6969
app.textFields.firstMatch.tap()
7070
app.textFields.firstMatch.typeText("username")
7171

72-
// Enter some password
73-
app.secureTextFields.firstMatch.tap()
74-
app.secureTextFields.firstMatch.typeText("password")
72+
if shouldEnterPassword {
73+
// Enter some password
74+
app.secureTextFields.firstMatch.tap()
75+
app.secureTextFields.firstMatch.typeText("password")
76+
}
7577

7678
// Tap Sign in button
7779
app.buttons["Sign In"].firstMatch.tap()

Tests/AuthenticatorHostApp/AuthenticatorHostAppUITests/AuthenticatorUITestUtils.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ enum ProcessArgument: Codable {
1515
case initialStep(AuthenticatorInitialStep)
1616
case authSignInStep(AuthUITestSignInStep)
1717
case userAttributes([UserAttribute])
18+
case passwordlessFlow(Bool)
1819
}
1920

2021
enum UserAttribute: String, Codable {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//
2+
// Copyright Amazon.com Inc. or its affiliates.
3+
// All Rights Reserved.
4+
//
5+
// SPDX-License-Identifier: Apache-2.0
6+
//
7+
8+
import XCTest
9+
10+
final class ContinueSignInWithFirstFactorSelectionTests: AuthenticatorBaseTestCase {
11+
12+
func testContinueSignInWithFirstFactorSelection() throws {
13+
launchAppAndLogin(with: [
14+
.hidesSignUpButton(false),
15+
.initialStep(.signIn),
16+
.authSignInStep(.continueSignInWithFirstFactorSelection)
17+
])
18+
assertSnapshot()
19+
}
20+
}

Tests/AuthenticatorHostApp/AuthenticatorHostAppUITests/TestCases/SignUpViewTests.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,12 @@ final class SignUpViewTests: AuthenticatorBaseTestCase {
1515
])
1616
assertSnapshot()
1717
}
18+
19+
func testPasswordlessSignUpView() throws {
20+
launchApp(with: [
21+
.initialStep(.signUp),
22+
.passwordlessFlow(true)
23+
])
24+
assertSnapshot()
25+
}
1826
}
Loading
133 KB
Loading

0 commit comments

Comments
 (0)