1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00
lens/src/common/utils/composite/get-composite-paths/get-composite-paths.test.ts
Iku-turso 5b9ce7bbb2 Make composite not care about in formatting of ids
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
2022-10-21 14:24:45 +03:00

62 lines
1.5 KiB
TypeScript

/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import getComposite from "../get-composite/get-composite";
import { getCompositePaths } from "./get-composite-paths";
describe("get-composite-paths", () => {
it("given composite with ordered children, returns ordered paths", () => {
const someRootItem = {
id: "some-root-id",
};
const someChildItem1 = {
id: "some-child-id-1",
parentId: "some-root-id",
orderNumber: 1,
};
const someChildItem2 = {
id: "some-child-id-2",
parentId: "some-root-id",
orderNumber: 2,
};
const someGrandchildItem1 = {
id: "some-grandchild-id-1",
parentId: "some-child-id-1",
orderNumber: 1,
};
const someGrandchildItem2 = {
id: "some-grandchild-id-2",
parentId: "some-child-id-1",
orderNumber: 2,
};
const items = [
someRootItem,
// Note: not in order yet.
someChildItem2,
someChildItem1,
someGrandchildItem2,
someGrandchildItem1,
];
const composite = getComposite({
source: items,
});
const actual = getCompositePaths(composite);
expect(actual).toEqual([
"some-root-id",
"some-root-id -> some-child-id-1",
"some-root-id -> some-child-id-1 -> some-grandchild-id-1",
"some-root-id -> some-child-id-1 -> some-grandchild-id-2",
"some-root-id -> some-child-id-2",
]);
});
});