|
| 1 | +var assert = require("assert"); |
| 2 | +var makeTree = require("../make-tree"); |
| 3 | + |
| 4 | +describe("makeTree", function() { |
| 5 | + it("makes flat trees based on heading tag names", function() { |
| 6 | + var elements = [ |
| 7 | + { tagName: "h2", textContent: "Usage" }, |
| 8 | + { tagName: "h2", textContent: "Install" }, |
| 9 | + { tagName: "h2", textContent: "Configure" }, |
| 10 | + { tagName: "h2", textContent: "Configure" } |
| 11 | + ]; |
| 12 | + |
| 13 | + assert.deepEqual(makeTree(elements), [ |
| 14 | + { id: "usage", level: 2, text: "Usage", children: [] }, |
| 15 | + { id: "install", level: 2, text: "Install", children: [] }, |
| 16 | + { id: "configure", level: 2, text: "Configure", children: [] }, |
| 17 | + { id: "configure-1", level: 2, text: "Configure", children: [] } |
| 18 | + ]); |
| 19 | + }); |
| 20 | + |
| 21 | + it("nests trees based on headings hierarchy", function() { |
| 22 | + var elements = [ |
| 23 | + { tagName: "h2", textContent: "Bower" }, |
| 24 | + { tagName: "h3", textContent: "Install" }, |
| 25 | + { tagName: "h2", textContent: "NPM" }, |
| 26 | + { tagName: "h3", textContent: "Install" }, |
| 27 | + { tagName: "h4", textContent: "Specifying components folder" }, |
| 28 | + { tagName: "h2", textContent: "Writing Modules" } |
| 29 | + ]; |
| 30 | + |
| 31 | + assert.deepEqual(makeTree(elements), [ |
| 32 | + { id: "bower", |
| 33 | + level: 2, |
| 34 | + text: "Bower", |
| 35 | + children: [ |
| 36 | + { id: "install", level: 3, text: "Install", children: [] } |
| 37 | + ] |
| 38 | + }, |
| 39 | + { id: "npm", |
| 40 | + level: 2, |
| 41 | + text: "NPM", |
| 42 | + children: [ |
| 43 | + { id: "install-1", level: 3, text: "Install", |
| 44 | + children: [ |
| 45 | + { id: "specifying-components-folder", |
| 46 | + level: 4, |
| 47 | + text: "Specifying components folder", |
| 48 | + children: [] |
| 49 | + } |
| 50 | + ] |
| 51 | + } |
| 52 | + ] |
| 53 | + }, |
| 54 | + { id: "writing-modules", level: 2, text: "Writing Modules", children: [] } |
| 55 | + ]); |
| 56 | + }); |
| 57 | +}); |
0 commit comments