Skip to content

Commit d235b05

Browse files
committed
add passkey ui tests
1 parent fbb236f commit d235b05

File tree

6 files changed

+79
-2
lines changed

6 files changed

+79
-2
lines changed

Tests/AuthenticatorHostApp/AuthenticatorHostApp/ContentView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ struct ContentView: View {
171171
username: "[email protected]",
172172
userId: "user-123"
173173
)
174+
175+
mockService.mockedSignUpResult = AuthSignUpResult(
176+
.done
177+
)
174178
}
175179

176180
var body: some View {

Tests/AuthenticatorHostApp/AuthenticatorHostApp/Mocks/MockAuthenticationService.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,11 @@ class MockAuthenticationService: AuthenticationService {
298298
// MARK: - WebAuthn
299299

300300
func associateWebAuthnCredential(presentationAnchor: AuthUIPresentationAnchor?, options: AuthAssociateWebAuthnCredentialRequest.Options?) async throws {
301-
fatalError("Unsupported operation in Authenticator")
301+
302302
}
303303

304304
func listWebAuthnCredentials(options: AuthListWebAuthnCredentialsRequest.Options?) async throws -> AuthListWebAuthnCredentialsResult {
305-
fatalError("Unsupported operation in Authenticator")
305+
return .init(credentials: [], nextToken: nil)
306306
}
307307

308308
func deleteWebAuthnCredential(credentialId: String, options: AuthDeleteWebAuthnCredentialRequest.Options?) async throws {
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 PasskeyPromptTests: AuthenticatorBaseTestCase {
11+
12+
func testSignInPasskeyPrompt() throws {
13+
launchAppAndLogin(with: [
14+
.hidesSignUpButton(false),
15+
.initialStep(.signIn),
16+
.authSignInStep(.done)
17+
])
18+
assertSnapshot()
19+
}
20+
21+
func testSignUpPasskeyPrompt() throws {
22+
23+
let app = XCUIApplication()
24+
25+
launchApp(with: [
26+
.hidesSignUpButton(false),
27+
.initialStep(.signUp),
28+
.authSignInStep(.done),
29+
.passwordlessFlow(true)
30+
])
31+
32+
// Enter some username
33+
app.textFields.firstMatch.tap()
34+
app.textFields.firstMatch.typeText("username")
35+
36+
// Enter some username
37+
app.textFields["Enter your email"].tap()
38+
app.textFields["Enter your email"].typeText("[email protected]")
39+
40+
// Tap Sign in button
41+
app.buttons["Create account"].firstMatch.tap()
42+
43+
// Wait for Sign In view to disappear
44+
let expectation = expectation(
45+
for: .init(format: "exists == false"),
46+
evaluatedWith: app.staticTexts["Create account"])
47+
let result = XCTWaiter.wait(for: [expectation], timeout: 5.0)
48+
XCTAssertEqual(result, .completed)
49+
50+
assertSnapshot()
51+
}
52+
53+
func testSignInPasskeyCreated() throws {
54+
launchAppAndLogin(with: [
55+
.hidesSignUpButton(false),
56+
.initialStep(.signIn),
57+
.authSignInStep(.done)
58+
])
59+
60+
let app = XCUIApplication()
61+
// Tap Sign in button
62+
app.buttons["Create a Passkey"].firstMatch.tap()
63+
64+
// Wait for Sign In view to disappear
65+
let expectation = expectation(
66+
for: .init(format: "exists == false"),
67+
evaluatedWith: app.staticTexts["Create a Passkey"])
68+
let result = XCTWaiter.wait(for: [expectation], timeout: 5.0)
69+
XCTAssertEqual(result, .completed)
70+
71+
assertSnapshot()
72+
}
73+
}
79.5 KB
Loading
199 KB
Loading
199 KB
Loading

0 commit comments

Comments
 (0)