Skip to content

Commit

Permalink
PM-13856 - After enabling Autofill in Device Settings, user is stuck …
Browse files Browse the repository at this point in the history
…in a loop/does not see the all set screen (#1074)
  • Loading branch information
phil-livefront authored Oct 24, 2024
1 parent e4d2d38 commit 759d524
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
34 changes: 34 additions & 0 deletions BitwardenShared/UI/Auth/AuthRouterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,23 @@ final class AuthRouterTests: BitwardenTestCase { // swiftlint:disable:this type_
XCTAssertEqual(route, .autofillSetup)
}

/// `handleAndRoute(_:)` redirects `.didCompleteAuth` to `.complete` if the user still
/// needs to set up autofill but is within the app extension.
@MainActor
func test_handleAndRoute_didCompleteAuth_incompleteAutofill_withinAppExtension() async {
subject = AuthRouter(
isInAppExtension: true,
services: ServiceContainer.withMocks(
authRepository: authRepository
)
)
authRepository.activeAccount = .fixture()
stateService.activeAccount = .fixture()
stateService.accountSetupAutofill["1"] = .incomplete
let route = await subject.handleAndRoute(.didCompleteAuth)
XCTAssertEqual(route, .complete)
}

/// `handleAndRoute(_:)` redirects `.didCompleteAuth` to `.vaultUnlockSetup` if the user still
/// needs to set up a vault unlock method.
func test_handleAndRoute_didCompleteAuth_incompleteVaultSetup() async {
Expand All @@ -206,6 +223,23 @@ final class AuthRouterTests: BitwardenTestCase { // swiftlint:disable:this type_
XCTAssertEqual(route, .vaultUnlockSetup(.createAccount))
}

/// `handleAndRoute(_:)` redirects `.didCompleteAuth` to `.complete` if the user still
/// needs to set up a vault unlock method but is within the app extension.
@MainActor
func test_handleAndRoute_didCompleteAuth_incomplete_withinAppExtension() async {
subject = AuthRouter(
isInAppExtension: true,
services: ServiceContainer.withMocks(
authRepository: authRepository
)
)
authRepository.activeAccount = .fixture()
stateService.activeAccount = .fixture()
stateService.accountSetupVaultUnlock["1"] = .incomplete
let route = await subject.handleAndRoute(.didCompleteAuth)
XCTAssertEqual(route, .complete)
}

/// `handleAndRoute(_ :)` redirects `.didCompleteAuth` to `.landing` when there are no accounts.
func test_handleAndRoute_didCompleteAuth_noAccounts() async {
let route = await subject.handleAndRoute(.didCompleteAuth)
Expand Down
19 changes: 12 additions & 7 deletions BitwardenShared/UI/Auth/Extensions/AuthRouter+Redirects.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,21 @@ extension AuthRouter {
guard let account = try? await services.authRepository.getAccount() else {
return .landing
}

if account.profile.forcePasswordResetReason != nil {
return .updateMasterPassword
} else if await (try? services.stateService.getAccountSetupVaultUnlock()) == .incomplete {
return .vaultUnlockSetup(.createAccount)
} else if await (try? services.stateService.getAccountSetupAutofill()) == .incomplete {
return .autofillSetup
} else {
await setCarouselShownIfEnabled()
return .complete
}

if !isInAppExtension {
if await (try? services.stateService.getAccountSetupVaultUnlock()) == .incomplete {
return .vaultUnlockSetup(.createAccount)
} else if await (try? services.stateService.getAccountSetupAutofill()) == .incomplete {
return .autofillSetup
}
}

await setCarouselShownIfEnabled()
return .complete
}

/// Handles the `.didDeleteAccount`route and redirects the user to the correct screen
Expand Down

0 comments on commit 759d524

Please sign in to comment.