table of contents with all the options

This commit is contained in:
Sergio Mendonça
2018-09-25 01:18:47 -03:00
parent 4de6b51e76
commit 808c5b00a0
6 changed files with 300 additions and 56 deletions

View File

@ -1,7 +1,46 @@
import { expect } from "chai";
import { Formatter } from "../../export/formatter";
import { TableOfContents } from "./";
import { StyleLevel, TableOfContents, TableOfContentsProperties } from "./";
describe("Table of Contents", () => {
describe("#constructor", () => {
it("should construct a TOC without options", () => {
const toc = new TableOfContents();
const tree = new Formatter().format(toc);
expect(tree).to.be.deep.equal(DEFAULT_TOC);
});
it("should construct a TOC with all the options and alias", () => {
const props = new TableOfContentsProperties();
props.captionLabel = "A";
props.entriesFromBookmark = "B";
props.captionLabelIncludingNumbers = "C";
props.sequenceAndPageNumbersSeparator = "D";
props.tcFieldIdentifier = "F";
props.hiperlink = true;
props.tcFieldLevelRange = "L";
props.pageNumbersEntryLevelsRange = "N";
props.headingStyleRange = "O";
props.entryAndPageNumberSeparator = "P";
props.seqFieldIdentifierForPrefix = "S";
const styles = new Array<StyleLevel>();
styles.push(new StyleLevel("SL", 1));
styles.push(new StyleLevel("SL", 2));
props.stylesWithLevels = styles;
props.useAppliedParagraphOutlineLevel = true;
props.preserveTabInEntries = true;
props.preserveNewLineInEntries = true;
props.hideTabAndPageNumbersInWebView = true;
const toc = new TableOfContents("Summary", props);
const tree = new Formatter().format(toc);
expect(tree).to.be.deep.equal(COMPLETE_TOC);
});
});
});
const DEFAULT_TOC = {
"w:sdt": [
@ -47,7 +86,7 @@ const DEFAULT_TOC = {
"xml:space": "preserve",
},
},
'TOC \\o "1-6"',
"TOC",
],
},
{
@ -91,13 +130,90 @@ const DEFAULT_TOC = {
],
};
describe("Table of Contents", () => {
describe("#constructor", () => {
it("should construct a TOC with default options", () => {
const toc = new TableOfContents();
const tree = new Formatter().format(toc);
// console.log(JSON.stringify(tree, null, 2));
expect(tree).to.be.deep.equal(DEFAULT_TOC);
});
});
});
const COMPLETE_TOC = {
"w:sdt": [
{
"w:sdtPr": [
{
"w:alias": [
{
_attr: {
"w:val": "Summary",
},
},
],
},
],
},
{
"w:sdtContent": [
{
"w:p": [
{
"w:pPr": [],
},
{
"w:r": [
{
"w:rPr": [],
},
{
"w:fldChar": [
{
_attr: {
"w:fldCharType": "begin",
"w:dirty": true,
},
},
],
},
{
"w:instrText": [
{
_attr: {
"xml:space": "preserve",
},
},
'TOC \\a "A" \\b "B" \\c "C" \\d "D" \\f "F" \\h \\l "L \\n "N \\o "O \\p "P \\s "S \\t "SL,1,SL,2" \\u \\w \\x \\z',
],
},
{
"w:fldChar": [
{
_attr: {
"w:fldCharType": "separate",
},
},
],
},
],
},
],
},
{
"w:p": [
{
"w:pPr": [],
},
{
"w:r": [
{
"w:rPr": [],
},
{
"w:fldChar": [
{
_attr: {
"w:fldCharType": "end",
},
},
],
},
],
},
],
},
],
},
],
};