Files
docx-js/src/file/table-of-contents/table-of-contents.spec.ts

182 lines
6.3 KiB
TypeScript
Raw Normal View History

2018-08-22 10:30:19 -03:00
import { expect } from "chai";
2018-10-26 01:04:07 +01:00
import { Formatter } from "export/formatter";
import { TableOfContents } from "./table-of-contents";
import { StyleLevel } from "./table-of-contents-properties";
2018-09-25 01:18:47 -03:00
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 styles = new Array<StyleLevel>();
styles.push(new StyleLevel("SL", 1));
styles.push(new StyleLevel("SL", 2));
const props = {
captionLabel: "A",
entriesFromBookmark: "B",
captionLabelIncludingNumbers: "C",
sequenceAndPageNumbersSeparator: "D",
tcFieldIdentifier: "F",
hyperlink: true,
tcFieldLevelRange: "L",
pageNumbersEntryLevelsRange: "N",
headingStyleRange: "O",
entryAndPageNumberSeparator: "P",
seqFieldIdentifierForPrefix: "S",
stylesWithLevels: styles,
useAppliedParagraphOutlineLevel: true,
preserveTabInEntries: true,
preserveNewLineInEntries: true,
hideTabAndPageNumbersInWebView: true,
};
2018-09-25 01:18:47 -03:00
const toc = new TableOfContents("Summary", props);
const tree = new Formatter().format(toc);
expect(tree).to.be.deep.equal(COMPLETE_TOC);
});
});
});
2018-08-29 12:06:01 -03:00
const DEFAULT_TOC = {
"w:sdt": [
2018-08-31 10:22:40 -03:00
{
"w:sdtPr": [
2018-09-03 11:20:36 -03:00
{
"w:alias": {
_attr: {
"w:val": "Table of Contents",
2018-09-04 18:22:08 -03:00
},
},
2018-09-04 18:22:08 -03:00
},
],
},
{
"w:sdtContent": [
2018-09-04 18:22:08 -03:00
{
"w:p": [
2018-09-04 18:22:08 -03:00
{
"w:r": [
{
"w:fldChar": {
_attr: {
"w:fldCharType": "begin",
"w:dirty": true,
},
},
},
{
"w:instrText": [
{
_attr: {
"xml:space": "preserve",
},
},
2018-09-25 01:18:47 -03:00
"TOC",
],
},
{
"w:fldChar": {
_attr: {
"w:fldCharType": "separate",
},
},
},
],
2018-09-04 18:22:08 -03:00
},
],
2018-09-03 11:20:36 -03:00
},
2018-09-04 18:22:08 -03:00
{
"w:p": [
{
"w:r": [
{
"w:fldChar": {
_attr: {
"w:fldCharType": "end",
},
},
},
],
2018-09-04 18:22:08 -03:00
},
],
2018-09-03 10:48:50 -03:00
},
],
},
2018-08-31 10:22:40 -03:00
],
2018-08-29 12:06:01 -03:00
};
2018-09-25 01:18:47 -03:00
const COMPLETE_TOC = {
"w:sdt": [
{
"w:sdtPr": [
{
"w:alias": {
_attr: {
"w:val": "Summary",
2018-09-25 01:18:47 -03:00
},
},
2018-09-25 01:18:47 -03:00
},
],
},
{
"w:sdtContent": [
{
"w:p": [
{
"w:r": [
{
"w:fldChar": {
_attr: {
"w:fldCharType": "begin",
"w:dirty": true,
2018-09-25 01:18:47 -03:00
},
},
2018-09-25 01:18:47 -03:00
},
{
"w:instrText": [
{
_attr: {
"xml:space": "preserve",
},
},
2018-10-21 19:56:31 -02:00
'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',
2018-09-25 01:18:47 -03:00
],
},
{
"w:fldChar": {
_attr: {
"w:fldCharType": "separate",
2018-09-25 01:18:47 -03:00
},
},
2018-09-25 01:18:47 -03:00
},
],
},
],
},
{
"w:p": [
{
"w:r": [
{
"w:fldChar": {
_attr: {
"w:fldCharType": "end",
2018-09-25 01:18:47 -03:00
},
},
2018-09-25 01:18:47 -03:00
},
],
},
],
},
],
},
],
};