mirror of
https://github.com/bitwarden/android.git
synced 2026-11-19 17:40:12 -06:00
BIT-540 Adding Custom Field Edit Actions (#723)
This commit is contained in:
committed by
Álison Fernandes
parent
9cc8763642
commit
17eb3e2e0b
+122
-6
@@ -37,6 +37,7 @@ import com.x8bit.bitwarden.ui.util.onAllNodesWithContentDescriptionAfterScroll
|
||||
import com.x8bit.bitwarden.ui.util.onAllNodesWithTextAfterScroll
|
||||
import com.x8bit.bitwarden.ui.util.onNodeWithContentDescriptionAfterScroll
|
||||
import com.x8bit.bitwarden.ui.util.onNodeWithTextAfterScroll
|
||||
import com.x8bit.bitwarden.ui.vault.feature.addedit.model.CustomFieldAction
|
||||
import com.x8bit.bitwarden.ui.vault.feature.addedit.model.CustomFieldType
|
||||
import com.x8bit.bitwarden.ui.vault.model.VaultAddEditType
|
||||
import com.x8bit.bitwarden.ui.vault.model.VaultCardBrand
|
||||
@@ -1939,7 +1940,7 @@ class VaultAddEditScreenTest : BaseComposeTest() {
|
||||
verify {
|
||||
viewModel.trySendAction(
|
||||
VaultAddEditAction.Common.CustomFieldValueChange(
|
||||
VaultAddEditState.Custom.TextField("Test ID", "TestText", ""),
|
||||
VaultAddEditState.Custom.TextField("Test ID 2", "TestText", ""),
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -1957,7 +1958,7 @@ class VaultAddEditScreenTest : BaseComposeTest() {
|
||||
verify {
|
||||
viewModel.trySendAction(
|
||||
VaultAddEditAction.Common.CustomFieldValueChange(
|
||||
VaultAddEditState.Custom.HiddenField("Test ID", "TestHidden", ""),
|
||||
VaultAddEditState.Custom.HiddenField("Test ID 3", "TestHidden", ""),
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -1975,7 +1976,122 @@ class VaultAddEditScreenTest : BaseComposeTest() {
|
||||
verify {
|
||||
viewModel.trySendAction(
|
||||
VaultAddEditAction.Common.CustomFieldValueChange(
|
||||
VaultAddEditState.Custom.BooleanField("Test ID", "TestBoolean", true),
|
||||
VaultAddEditState.Custom.BooleanField("Test ID 1", "TestBoolean", true),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `clicking custom field edit icon and Edit option sends a CustomFieldValueChange action`() {
|
||||
mutableStateFlow.value = DEFAULT_STATE_SECURE_NOTES_CUSTOM_FIELDS
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithContentDescriptionAfterScroll("Edit")
|
||||
.onFirst()
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("Edit")
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("Name")
|
||||
.performTextInput("NewTestBooleanName")
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("Ok")
|
||||
.performClick()
|
||||
|
||||
verify {
|
||||
viewModel.trySendAction(
|
||||
VaultAddEditAction.Common.CustomFieldValueChange(
|
||||
VaultAddEditState.Custom.BooleanField("Test ID 1", "NewTestBooleanName", false),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `clicking custom field edit icon and Delete option sends a CustomFieldActionSelect delete action`() {
|
||||
mutableStateFlow.value = DEFAULT_STATE_SECURE_NOTES_CUSTOM_FIELDS
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithContentDescriptionAfterScroll("Edit")
|
||||
.onFirst()
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("Delete")
|
||||
.performClick()
|
||||
|
||||
verify {
|
||||
viewModel.trySendAction(
|
||||
VaultAddEditAction.Common.CustomFieldActionSelect(
|
||||
customFieldAction = CustomFieldAction.DELETE,
|
||||
customField = VaultAddEditState.Custom.BooleanField(
|
||||
itemId = "Test ID 1",
|
||||
name = "TestBoolean",
|
||||
value = false,
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `clicking custom field edit icon and Move down option sends a CustomFieldActionSelect move down action`() {
|
||||
mutableStateFlow.value = DEFAULT_STATE_SECURE_NOTES_CUSTOM_FIELDS
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithContentDescriptionAfterScroll("Edit")
|
||||
.onFirst()
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("Move down")
|
||||
.performClick()
|
||||
|
||||
verify {
|
||||
viewModel.trySendAction(
|
||||
VaultAddEditAction.Common.CustomFieldActionSelect(
|
||||
customFieldAction = CustomFieldAction.MOVE_DOWN,
|
||||
customField = VaultAddEditState.Custom.BooleanField(
|
||||
itemId = "Test ID 1",
|
||||
name = "TestBoolean",
|
||||
value = false,
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MaxLineLength")
|
||||
@Test
|
||||
fun `clicking custom field edit icon and Move Up options sends a CustomFieldActionSelect move up action`() {
|
||||
mutableStateFlow.value = DEFAULT_STATE_SECURE_NOTES_CUSTOM_FIELDS
|
||||
|
||||
composeTestRule
|
||||
.onAllNodesWithContentDescriptionAfterScroll("Edit")
|
||||
.onFirst()
|
||||
.performClick()
|
||||
|
||||
composeTestRule
|
||||
.onNodeWithText("Move Up")
|
||||
.performClick()
|
||||
|
||||
verify {
|
||||
viewModel.trySendAction(
|
||||
VaultAddEditAction.Common.CustomFieldActionSelect(
|
||||
customFieldAction = CustomFieldAction.MOVE_UP,
|
||||
customField = VaultAddEditState.Custom.BooleanField(
|
||||
itemId = "Test ID 1",
|
||||
name = "TestBoolean",
|
||||
value = false,
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
@@ -2111,10 +2227,10 @@ class VaultAddEditScreenTest : BaseComposeTest() {
|
||||
viewState = VaultAddEditState.ViewState.Content(
|
||||
common = VaultAddEditState.ViewState.Content.Common(
|
||||
customFieldData = listOf(
|
||||
VaultAddEditState.Custom.BooleanField("Test ID", "TestBoolean", false),
|
||||
VaultAddEditState.Custom.TextField("Test ID", "TestText", "TestTextVal"),
|
||||
VaultAddEditState.Custom.BooleanField("Test ID 1", "TestBoolean", false),
|
||||
VaultAddEditState.Custom.TextField("Test ID 2", "TestText", "TestTextVal"),
|
||||
VaultAddEditState.Custom.HiddenField(
|
||||
"Test ID",
|
||||
"Test ID 3",
|
||||
"TestHidden",
|
||||
"TestHiddenVal",
|
||||
),
|
||||
|
||||
+196
@@ -18,6 +18,7 @@ import com.x8bit.bitwarden.ui.platform.base.util.Text
|
||||
import com.x8bit.bitwarden.ui.platform.base.util.asText
|
||||
import com.x8bit.bitwarden.ui.platform.manager.resource.ResourceManager
|
||||
import com.x8bit.bitwarden.ui.tools.feature.generator.model.GeneratorMode
|
||||
import com.x8bit.bitwarden.ui.vault.feature.addedit.model.CustomFieldAction
|
||||
import com.x8bit.bitwarden.ui.vault.feature.addedit.model.CustomFieldType
|
||||
import com.x8bit.bitwarden.ui.vault.feature.addedit.model.toCustomField
|
||||
import com.x8bit.bitwarden.ui.vault.feature.addedit.util.toViewState
|
||||
@@ -1444,6 +1445,201 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `CustomFieldValueChange should update name field`() = runTest {
|
||||
val initState = createVaultAddItemState(
|
||||
typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.SecureNotes,
|
||||
commonContentViewState = VaultAddEditState.ViewState.Content.Common(
|
||||
customFieldData = listOf(
|
||||
VaultAddEditState.Custom.BooleanField(
|
||||
"TestId 3",
|
||||
"Boolean Field",
|
||||
true,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
assertCustomFieldValueChange(
|
||||
initState,
|
||||
CustomFieldType.BOOLEAN,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `CustomFieldActionSelect with delete action should delete the item`() = runTest {
|
||||
val customFieldData = VaultAddEditState.Custom.BooleanField(
|
||||
"TestId 3",
|
||||
"Boolean Field",
|
||||
true,
|
||||
)
|
||||
|
||||
val initState = createVaultAddItemState(
|
||||
typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.SecureNotes,
|
||||
commonContentViewState = VaultAddEditState.ViewState.Content.Common(
|
||||
customFieldData = listOf(customFieldData),
|
||||
),
|
||||
)
|
||||
|
||||
val viewModel = createAddVaultItemViewModel(
|
||||
savedStateHandle = createSavedStateHandleWithState(
|
||||
state = initState,
|
||||
vaultAddEditType = VaultAddEditType.AddItem,
|
||||
),
|
||||
)
|
||||
val currentContentState =
|
||||
(viewModel.stateFlow.value.viewState as VaultAddEditState.ViewState.Content)
|
||||
val expectedState = currentContentState
|
||||
.copy(
|
||||
common = currentContentState.common.copy(
|
||||
customFieldData = listOf(),
|
||||
),
|
||||
)
|
||||
|
||||
viewModel.actionChannel.trySend(
|
||||
VaultAddEditAction.Common.CustomFieldActionSelect(
|
||||
CustomFieldAction.DELETE,
|
||||
customFieldData,
|
||||
),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expectedState,
|
||||
viewModel.stateFlow.value.viewState,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `CustomFieldActionSelect with move up action should move the item up`() = runTest {
|
||||
val customFieldData =
|
||||
VaultAddEditState.Custom.BooleanField(
|
||||
"TestId 3",
|
||||
"Boolean Field",
|
||||
true,
|
||||
)
|
||||
|
||||
val initState = createVaultAddItemState(
|
||||
typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.SecureNotes,
|
||||
commonContentViewState = VaultAddEditState.ViewState.Content.Common(
|
||||
customFieldData = listOf(
|
||||
VaultAddEditState.Custom.BooleanField(
|
||||
"TestId 1",
|
||||
"Boolean Field",
|
||||
true,
|
||||
), VaultAddEditState.Custom.BooleanField(
|
||||
"TestId 3",
|
||||
"Boolean Field",
|
||||
true,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
val viewModel = createAddVaultItemViewModel(
|
||||
savedStateHandle = createSavedStateHandleWithState(
|
||||
state = initState,
|
||||
vaultAddEditType = VaultAddEditType.AddItem,
|
||||
),
|
||||
)
|
||||
val currentContentState =
|
||||
(viewModel.stateFlow.value.viewState as VaultAddEditState.ViewState.Content)
|
||||
val expectedState = currentContentState
|
||||
.copy(
|
||||
common = currentContentState.common.copy(
|
||||
customFieldData = listOf(
|
||||
VaultAddEditState.Custom.BooleanField(
|
||||
"TestId 3",
|
||||
"Boolean Field",
|
||||
true,
|
||||
),
|
||||
VaultAddEditState.Custom.BooleanField(
|
||||
"TestId 1",
|
||||
"Boolean Field",
|
||||
true,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
viewModel.actionChannel.trySend(
|
||||
VaultAddEditAction.Common.CustomFieldActionSelect(
|
||||
CustomFieldAction.MOVE_UP,
|
||||
customFieldData,
|
||||
),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expectedState,
|
||||
viewModel.stateFlow.value.viewState,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `CustomFieldActionSelect with move down action should move the item down`() = runTest {
|
||||
val customFieldData =
|
||||
VaultAddEditState.Custom.BooleanField(
|
||||
"TestId 1",
|
||||
"Boolean Field",
|
||||
true,
|
||||
)
|
||||
|
||||
val initState = createVaultAddItemState(
|
||||
typeContentViewState = VaultAddEditState.ViewState.Content.ItemType.SecureNotes,
|
||||
commonContentViewState = VaultAddEditState.ViewState.Content.Common(
|
||||
customFieldData = listOf(
|
||||
VaultAddEditState.Custom.BooleanField(
|
||||
"TestId 1",
|
||||
"Boolean Field",
|
||||
true,
|
||||
),
|
||||
VaultAddEditState.Custom.BooleanField(
|
||||
"TestId 3",
|
||||
"Boolean Field",
|
||||
true,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
val viewModel = createAddVaultItemViewModel(
|
||||
savedStateHandle = createSavedStateHandleWithState(
|
||||
state = initState,
|
||||
vaultAddEditType = VaultAddEditType.AddItem,
|
||||
),
|
||||
)
|
||||
val currentContentState =
|
||||
(viewModel.stateFlow.value.viewState as VaultAddEditState.ViewState.Content)
|
||||
val expectedState = currentContentState
|
||||
.copy(
|
||||
common = currentContentState.common.copy(
|
||||
customFieldData = listOf(
|
||||
VaultAddEditState.Custom.BooleanField(
|
||||
"TestId 3",
|
||||
"Boolean Field",
|
||||
true,
|
||||
),
|
||||
VaultAddEditState.Custom.BooleanField(
|
||||
"TestId 1",
|
||||
"Boolean Field",
|
||||
true,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
viewModel.actionChannel.trySend(
|
||||
VaultAddEditAction.Common.CustomFieldActionSelect(
|
||||
CustomFieldAction.MOVE_DOWN,
|
||||
customFieldData,
|
||||
),
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
expectedState,
|
||||
viewModel.stateFlow.value.viewState,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `TooltipClick should emit ShowToast with 'Tooltip' message`() = runTest {
|
||||
viewModel.eventFlow.test {
|
||||
|
||||
Reference in New Issue
Block a user