| 1 |
import { test } from "uvu"; |
| 2 |
import assert from "uvu/assert"; |
| 3 |
|
| 4 |
import { stratify } from "../src/lib/tree"; |
| 5 |
|
| 6 |
test("tree: stratify", () => { |
| 7 |
const empty = stratify( |
| 8 |
[], |
| 9 |
() => "", |
| 10 |
() => null, |
| 11 |
); |
| 12 |
assert.equal(empty, { children: [] }); |
| 13 |
const emptyWithData = stratify( |
| 14 |
[], |
| 15 |
() => "", |
| 16 |
() => ({ test: "test" }), |
| 17 |
); |
| 18 |
assert.equal(emptyWithData, { children: [], test: "test" }); |
| 19 |
const tree = stratify( |
| 20 |
["aName:cName", "aName", "aName:bName"], |
| 21 |
(s) => s, |
| 22 |
(name) => ({ name }), |
| 23 |
); |
| 24 |
|
| 25 |
assert.equal(tree, { |
| 26 |
children: [ |
| 27 |
{ |
| 28 |
children: [ |
| 29 |
{ children: [], name: "aName:bName" }, |
| 30 |
{ children: [], name: "aName:cName" }, |
| 31 |
], |
| 32 |
name: "aName", |
| 33 |
}, |
| 34 |
], |
| 35 |
name: "", |
| 36 |
}); |
| 37 |
assert.equal( |
| 38 |
stratify( |
| 39 |
["Assets:Cash"], |
| 40 |
(s) => s, |
| 41 |
(name) => ({ name }), |
| 42 |
), |
| 43 |
{ |
| 44 |
children: [ |
| 45 |
{ |
| 46 |
children: [{ children: [], name: "Assets:Cash" }], |
| 47 |
name: "Assets", |
| 48 |
}, |
| 49 |
], |
| 50 |
name: "", |
| 51 |
}, |
| 52 |
); |
| 53 |
}); |
| 54 |
|
| 55 |
test.run(); |