1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Consolidate tests to now point-free composite

Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
Iku-turso 2022-10-24 12:49:00 +03:00
parent e9d951920c
commit 2a2ab66a44
4 changed files with 55 additions and 21 deletions

View File

@ -4,11 +4,11 @@
*/ */
import type { Composite } from "../get-composite/get-composite"; import type { Composite } from "../get-composite/get-composite";
import getComposite from "../get-composite/get-composite";
import { compositeHasDescendant } from "./composite-has-descendant"; import { compositeHasDescendant } from "./composite-has-descendant";
import getCompositeFor from "../get-composite/get-composite";
describe("composite-has-descendant, given composite with children and grand children", () => { describe("composite-has-descendant, given composite with children and grand children", () => {
let composite: Composite<{ id: string; parentId: string | undefined }>; let composite: Composite<{ id: string; parentId?: string }>;
beforeEach(() => { beforeEach(() => {
const items = [ const items = [
@ -21,7 +21,16 @@ describe("composite-has-descendant, given composite with children and grand chil
}, },
]; ];
composite = getComposite({ source: items }); const getComposite = getCompositeFor<{
id: string;
parentId?: string;
}>({
rootId: "some-root-id",
getId: (x) => x.id,
getParentId: (x) => x.parentId,
});
composite = getComposite(items);
}); });
it("has a child as descendant", () => { it("has a child as descendant", () => {
@ -34,7 +43,8 @@ describe("composite-has-descendant, given composite with children and grand chil
it("has a grand child as descendant", () => { it("has a grand child as descendant", () => {
const actual = compositeHasDescendant<typeof composite["value"]>( const actual = compositeHasDescendant<typeof composite["value"]>(
(referenceComposite) => referenceComposite.value.id === "some-grand-child-item", (referenceComposite) =>
referenceComposite.value.id === "some-grand-child-item",
)(composite); )(composite);
expect(actual).toBe(true); expect(actual).toBe(true);
@ -42,7 +52,8 @@ describe("composite-has-descendant, given composite with children and grand chil
it("does not have an unrelated descendant", () => { it("does not have an unrelated descendant", () => {
const actual = compositeHasDescendant<typeof composite["value"]>( const actual = compositeHasDescendant<typeof composite["value"]>(
(referenceComposite) => referenceComposite.value.id === "some-unknown-item", (referenceComposite) =>
referenceComposite.value.id === "some-unknown-item",
)(composite); )(composite);
expect(actual).toBe(false); expect(actual).toBe(false);

View File

@ -3,23 +3,28 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import type { Composite } from "../get-composite/get-composite"; import type { Composite } from "../get-composite/get-composite";
import getComposite from "../get-composite/get-composite";
import { findComposite } from "./find-composite"; import { findComposite } from "./find-composite";
import getCompositeFor from "../get-composite/get-composite";
describe("find-composite", () => { describe("find-composite", () => {
let composite: Composite<{ id: string; parentId?: string }>; let composite: Composite<{ id: string; parentId?: string }>;
beforeEach(() => { beforeEach(() => {
composite = getComposite({ const getComposite = getCompositeFor<{
source: [ id: string;
parentId?: string;
}>({
rootId: "some-root-id",
getId: (x) => x.id,
getParentId: (x) => x.parentId,
});
composite = getComposite([
{ id: "some-root-id" }, { id: "some-root-id" },
{ id: "some-child-id", parentId: "some-root-id" }, { id: "some-child-id", parentId: "some-root-id" },
{ id: "some-grandchild-id", parentId: "some-child-id" }, { id: "some-grandchild-id", parentId: "some-child-id" },
{ id: "some-other-grandchild-id", parentId: "some-child-id" }, { id: "some-other-grandchild-id", parentId: "some-child-id" },
], ]);
rootId: "some-root-id",
});
}); });
it("when finding root using path, does so", () => { it("when finding root using path, does so", () => {

View File

@ -3,7 +3,7 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getCompositeNormalization } from "./get-composite-normalization"; import { getCompositeNormalization } from "./get-composite-normalization";
import getComposite from "../get-composite/get-composite"; import getCompositeFor from "../get-composite/get-composite";
describe("get-composite-normalization", () => { describe("get-composite-normalization", () => {
it("given a composite, flattens it to paths and composites", () => { it("given a composite, flattens it to paths and composites", () => {
@ -24,10 +24,18 @@ describe("get-composite-normalization", () => {
const items = [someRootItem, someItem, someNestedItem]; const items = [someRootItem, someItem, someNestedItem];
const composite = getComposite({ const getComposite = getCompositeFor<{
source: items, id: string;
parentId?: string;
orderNumber?: number;
}>({
rootId: "some-root-id",
getId: (x) => x.id,
getParentId: (x) => x.parentId,
}); });
const composite = getComposite(items);
const actual = getCompositeNormalization(composite); const actual = getCompositeNormalization(composite);
expect(actual).toEqual([ expect(actual).toEqual([

View File

@ -2,11 +2,12 @@
* Copyright (c) OpenLens Authors. All rights reserved. * Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information. * 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"; import { getCompositePaths } from "./get-composite-paths";
import getCompositeFor from "../get-composite/get-composite";
import { sortBy } from "lodash/fp";
describe("get-composite-paths", () => { describe("get-composite-paths", () => {
it("given composite with ordered children, returns ordered paths", () => { it("given composite with transformed children, returns paths of transformed children in hierarchical order", () => {
const someRootItem = { const someRootItem = {
id: "some-root-id", id: "some-root-id",
}; };
@ -44,10 +45,19 @@ describe("get-composite-paths", () => {
someGrandchildItem1, someGrandchildItem1,
]; ];
const composite = getComposite({ const getComposite = getCompositeFor<{
source: items, id: string;
parentId?: string;
orderNumber?: number;
}>({
rootId: "some-root-id",
getId: (x) => x.id,
getParentId: (x) => x.parentId,
transformChildren: children => sortBy(child => child.orderNumber, children),
}); });
const composite = getComposite(items);
const actual = getCompositePaths(composite); const actual = getCompositePaths(composite);
expect(actual).toEqual([ expect(actual).toEqual([