1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-12-22 16:29:09 +01:00

[PM-2089] Fix Collections not nesting properly in the Org Vault (#5369)

This commit is contained in:
Robyn MacCallum 2023-05-08 13:22:06 -04:00 committed by GitHub
parent 0b9ed77b8e
commit 9bbaae6ef2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 1 deletions

View File

@ -0,0 +1,28 @@
import { CollectionView } from "@bitwarden/common/admin-console/models/view/collection.view";
import { getNestedCollectionTree } from "./collection-utils";
describe("CollectionUtils Service", () => {
describe("getNestedCollectionTree", () => {
it("should return collections properly sorted if provided out of order", () => {
// Arrange
const collections: CollectionView[] = [];
const parentCollection = new CollectionView();
parentCollection.name = "Parent";
const childCollection = new CollectionView();
childCollection.name = "Parent/Child";
collections.push(childCollection);
collections.push(parentCollection);
// Act
const result = getNestedCollectionTree(collections);
// Assert
expect(result[0].node.name).toBe("Parent");
expect(result[0].children[0].node.name).toBe("Child");
});
});
});

View File

@ -17,7 +17,9 @@ export function getNestedCollectionTree(
// Collections need to be cloned because ServiceUtils.nestedTraverse actively // Collections need to be cloned because ServiceUtils.nestedTraverse actively
// modifies the names of collections. // modifies the names of collections.
// These changes risk affecting collections store in StateService. // These changes risk affecting collections store in StateService.
const clonedCollections = collections.map(cloneCollection); const clonedCollections = collections
.sort((a, b) => a.name.localeCompare(b.name))
.map(cloneCollection);
const nodes: TreeNode<CollectionView | CollectionAdminView>[] = []; const nodes: TreeNode<CollectionView | CollectionAdminView>[] = [];
clonedCollections.forEach((collection) => { clonedCollections.forEach((collection) => {