Skip to content

Commit 1e665db

Browse files
authored
🍒 [PM-21537] Fix remove individual vault collection selection cherrypick (#5261)
1 parent 04e0690 commit 1e665db

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

‎app/src/main/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditViewModel.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -960,11 +960,12 @@ class VaultAddEditViewModel @Inject constructor(
960960
) {
961961
updateCommonContent { currentCommonContentState ->
962962
currentCommonContentState.copy(
963+
selectedOwnerId = currentCommonContentState.selectedOwner?.id,
963964
availableOwners = currentCommonContentState
964965
.availableOwners
965966
.toUpdatedOwners(
966967
selectedCollectionId = action.collection.id,
967-
selectedOwnerId = currentCommonContentState.selectedOwnerId,
968+
selectedOwnerId = currentCommonContentState.selectedOwner?.id,
968969
),
969970
)
970971
}

‎app/src/test/java/com/x8bit/bitwarden/ui/vault/feature/addedit/VaultAddEditViewModelTest.kt

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4056,6 +4056,58 @@ class VaultAddEditViewModelTest : BaseViewModelTest() {
40564056
assertEquals(expectedState, viewModel.stateFlow.value)
40574057
}
40584058

4059+
@Suppress("MaxLineLength")
4060+
@Test
4061+
fun `CollectionSelect should update selectedOwnerId when isIndividualVaultDisabled is true`() =
4062+
runTest {
4063+
every {
4064+
policyManager.getActivePolicies(type = PolicyTypeJson.PERSONAL_OWNERSHIP)
4065+
} returns listOf(
4066+
SyncResponseJson.Policy(
4067+
organizationId = "Test Org",
4068+
id = "testId",
4069+
type = PolicyTypeJson.PERSONAL_OWNERSHIP,
4070+
isEnabled = true,
4071+
data = null,
4072+
),
4073+
)
4074+
4075+
val vaultAddEditType = VaultAddEditType.AddItem
4076+
val vaultItemCipherType = VaultItemCipherType.LOGIN
4077+
mutableVaultDataFlow.value = DataState.Loaded(
4078+
data = createVaultData(),
4079+
)
4080+
4081+
val viewModel = createAddVaultItemViewModel(
4082+
savedStateHandle = createSavedStateHandleWithState(
4083+
state = null,
4084+
vaultAddEditType = vaultAddEditType,
4085+
vaultItemCipherType = vaultItemCipherType,
4086+
),
4087+
)
4088+
4089+
val action = collectionSelectAction()
4090+
viewModel.trySendAction(action)
4091+
4092+
val expectedState = vaultAddItemInitialState.copy(
4093+
viewState = VaultAddEditState.ViewState.Content(
4094+
common = createCommonContentViewState(
4095+
availableOwners = listOf(
4096+
VaultAddEditState.Owner(
4097+
id = "organizationId",
4098+
name = "organizationName",
4099+
collections = emptyList(),
4100+
),
4101+
),
4102+
selectedOwnerId = "organizationId",
4103+
),
4104+
isIndividualVaultDisabled = true,
4105+
type = createLoginTypeContentViewState(),
4106+
),
4107+
)
4108+
assertEquals(expectedState, viewModel.stateFlow.value)
4109+
}
4110+
40594111
@Suppress("MaxLineLength")
40604112
@Test
40614113
fun `UserVerificationLockout should set isUserVerified to false and display Fido2ErrorDialog`() {

0 commit comments

Comments
 (0)