mirror of
https://github.com/bitwarden/android.git
synced 2026-06-02 02:36:58 -05:00
Add BitwardenStepper component (#226)
This commit is contained in:
@@ -32,6 +32,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.emptyFlow
|
||||
import org.junit.Test
|
||||
|
||||
@Suppress("LargeClass")
|
||||
class GeneratorScreenTest : BaseComposeTest() {
|
||||
private val mutableStateFlow = MutableStateFlow(
|
||||
GeneratorState(
|
||||
@@ -409,6 +410,70 @@ class GeneratorScreenTest : BaseComposeTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `in Passcode_Password state, decrementing the minimum numbers counter below 0 should do nothing`() {
|
||||
val initialMinNumbers = 0
|
||||
updateState(
|
||||
GeneratorState(
|
||||
generatedText = "Placeholder",
|
||||
selectedType = GeneratorState
|
||||
.MainType
|
||||
.Passcode(
|
||||
GeneratorState
|
||||
.MainType
|
||||
.Passcode
|
||||
.PasscodeType
|
||||
.Password(minNumbers = initialMinNumbers),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
composeTestRule.setContent {
|
||||
GeneratorScreen(viewModel = viewModel)
|
||||
}
|
||||
|
||||
composeTestRule.onNodeWithContentDescription("Minimum numbers, $initialMinNumbers")
|
||||
.onChildren()
|
||||
.filterToOne(hasContentDescription("\u2212"))
|
||||
.performScrollTo()
|
||||
.performClick()
|
||||
|
||||
verify(exactly = 0) { viewModel.trySendAction(any()) }
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `in Passcode_Password state, incrementing the minimum numbers counter above 5 should do nothing`() {
|
||||
val initialMinNumbers = 5
|
||||
updateState(
|
||||
GeneratorState(
|
||||
generatedText = "Placeholder",
|
||||
selectedType = GeneratorState
|
||||
.MainType
|
||||
.Passcode(
|
||||
GeneratorState
|
||||
.MainType
|
||||
.Passcode
|
||||
.PasscodeType
|
||||
.Password(minNumbers = initialMinNumbers),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
composeTestRule.setContent {
|
||||
GeneratorScreen(viewModel = viewModel)
|
||||
}
|
||||
|
||||
composeTestRule.onNodeWithContentDescription("Minimum numbers, $initialMinNumbers")
|
||||
.onChildren()
|
||||
.filterToOne(hasContentDescription("+"))
|
||||
.performScrollTo()
|
||||
.performClick()
|
||||
|
||||
verify(exactly = 0) { viewModel.trySendAction(any()) }
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `in Passcode_Password state, decrementing the minimum special characters counter should send MinSpecialCharactersChange action`() {
|
||||
@@ -485,6 +550,70 @@ class GeneratorScreenTest : BaseComposeTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `in Passcode_Password state, decrementing the minimum special characters below 0 should do nothing`() {
|
||||
val initialSpecialChars = 0
|
||||
updateState(
|
||||
GeneratorState(
|
||||
generatedText = "Placeholder",
|
||||
selectedType = GeneratorState
|
||||
.MainType
|
||||
.Passcode(
|
||||
GeneratorState
|
||||
.MainType
|
||||
.Passcode
|
||||
.PasscodeType
|
||||
.Password(minSpecial = initialSpecialChars),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
composeTestRule.setContent {
|
||||
GeneratorScreen(viewModel = viewModel)
|
||||
}
|
||||
|
||||
composeTestRule.onNodeWithContentDescription("Minimum special, $initialSpecialChars")
|
||||
.onChildren()
|
||||
.filterToOne(hasContentDescription("\u2212"))
|
||||
.performScrollTo()
|
||||
.performClick()
|
||||
|
||||
verify(exactly = 0) { viewModel.trySendAction(any()) }
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `in Passcode_Password state, decrementing the minimum special characters above 5 should do nothing`() {
|
||||
val initialSpecialChars = 5
|
||||
updateState(
|
||||
GeneratorState(
|
||||
generatedText = "Placeholder",
|
||||
selectedType = GeneratorState
|
||||
.MainType
|
||||
.Passcode(
|
||||
GeneratorState
|
||||
.MainType
|
||||
.Passcode
|
||||
.PasscodeType
|
||||
.Password(minSpecial = initialSpecialChars),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
composeTestRule.setContent {
|
||||
GeneratorScreen(viewModel = viewModel)
|
||||
}
|
||||
|
||||
composeTestRule.onNodeWithContentDescription("Minimum special, $initialSpecialChars")
|
||||
.onChildren()
|
||||
.filterToOne(hasContentDescription("+"))
|
||||
.performScrollTo()
|
||||
.performClick()
|
||||
|
||||
verify(exactly = 0) { viewModel.trySendAction(any()) }
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `in Passcode_Password state, toggling the use avoid ambiguous characters toggle should send ToggleSpecialCharactersChange action`() {
|
||||
@@ -517,7 +646,7 @@ class GeneratorScreenTest : BaseComposeTest() {
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `in Passcode_Passphrase state, decrementing number of words should send NumWordsCounterChange action with decremented value`() {
|
||||
val initialNumWords = 3
|
||||
val initialNumWords = 4
|
||||
updateState(
|
||||
GeneratorState(
|
||||
generatedText = "Placeholder",
|
||||
@@ -528,7 +657,7 @@ class GeneratorScreenTest : BaseComposeTest() {
|
||||
.MainType
|
||||
.Passcode
|
||||
.PasscodeType
|
||||
.Passphrase(),
|
||||
.Passphrase(numWords = initialNumWords),
|
||||
),
|
||||
),
|
||||
)
|
||||
@@ -539,7 +668,7 @@ class GeneratorScreenTest : BaseComposeTest() {
|
||||
|
||||
// Unicode for "minus" used for content description
|
||||
composeTestRule
|
||||
.onNodeWithContentDescription("Number of words, 3")
|
||||
.onNodeWithContentDescription("Number of words, $initialNumWords")
|
||||
.onChildren()
|
||||
.filterToOne(hasContentDescription("\u2212"))
|
||||
.performScrollTo()
|
||||
@@ -554,6 +683,70 @@ class GeneratorScreenTest : BaseComposeTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `in Passcode_Passphrase state, decrementing number of words under 3 should do nothing`() {
|
||||
val initialNumWords = 3
|
||||
updateState(
|
||||
GeneratorState(
|
||||
generatedText = "Placeholder",
|
||||
selectedType = GeneratorState
|
||||
.MainType
|
||||
.Passcode(
|
||||
GeneratorState
|
||||
.MainType
|
||||
.Passcode
|
||||
.PasscodeType
|
||||
.Passphrase(numWords = initialNumWords),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
composeTestRule.setContent {
|
||||
GeneratorScreen(viewModel = viewModel)
|
||||
}
|
||||
|
||||
// Unicode for "minus" used for content description
|
||||
composeTestRule
|
||||
.onNodeWithContentDescription("Number of words, $initialNumWords")
|
||||
.onChildren()
|
||||
.filterToOne(hasContentDescription("\u2212"))
|
||||
.performScrollTo()
|
||||
.performClick()
|
||||
verify(exactly = 0) { viewModel.trySendAction(any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `in Passcode_Passphrase state, incrementing number of words over 20 should do nothing`() {
|
||||
val initialNumWords = 20
|
||||
updateState(
|
||||
GeneratorState(
|
||||
generatedText = "Placeholder",
|
||||
selectedType = GeneratorState
|
||||
.MainType
|
||||
.Passcode(
|
||||
GeneratorState
|
||||
.MainType
|
||||
.Passcode
|
||||
.PasscodeType
|
||||
.Passphrase(numWords = initialNumWords),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
composeTestRule.setContent {
|
||||
GeneratorScreen(viewModel = viewModel)
|
||||
}
|
||||
|
||||
// Unicode for "minus" used for content description
|
||||
composeTestRule
|
||||
.onNodeWithContentDescription("Number of words, $initialNumWords")
|
||||
.onChildren()
|
||||
.filterToOne(hasContentDescription("+"))
|
||||
.performScrollTo()
|
||||
.performClick()
|
||||
verify(exactly = 0) { viewModel.trySendAction(any()) }
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `in Passcode_Passphrase state, incrementing number of words should send NumWordsCounterChange action with incremented value`() {
|
||||
|
||||
@@ -248,6 +248,25 @@ class NewSendScreenTest : BaseComposeTest() {
|
||||
verify { viewModel.trySendAction(NewSendAction.MaxAccessCountChange(2)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `max access count decrement when set to 1 should do nothing`() =
|
||||
runTest {
|
||||
mutableStateFlow.update {
|
||||
it.copy(maxAccessCount = 1)
|
||||
}
|
||||
// Expand options section:
|
||||
composeTestRule
|
||||
.onNodeWithText("Options")
|
||||
.performScrollTo()
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithContentDescription("\u2212")
|
||||
.performScrollTo()
|
||||
.performClick()
|
||||
verify(exactly = 0) { viewModel.trySendAction(any()) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `on max access count increment should send MaxAccessCountChange`() = runTest {
|
||||
// Expand options section:
|
||||
|
||||
@@ -87,16 +87,6 @@ class NewSendViewModelTest : BaseViewModelTest() {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `MaxAccessCountChang below 1 should keep maxAccessCount at 1`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
viewModel.stateFlow.test {
|
||||
assertEquals(DEFAULT_STATE, awaitItem())
|
||||
viewModel.trySendAction(NewSendAction.MaxAccessCountChange(0))
|
||||
assertEquals(DEFAULT_STATE.copy(maxAccessCount = 1), awaitItem())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `TextChange should update text input`() = runTest {
|
||||
val viewModel = createViewModel()
|
||||
|
||||
Reference in New Issue
Block a user