[PM-12739] Updated generator maximum number and specials (#3994)

This commit is contained in:
aj-rosado 2024-09-30 19:33:27 +02:00 committed by GitHub
parent ad338a8fd6
commit d60c534e06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 69 additions and 12 deletions

View file

@ -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,
)

View file

@ -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
}
}

View file

@ -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(

View file

@ -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",