FIX: medial nodes are always at index[1]. Terminal nodes at index[2].

folders
Rick Carlino 2019-12-02 11:53:37 -06:00
parent 1aa316ee62
commit 43826465ec
4 changed files with 28 additions and 13 deletions

View File

@ -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");

View File

@ -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();
}
}));
};

View File

@ -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. */

View File

@ -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",