@menome/document-to-graph
Version:
Menome Technologies Inc: takes incoming text and turns it into a structure suitable for a graph
97 lines (80 loc) • 4.23 kB
JavaScript
const ht = require("../headerTypeEnum");
const assert = require('assert');
const th = require('./section6TestHelper.js');
const DocumentToGraph = require('../DocumentToGraph.js');
const SEGMENT_1 = 0
const SEGMENT_2 = 1
const SEGMENT_3 = 2
const SEGMENT_4 = 3
const SEGMENT_6 = 5
const SEGMENT_10 = 9
let actual
describe('Document to Segments', function () {
it('Should be nine segments', function () {
actual = DocumentToGraph.DocumentToGraph(th.section6Text(), th.rootNode());
assert.strictEqual(actual.length, 36);
})
it('First segment heading type should be a Heading1', function () {
actual = DocumentToGraph.DocumentToGraph(th.section6Text(), th.rootNode());
assert.strictEqual(actual[SEGMENT_1].type, ht.HeaderType.HEADING1);
})
it('First segment code should be 6', function () {
actual = DocumentToGraph.DocumentToGraph(th.section6Text(), th.rootNode());
assert.strictEqual(actual[SEGMENT_1].code, "6");
})
it('First segment parent code should be root node', function () {
actual = DocumentToGraph.DocumentToGraph(th.section6Text(), th.rootNode());
rootNode=th.rootNode();
assert.strictEqual(actual[SEGMENT_1].parentCode,rootNode.code);
})
it('First segment index name should be stakeholder engagement', function () {
actual = DocumentToGraph.DocumentToGraph(th.section6Text(), th.rootNode());
assert.strictEqual(actual[SEGMENT_1].indexName, "6 Stakeholder Engagement");
})
it('Second segment heading type should be a Heading2', function () {
actual = DocumentToGraph.DocumentToGraph(th.section6Text(), th.rootNode());
assert.strictEqual(actual[SEGMENT_2].type, ht.HeaderType.HEADING2);
})
it('Second segment code should be 6.1', function () {
actual = DocumentToGraph.DocumentToGraph(th.section6Text(), th.rootNode());
assert.strictEqual(actual[SEGMENT_2].code, "6.1");
})
it('Second segment parent code should be 6', function () {
actual = DocumentToGraph.DocumentToGraph(th.section6Text(), th.rootNode());
assert.strictEqual(actual[SEGMENT_2].parentCode, "6");
})
it('Second segment parent code should match the first segment code', function () {
actual = DocumentToGraph.DocumentToGraph(th.section6Text(), th.rootNode());
assert.strictEqual(actual[SEGMENT_2].parentCode, actual[SEGMENT_1].code);
})
it('Index name should be general', function () {
actual = DocumentToGraph.DocumentToGraph(th.section6Text(), th.rootNode());
assert.strictEqual(actual[SEGMENT_2].indexName, "6.1 General");
})
it('Third segment should be text', function () {
actual = DocumentToGraph.DocumentToGraph(th.section6Text(), th.rootNode());
assert.strictEqual(actual[SEGMENT_3].type, ht.HeaderType.TEXT);
})
it('Third segment parent code should be 6.1 ', function () {
actual = DocumentToGraph.DocumentToGraph(th.section6Text(), th.rootNode());
assert.strictEqual(actual[SEGMENT_3].parentCode, "6.1");
})
it('Fourth segment should be text', function () {
actual = DocumentToGraph.DocumentToGraph(th.section6Text(), th.rootNode());
assert.strictEqual(actual[SEGMENT_4].type, ht.HeaderType.TEXT);
})
it('Fourth segment parent code should be 6.1 ', function () {
actual = DocumentToGraph.DocumentToGraph(th.section6Text(), th.rootNode());
assert.strictEqual(actual[SEGMENT_4].parentCode, "6.1");
})
it('Page Heading Left side page number', function () {
actual = DocumentToGraph.DocumentToGraph(th.section6Text(), th.rootNode());
var pageHeading=actual.filter(segement => segement.type === ht.HeaderType.PAGE_HEADING );
assert.strictEqual(1, pageHeading.length);
})
/*it('Page Heading right side page number', function () {
actual = DocumentToGraph.DocumentToGraph(th.section6Text());
assert.strictEqual(actual[SEGMENT_10].type, ht.HeaderType.PAGE_HEADING);
assert.strictEqual(actual[SEGMENT_4].parentCode, "6.1");
})*/
});