Update the Send max access count logic (#557)

This commit is contained in:
David Perez 2024-01-09 20:35:05 -06:00 committed by Álison Fernandes
parent 27ddac59b9
commit 49411f3e2f
4 changed files with 24 additions and 26 deletions

View file

@ -228,6 +228,7 @@ private fun AddSendOptions(
value = state.common.maxAccessCount,
onValueChange = addSendHandlers.onMaxAccessCountChange,
isDecrementEnabled = state.common.maxAccessCount != null,
range = 0..Int.MAX_VALUE,
modifier = Modifier
.padding(horizontal = 16.dp),
)

View file

@ -261,7 +261,9 @@ class AddSendViewModel @Inject constructor(
}
private fun handleMaxAccessCountChange(action: AddSendAction.MaxAccessCountChange) {
updateCommonContent { it.copy(maxAccessCount = action.value) }
updateCommonContent { common ->
common.copy(maxAccessCount = action.value.takeUnless { it == 0 })
}
}
private inline fun onContent(
@ -355,7 +357,6 @@ data class AddSendState(
@Parcelize
data class Common(
val name: String,
// Null here means "not set"
val maxAccessCount: Int?,
val passwordInput: String,
val noteInput: String,

View file

@ -306,29 +306,6 @@ class AddSendScreenTest : BaseComposeTest() {
verify { viewModel.trySendAction(AddSendAction.MaxAccessCountChange(2)) }
}
@Test
fun `max access count decrement when set to 1 should do nothing`() =
runTest {
mutableStateFlow.update {
it.copy(
viewState = DEFAULT_VIEW_STATE.copy(
common = DEFAULT_COMMON_STATE.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:

View file

@ -287,7 +287,7 @@ class AddSendViewModelTest : BaseViewModelTest() {
}
@Test
fun `MaxAccessCountChange should update maxAccessCount`() = runTest {
fun `MaxAccessCountChange should update maxAccessCount to value when non-zero`() = runTest {
val viewModel = createViewModel()
val expectedViewState = DEFAULT_VIEW_STATE.copy(
common = DEFAULT_COMMON_STATE.copy(maxAccessCount = 5),
@ -300,6 +300,25 @@ class AddSendViewModelTest : BaseViewModelTest() {
}
}
@Test
fun `MaxAccessCountChange should update maxAccessCount to null when zero`() = runTest {
val initialState = DEFAULT_STATE.copy(
viewState = DEFAULT_VIEW_STATE.copy(
common = DEFAULT_COMMON_STATE.copy(maxAccessCount = 5),
),
)
val expectedViewState = DEFAULT_VIEW_STATE.copy(
common = DEFAULT_COMMON_STATE.copy(maxAccessCount = null),
)
val viewModel = createViewModel(initialState)
viewModel.stateFlow.test {
assertEquals(initialState, awaitItem())
viewModel.trySendAction(AddSendAction.MaxAccessCountChange(0))
assertEquals(initialState.copy(viewState = expectedViewState), awaitItem())
}
}
@Test
fun `TextChange should update text input`() = runTest {
val viewModel = createViewModel()