mirror of
https://github.com/bitwarden/android.git
synced 2025-03-16 03:08:50 +03:00
[PM-12739] Updated generator maximum number and specials (#3994)
This commit is contained in:
parent
ad338a8fd6
commit
d60c534e06
4 changed files with 69 additions and 12 deletions
|
@ -68,6 +68,7 @@ import com.x8bit.bitwarden.ui.tools.feature.generator.model.GeneratorMode
|
|||
import kotlinx.collections.immutable.ImmutableList
|
||||
import kotlinx.collections.immutable.persistentListOf
|
||||
import kotlinx.collections.immutable.toImmutableList
|
||||
import kotlin.math.max
|
||||
|
||||
/**
|
||||
* Top level composable for the generator screen.
|
||||
|
@ -550,7 +551,7 @@ private fun ColumnScope.PasswordTypeContent(
|
|||
minNumbers = passwordTypeState.minNumbers,
|
||||
onPasswordMinNumbersCounterChange =
|
||||
passwordHandlers.onPasswordMinNumbersCounterChange,
|
||||
maxValue = passwordTypeState.maxNumbersAllowed,
|
||||
maxValue = max(passwordTypeState.maxNumbersAllowed, passwordTypeState.minNumbersAllowed),
|
||||
minValue = passwordTypeState.minNumbersAllowed,
|
||||
)
|
||||
|
||||
|
@ -560,7 +561,7 @@ private fun ColumnScope.PasswordTypeContent(
|
|||
minSpecial = passwordTypeState.minSpecial,
|
||||
onPasswordMinSpecialCharactersChange =
|
||||
passwordHandlers.onPasswordMinSpecialCharactersChange,
|
||||
maxValue = passwordTypeState.maxSpecialAllowed,
|
||||
maxValue = max(passwordTypeState.maxSpecialAllowed, passwordTypeState.minSpecialAllowed),
|
||||
minValue = passwordTypeState.minSpecialAllowed,
|
||||
)
|
||||
|
||||
|
|
|
@ -1862,7 +1862,7 @@ data class GeneratorState(
|
|||
const val PASSWORD_LENGTH_SLIDER_MIN: Int = 5
|
||||
const val PASSWORD_LENGTH_SLIDER_MAX: Int = 128
|
||||
const val PASSWORD_COUNTER_MIN: Int = 0
|
||||
const val PASSWORD_COUNTER_MAX: Int = 5
|
||||
const val PASSWORD_COUNTER_MAX: Int = 9
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -551,8 +551,8 @@ class GeneratorScreenTest : BaseComposeTest() {
|
|||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `in Passcode_Password state, incrementing the minimum numbers counter above 5 should do nothing`() {
|
||||
val initialMinNumbers = 5
|
||||
fun `in Passcode_Password state, incrementing the minimum numbers counter above 9 should do nothing`() {
|
||||
val initialMinNumbers = 9
|
||||
updateState(
|
||||
DEFAULT_STATE.copy(
|
||||
selectedType = GeneratorState.MainType.Passcode(
|
||||
|
@ -650,8 +650,8 @@ class GeneratorScreenTest : BaseComposeTest() {
|
|||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `in Passcode_Password state, decrementing the minimum special characters above 5 should do nothing`() {
|
||||
val initialSpecialChars = 5
|
||||
fun `in Passcode_Password state, decrementing the minimum special characters above 9 should do nothing`() {
|
||||
val initialSpecialChars = 9
|
||||
updateState(
|
||||
DEFAULT_STATE.copy(
|
||||
selectedType = GeneratorState.MainType.Passcode(
|
||||
|
@ -821,6 +821,35 @@ class GeneratorScreenTest : BaseComposeTest() {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `in Passcode_Password state, maximum numbers should match minimum if lower`() {
|
||||
val initialMinNumbers = 7
|
||||
val initialMaxNumbers = 5
|
||||
|
||||
updateState(
|
||||
DEFAULT_STATE.copy(
|
||||
selectedType = GeneratorState.MainType.Passcode(
|
||||
GeneratorState
|
||||
.MainType
|
||||
.Passcode
|
||||
.PasscodeType
|
||||
.Password(
|
||||
minNumbersAllowed = initialMinNumbers,
|
||||
maxNumbersAllowed = initialMaxNumbers,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("Minimum numbers")
|
||||
.assertTextEquals("Minimum numbers", "7")
|
||||
.onSiblings()
|
||||
.filterToOne(hasContentDescription("\u2212"))
|
||||
.performScrollTo()
|
||||
.assertIsDisplayed()
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `in Passcode_Password state, minimum special characters cannot go below minimum threshold`() {
|
||||
|
@ -856,6 +885,34 @@ class GeneratorScreenTest : BaseComposeTest() {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `in Passcode_Password state, maximum special should match minimum if lower `() {
|
||||
val initialMinSpecials = 7
|
||||
val initialMaxSpecials = 5
|
||||
|
||||
updateState(
|
||||
DEFAULT_STATE.copy(
|
||||
selectedType = GeneratorState.MainType.Passcode(
|
||||
GeneratorState
|
||||
.MainType
|
||||
.Passcode
|
||||
.PasscodeType
|
||||
.Password(
|
||||
minSpecialAllowed = initialMinSpecials,
|
||||
maxSpecialAllowed = initialMaxSpecials,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
composeTestRule.onNodeWithText("Minimum special")
|
||||
.assertTextEquals("Minimum special", "7")
|
||||
.onSiblings()
|
||||
.filterToOne(hasContentDescription("\u2212"))
|
||||
.performScrollTo()
|
||||
.performClick()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `in Passcode_Passphrase state, disabled elements should not send events`() {
|
||||
updateState(
|
||||
|
|
|
@ -228,10 +228,10 @@ class GeneratorViewModelTest : BaseViewModelTest() {
|
|||
specialCharsEnabled = false,
|
||||
minNumbers = 3,
|
||||
minNumbersAllowed = 3,
|
||||
maxNumbersAllowed = 5,
|
||||
maxNumbersAllowed = 9,
|
||||
minSpecial = 3,
|
||||
minSpecialAllowed = 3,
|
||||
maxSpecialAllowed = 5,
|
||||
maxSpecialAllowed = 9,
|
||||
avoidAmbiguousChars = false,
|
||||
ambiguousCharsEnabled = true,
|
||||
isUserInteracting = false,
|
||||
|
@ -262,10 +262,10 @@ class GeneratorViewModelTest : BaseViewModelTest() {
|
|||
specialCharsEnabled = true,
|
||||
minNumbers = 3,
|
||||
minNumbersAllowed = 0,
|
||||
maxNumbersAllowed = 5,
|
||||
maxNumbersAllowed = 9,
|
||||
minSpecial = 3,
|
||||
minSpecialAllowed = 0,
|
||||
maxSpecialAllowed = 5,
|
||||
maxSpecialAllowed = 9,
|
||||
avoidAmbiguousChars = false,
|
||||
ambiguousCharsEnabled = true,
|
||||
isUserInteracting = false,
|
||||
|
@ -985,7 +985,6 @@ class GeneratorViewModelTest : BaseViewModelTest() {
|
|||
capitalizeEnabled = true,
|
||||
includeNumber = false,
|
||||
includeNumberEnabled = true,
|
||||
|
||||
),
|
||||
),
|
||||
generatedText = "updatedPassphrase",
|
||||
|
|
Loading…
Add table
Reference in a new issue