FIX: medial nodes are always at index[1]. Terminal nodes at index[2].
parent
1aa316ee62
commit
43826465ec
|
@ -71,10 +71,11 @@ describe("creation of folders", () => {
|
|||
|
||||
it("adds a folder to an initial node", async () => {
|
||||
const name = "~ Folder Name ~";
|
||||
const nextGraph = await createFolder(GRAPH, 6, name);
|
||||
const id = 6;
|
||||
const nextGraph = await createFolder(GRAPH, id, name);
|
||||
let target: FolderUnion | undefined;
|
||||
climb(nextGraph, (node) => {
|
||||
if (node.id == 6) { target = node; }
|
||||
if (node.id == id) { target = node; }
|
||||
});
|
||||
|
||||
if (target && target.kind === "initial") {
|
||||
|
@ -86,8 +87,21 @@ describe("creation of folders", () => {
|
|||
}
|
||||
});
|
||||
|
||||
it("adds a folder to a medial node", () => {
|
||||
pending();
|
||||
it("adds a folder to a medial node", async () => {
|
||||
const name = "~ Folder Name ~";
|
||||
const id = 11;
|
||||
const nextGraph = await createFolder(GRAPH, id, name);
|
||||
let target: FolderUnion | undefined;
|
||||
|
||||
climb(nextGraph, (node) => {
|
||||
if (node.id == id) { target = node; }
|
||||
});
|
||||
|
||||
if (target && target.kind === "medial") {
|
||||
expect(target.children.map(x => x.name)).toContain(name);
|
||||
} else {
|
||||
fail("Wrong target?");
|
||||
}
|
||||
});
|
||||
|
||||
test.todo("does not add a folder to terminal node");
|
||||
|
|
|
@ -118,11 +118,15 @@ export const createFolder =
|
|||
|
||||
if (node.id == parent_id) {
|
||||
switch (node.kind) {
|
||||
case "initial": node.children.push(medial(name)); break;
|
||||
case "medial": node.children.push(terminal(name)); break;
|
||||
case "terminal": throw new Error("Can't attach folders more than 3 levels deep");
|
||||
case "initial":
|
||||
node.children.push(medial(name));
|
||||
return halt();
|
||||
case "medial":
|
||||
node.children.push(terminal(name));
|
||||
return halt();
|
||||
case "terminal":
|
||||
throw new Error("Can't attach folders more than 3 levels deep");
|
||||
}
|
||||
return halt();
|
||||
}
|
||||
}));
|
||||
};
|
||||
|
|
|
@ -13,7 +13,7 @@ interface FolderUI {
|
|||
/** A top-level directory */
|
||||
export interface FolderNodeInitial extends FolderUI {
|
||||
kind: "initial";
|
||||
children: (FolderNodeMedial | FolderNodeTerminal)[];
|
||||
children: FolderNodeMedial[];
|
||||
}
|
||||
|
||||
/** A mid-level directory. */
|
||||
|
|
|
@ -43,11 +43,8 @@ export function ingest(input: FolderNode[]): RootFolderNode {
|
|||
content: []
|
||||
});
|
||||
|
||||
const mapper = (x: FolderNode) => (index[x.id] || []).length ?
|
||||
medial(x) : terminal(x);
|
||||
|
||||
childrenOf(-1).map((root) => {
|
||||
const children = childrenOf(root.id).map(mapper);
|
||||
const children = childrenOf(root.id).map(medial);
|
||||
return output.folders.push({
|
||||
...root,
|
||||
kind: "initial",
|
||||
|
|
Loading…
Reference in New Issue