Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ internal sealed class ChallengeAction : Parcelable {
@Parcelize
data class NativeForm(
internal val userEntry: String,
internal val whitelistingValue: Boolean
internal val whitelistingValue: Boolean?
) : ChallengeAction()

@Parcelize
Expand All @@ -17,7 +17,7 @@ internal sealed class ChallengeAction : Parcelable {

@Parcelize
data class Oob(
internal val whitelistingValue: Boolean
internal val whitelistingValue: Boolean?
) : ChallengeAction()

@Parcelize
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,16 @@ internal class ChallengeFragment(

private val challengeAction: ChallengeAction
get() {
val whitelistingSelection = if (cresData.whitelistingInfoText.isNullOrEmpty()) {
null
} else {
challengeZoneView.whitelistingSelection
}

return when (cresData.uiType) {
UiType.OutOfBand -> ChallengeAction.Oob(challengeZoneView.whitelistingSelection)
UiType.OutOfBand -> ChallengeAction.Oob(whitelistingSelection)
UiType.Html -> ChallengeAction.HtmlForm(userEntry)
else -> ChallengeAction.NativeForm(userEntry, challengeZoneView.whitelistingSelection)
else -> ChallengeAction.NativeForm(userEntry, whitelistingSelection)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class ChallengeFragmentTest {

assertThat(challengeActionHandler.actions)
.containsExactly(
ChallengeAction.NativeForm("123456", whitelistingValue = false)
ChallengeAction.NativeForm("123456", whitelistingValue = null)
)
}
}
Expand Down Expand Up @@ -273,6 +273,90 @@ class ChallengeFragmentTest {
}
}

@Test
fun `native form whitelisting value is true if whitelistingInfoText is present and button checked`() {
createFragment(
cres = CRES_TEXT_DATA
) { fragment ->
fragment.challengeZoneView.setWhitelistChecked(true)
fragment.clickSubmitButton()
val action = challengeActionHandler
.actions[challengeActionHandler.actions.lastIndex] as? ChallengeAction.NativeForm

assertThat(action?.whitelistingValue).isTrue()
}
}

@Test
fun `oob whitelisting value is true if whitelistingInfoText is present and button checked`() {
createFragment(
cres = CRES_OOB_DATA.copy(whitelistingInfoText = "Whitelisting text is present")
) { fragment ->
fragment.challengeZoneView.setWhitelistChecked(true)
fragment.clickSubmitButton()
val action = challengeActionHandler
.actions[challengeActionHandler.actions.lastIndex] as? ChallengeAction.Oob

assertThat(action?.whitelistingValue).isTrue()
}
}

@Test
fun `native form whitelisting value is null if whitelistingInfoText is null and button checked`() {
createFragment(
cres = CRES_TEXT_DATA.copy(whitelistingInfoText = null)
) { fragment ->
fragment.challengeZoneView.setWhitelistChecked(true)
fragment.clickSubmitButton()
val action = challengeActionHandler
.actions[challengeActionHandler.actions.lastIndex] as? ChallengeAction.NativeForm

assertThat(action?.whitelistingValue).isNull()
}
}

@Test
fun `OOB whitelisting value is null if whitelistingInfoText is null and button checked`() {
createFragment(
cres = CRES_OOB_DATA.copy(whitelistingInfoText = null)
) { fragment ->
fragment.challengeZoneView.setWhitelistChecked(true)
fragment.clickSubmitButton()
val action = challengeActionHandler
.actions[challengeActionHandler.actions.lastIndex] as? ChallengeAction.Oob

assertThat(action?.whitelistingValue).isNull()
}
}

@Test
fun `native form whitelisting value is false if whitelistingInfoText is present and button not checked`() {
createFragment(
cres = CRES_TEXT_DATA
) { fragment ->
fragment.challengeZoneView.setWhitelistChecked(false)
fragment.clickSubmitButton()
val action = challengeActionHandler
.actions[challengeActionHandler.actions.lastIndex] as? ChallengeAction.NativeForm

assertThat(action?.whitelistingValue).isFalse()
}
}

@Test
fun `oob whitelisting value is false if whitelistingInfoText is present and button not checked`() {
createFragment(
cres = CRES_OOB_DATA.copy(whitelistingInfoText = "Whitelisting text exists")
) { fragment ->
fragment.challengeZoneView.setWhitelistChecked(false)
fragment.clickSubmitButton()
val action = challengeActionHandler
.actions[challengeActionHandler.actions.lastIndex] as? ChallengeAction.Oob

assertThat(action?.whitelistingValue).isFalse()
}
}

private fun createFragment(
cres: ChallengeResponseData? = ChallengeMessageFixtures.CRES_TEXT_DATA,
onFragment: (ChallengeFragment) -> Unit
Expand Down
Loading