mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Remove some duplication from tests of composite
Also make the thrown error suggest how to fix the problem. Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
parent
11d2023c70
commit
271255114c
@ -8,12 +8,15 @@ import getCompositeFor from "./get-composite";
|
|||||||
import { getCompositePaths } from "../get-composite-paths/get-composite-paths";
|
import { getCompositePaths } from "../get-composite-paths/get-composite-paths";
|
||||||
import { sortBy } from "lodash/fp";
|
import { sortBy } from "lodash/fp";
|
||||||
|
|
||||||
|
interface SomeItem {
|
||||||
|
id: string;
|
||||||
|
parentId?: string;
|
||||||
|
orderNumber?: number;
|
||||||
|
}
|
||||||
|
|
||||||
describe("get-composite", () => {
|
describe("get-composite", () => {
|
||||||
it("given items and a specified root id, creates a composite", () => {
|
it("given items and a specified root id, creates a composite", () => {
|
||||||
const getComposite = getCompositeFor<{
|
const getComposite = getCompositeFor<SomeItem>({
|
||||||
id: string;
|
|
||||||
parentId: string | undefined;
|
|
||||||
}>({
|
|
||||||
rootId: "some-root-id",
|
rootId: "some-root-id",
|
||||||
getId: (x) => x.id,
|
getId: (x) => x.id,
|
||||||
getParentId: (x) => x.parentId,
|
getParentId: (x) => x.parentId,
|
||||||
@ -86,10 +89,7 @@ describe("get-composite", () => {
|
|||||||
|
|
||||||
const items = [someRootItem, someItem, someNestedItem];
|
const items = [someRootItem, someItem, someNestedItem];
|
||||||
|
|
||||||
const getComposite = getCompositeFor<{
|
const getComposite = getCompositeFor<SomeItem>({
|
||||||
id: string;
|
|
||||||
parentId: string | undefined;
|
|
||||||
}>({
|
|
||||||
// Notice: no root id
|
// Notice: no root id
|
||||||
// rootId: "some-root-id",
|
// rootId: "some-root-id",
|
||||||
getId: (x) => x.id,
|
getId: (x) => x.id,
|
||||||
@ -136,10 +136,7 @@ describe("get-composite", () => {
|
|||||||
|
|
||||||
const items = [someRootItem, someOtherRootItem];
|
const items = [someRootItem, someOtherRootItem];
|
||||||
|
|
||||||
const getComposite = getCompositeFor<{
|
const getComposite = getCompositeFor<SomeItem>({
|
||||||
id: string;
|
|
||||||
parentId: string | undefined;
|
|
||||||
}>({
|
|
||||||
getId: (x) => x.id,
|
getId: (x) => x.id,
|
||||||
getParentId: (x) => x.parentId,
|
getParentId: (x) => x.parentId,
|
||||||
});
|
});
|
||||||
@ -164,10 +161,7 @@ describe("get-composite", () => {
|
|||||||
|
|
||||||
const items = [someItem, someOtherItem];
|
const items = [someItem, someOtherItem];
|
||||||
|
|
||||||
const getComposite = getCompositeFor<{
|
const getComposite = getCompositeFor<SomeItem>({
|
||||||
id: string;
|
|
||||||
parentId: string | undefined;
|
|
||||||
}>({
|
|
||||||
getId: (x) => x.id,
|
getId: (x) => x.id,
|
||||||
getParentId: (x) => x.parentId,
|
getParentId: (x) => x.parentId,
|
||||||
});
|
});
|
||||||
@ -192,10 +186,7 @@ describe("get-composite", () => {
|
|||||||
|
|
||||||
const items = [someItem, someItemWithMissingParentId];
|
const items = [someItem, someItemWithMissingParentId];
|
||||||
|
|
||||||
const getComposite = getCompositeFor<{
|
const getComposite = getCompositeFor<SomeItem>({
|
||||||
id: string;
|
|
||||||
parentId: string | undefined;
|
|
||||||
}>({
|
|
||||||
getId: (x) => x.id,
|
getId: (x) => x.id,
|
||||||
getParentId: (x) => x.parentId,
|
getParentId: (x) => x.parentId,
|
||||||
});
|
});
|
||||||
@ -230,10 +221,7 @@ Available parent ids are:
|
|||||||
|
|
||||||
handleMissingParentIdMock = jest.fn();
|
handleMissingParentIdMock = jest.fn();
|
||||||
|
|
||||||
const getComposite = getCompositeFor<{
|
const getComposite = getCompositeFor<SomeItem>({
|
||||||
id: string;
|
|
||||||
parentId?: string;
|
|
||||||
}>({
|
|
||||||
getId: (x) => x.id,
|
getId: (x) => x.id,
|
||||||
getParentId: (x) => x.parentId,
|
getParentId: (x) => x.parentId,
|
||||||
handleMissingParentIds: handleMissingParentIdMock,
|
handleMissingParentIds: handleMissingParentIdMock,
|
||||||
@ -269,10 +257,7 @@ Available parent ids are:
|
|||||||
|
|
||||||
const items = [someItem, someRoot];
|
const items = [someItem, someRoot];
|
||||||
|
|
||||||
const getComposite = getCompositeFor<{
|
const getComposite = getCompositeFor<SomeItem>({
|
||||||
id: string;
|
|
||||||
parentId: string | undefined;
|
|
||||||
}>({
|
|
||||||
getId: (x) => x.id,
|
getId: (x) => x.id,
|
||||||
getParentId: (x) => x.parentId,
|
getParentId: (x) => x.parentId,
|
||||||
});
|
});
|
||||||
@ -302,10 +287,7 @@ Available parent ids are:
|
|||||||
|
|
||||||
const items = [root, someItem, someOtherItem];
|
const items = [root, someItem, someOtherItem];
|
||||||
|
|
||||||
const getComposite = getCompositeFor<{
|
const getComposite = getCompositeFor<SomeItem>({
|
||||||
id: any;
|
|
||||||
parentId: string | undefined;
|
|
||||||
}>({
|
|
||||||
getId: (x) => x.id,
|
getId: (x) => x.id,
|
||||||
getParentId: (x) => x.parentId,
|
getParentId: (x) => x.parentId,
|
||||||
});
|
});
|
||||||
@ -354,11 +336,7 @@ Available parent ids are:
|
|||||||
someChildItem1,
|
someChildItem1,
|
||||||
];
|
];
|
||||||
|
|
||||||
const getComposite = getCompositeFor<{
|
const getComposite = getCompositeFor<SomeItem>({
|
||||||
id: string;
|
|
||||||
parentId?: string;
|
|
||||||
orderNumber?: number;
|
|
||||||
}>({
|
|
||||||
getId: (x) => x.id,
|
getId: (x) => x.id,
|
||||||
getParentId: (x) => x.parentId,
|
getParentId: (x) => x.parentId,
|
||||||
transformChildren: (things) =>
|
transformChildren: (things) =>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user