[PM-10065] Use appropriate back behavior depending on how you are take to auth approval screen (#3695)
Some checks failed
Crowdin Push / Crowdin Push (push) Waiting to run
Scan / Check PR run (push) Failing after 0s
Scan / SAST scan (push) Has been skipped
Scan / Quality scan (push) Has been skipped
Test / Check PR run (push) Failing after 0s
Test / Test (push) Has been skipped

This commit is contained in:
Dave Severns 2024-08-08 11:37:20 -04:00 committed by GitHub
parent f17289a104
commit a57a7e099c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 86 additions and 8 deletions

View file

@ -108,7 +108,7 @@ class LoginApprovalViewModel @Inject constructor(
}
private fun handleCloseClicked() {
closeScreen()
sendClosingEvent()
}
private fun handleDeclineRequestClicked() {
@ -138,7 +138,7 @@ class LoginApprovalViewModel @Inject constructor(
when (action.result) {
is AuthRequestResult.Success -> {
sendEvent(LoginApprovalEvent.ShowToast(R.string.login_approved.asText()))
sendEvent(LoginApprovalEvent.NavigateBack)
sendClosingEvent()
}
is AuthRequestResult.Error -> {
@ -184,7 +184,7 @@ class LoginApprovalViewModel @Inject constructor(
AuthRequestUpdatesResult.Declined,
AuthRequestUpdatesResult.Expired,
-> {
closeScreen()
sendClosingEvent()
}
}
}
@ -195,7 +195,7 @@ class LoginApprovalViewModel @Inject constructor(
when (action.result) {
is AuthRequestResult.Success -> {
sendEvent(LoginApprovalEvent.ShowToast(R.string.log_in_denied.asText()))
sendEvent(LoginApprovalEvent.NavigateBack)
sendClosingEvent()
}
is AuthRequestResult.Error -> {
@ -206,12 +206,14 @@ class LoginApprovalViewModel @Inject constructor(
}
}
private fun closeScreen() {
if (state.specialCircumstance?.shouldFinishWhenComplete == true) {
sendEvent(LoginApprovalEvent.ExitApp)
private fun sendClosingEvent() {
val event = if (state.specialCircumstance?.shouldFinishWhenComplete == true) {
LoginApprovalEvent.ExitApp
} else {
sendEvent(LoginApprovalEvent.NavigateBack)
LoginApprovalEvent.NavigateBack
}
sendEvent(event)
}
}

View file

@ -189,6 +189,44 @@ class LoginApprovalViewModelTest : BaseViewModelTest() {
}
}
@Test
@Suppress("MaxLineLength")
fun `When approval request is successful, should emit ExitApp when shouldFinishWhenComplete is true`() =
runTest {
val specialCircumstance = SpecialCircumstance.PasswordlessRequest(
passwordlessRequestData = PasswordlessRequestData(
loginRequestId = REQUEST_ID,
userId = USER_ID,
),
shouldFinishWhenComplete = true,
)
every {
mockSpecialCircumstanceManager.specialCircumstance
} returns specialCircumstance
val viewModel = createViewModel(
state = DEFAULT_STATE.copy(
specialCircumstance = specialCircumstance,
),
)
coEvery {
mockAuthRepository.updateAuthRequest(
requestId = REQUEST_ID,
masterPasswordHash = PASSWORD_HASH,
publicKey = PUBLIC_KEY,
isApproved = true,
)
} returns AuthRequestResult.Success(AUTH_REQUEST)
viewModel.eventFlow.test {
viewModel.trySendAction(LoginApprovalAction.ApproveRequestClick)
assertEquals(
LoginApprovalEvent.ShowToast(R.string.login_approved.asText()),
awaitItem(),
)
assertEquals(LoginApprovalEvent.ExitApp, awaitItem())
}
}
@Test
fun `on DeclineRequestClick should deny auth request`() = runTest {
val viewModel = createViewModel()
@ -220,6 +258,44 @@ class LoginApprovalViewModelTest : BaseViewModelTest() {
}
}
@Test
@Suppress("MaxLineLength")
fun `When deny request is successful, should emit ExitApp when shouldFinishWhenComplete is true`() =
runTest {
val specialCircumstance = SpecialCircumstance.PasswordlessRequest(
passwordlessRequestData = PasswordlessRequestData(
loginRequestId = REQUEST_ID,
userId = USER_ID,
),
shouldFinishWhenComplete = true,
)
every {
mockSpecialCircumstanceManager.specialCircumstance
} returns specialCircumstance
val viewModel = createViewModel(
state = DEFAULT_STATE.copy(
specialCircumstance = specialCircumstance,
),
)
coEvery {
mockAuthRepository.updateAuthRequest(
requestId = REQUEST_ID,
masterPasswordHash = PASSWORD_HASH,
publicKey = PUBLIC_KEY,
isApproved = false,
)
} returns AuthRequestResult.Success(AUTH_REQUEST)
viewModel.eventFlow.test {
viewModel.trySendAction(LoginApprovalAction.DeclineRequestClick)
assertEquals(
LoginApprovalEvent.ShowToast(R.string.log_in_denied.asText()),
awaitItem(),
)
assertEquals(LoginApprovalEvent.ExitApp, awaitItem())
}
}
@Test
fun `on ErrorDialogDismiss should update state`() = runTest {
val viewModel = createViewModel()