Added constant EMPTY_OBJECT (an empty sealed object) that is used to indicate to the xml
library that an empty XML element should be generated, and use it in the JSON hardcoded into the tests.
This commit is contained in:
@ -4,6 +4,8 @@ import { Formatter } from "export/formatter";
|
||||
|
||||
import { CharacterStyle } from "./character-style";
|
||||
|
||||
import { EMPTY_OBJECT } from "file/xml-components";
|
||||
|
||||
describe("CharacterStyle", () => {
|
||||
describe("#constructor", () => {
|
||||
it("should set the style type to character and use the given style id", () => {
|
||||
@ -20,7 +22,7 @@ describe("CharacterStyle", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": {},
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -41,7 +43,7 @@ describe("CharacterStyle", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": {},
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -63,7 +65,7 @@ describe("CharacterStyle", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": {},
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{ "w:basedOn": { _attr: { "w:val": "otherId" } } },
|
||||
],
|
||||
@ -89,7 +91,7 @@ describe("CharacterStyle", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": {},
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -113,7 +115,7 @@ describe("CharacterStyle", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": {},
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -136,7 +138,7 @@ describe("CharacterStyle", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": {},
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -159,7 +161,7 @@ describe("CharacterStyle", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": {},
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -191,7 +193,7 @@ describe("CharacterStyle", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": {},
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -214,7 +216,7 @@ describe("CharacterStyle", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": {},
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -237,7 +239,7 @@ describe("CharacterStyle", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": {},
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -260,7 +262,7 @@ describe("CharacterStyle", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": {},
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -280,7 +282,7 @@ describe("CharacterStyle", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": {},
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{ "w:link": { _attr: { "w:val": "MyLink" } } },
|
||||
],
|
||||
@ -300,8 +302,8 @@ describe("CharacterStyle", () => {
|
||||
},
|
||||
},
|
||||
},
|
||||
{ "w:unhideWhenUsed": {} },
|
||||
{ "w:semiHidden": {} },
|
||||
{ "w:unhideWhenUsed": EMPTY_OBJECT },
|
||||
{ "w:semiHidden": EMPTY_OBJECT },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
@ -2,6 +2,8 @@ import { expect } from "chai";
|
||||
import { Formatter } from "export/formatter";
|
||||
import * as components from "./components";
|
||||
|
||||
import { EMPTY_OBJECT } from "file/xml-components";
|
||||
|
||||
describe("Style components", () => {
|
||||
it("Name#constructor", () => {
|
||||
const style = new components.Name("Style Name");
|
||||
@ -36,18 +38,18 @@ describe("Style components", () => {
|
||||
it("UnhideWhenUsed#constructor", () => {
|
||||
const style = new components.UnhideWhenUsed();
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({ "w:unhideWhenUsed": {} });
|
||||
expect(tree).to.deep.equal({ "w:unhideWhenUsed": EMPTY_OBJECT });
|
||||
});
|
||||
|
||||
it("QuickFormat#constructor", () => {
|
||||
const style = new components.QuickFormat();
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({ "w:qFormat": {} });
|
||||
expect(tree).to.deep.equal({ "w:qFormat": EMPTY_OBJECT });
|
||||
});
|
||||
|
||||
it("SemiHidden#constructor", () => {
|
||||
const style = new components.SemiHidden();
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({ "w:semiHidden": {} });
|
||||
expect(tree).to.deep.equal({ "w:semiHidden": EMPTY_OBJECT });
|
||||
});
|
||||
});
|
||||
|
@ -2,6 +2,8 @@ import { expect } from "chai";
|
||||
import { Formatter } from "export/formatter";
|
||||
import * as defaultStyels from "./default-styles";
|
||||
|
||||
import { EMPTY_OBJECT } from "file/xml-components";
|
||||
|
||||
describe("Default Styles", () => {
|
||||
it("HeadingStyle#constructor", () => {
|
||||
const style = new defaultStyels.HeadingStyle("Heading1", "Heading 1");
|
||||
@ -12,7 +14,7 @@ describe("Default Styles", () => {
|
||||
{ "w:name": { _attr: { "w:val": "Heading 1" } } },
|
||||
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||
{ "w:next": { _attr: { "w:val": "Normal" } } },
|
||||
{ "w:qFormat": {} },
|
||||
{ "w:qFormat": EMPTY_OBJECT },
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -26,7 +28,7 @@ describe("Default Styles", () => {
|
||||
{ "w:name": { _attr: { "w:val": "Title" } } },
|
||||
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||
{ "w:next": { _attr: { "w:val": "Normal" } } },
|
||||
{ "w:qFormat": {} },
|
||||
{ "w:qFormat": EMPTY_OBJECT },
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -40,7 +42,7 @@ describe("Default Styles", () => {
|
||||
{ "w:name": { _attr: { "w:val": "Heading 1" } } },
|
||||
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||
{ "w:next": { _attr: { "w:val": "Normal" } } },
|
||||
{ "w:qFormat": {} },
|
||||
{ "w:qFormat": EMPTY_OBJECT },
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -54,7 +56,7 @@ describe("Default Styles", () => {
|
||||
{ "w:name": { _attr: { "w:val": "Heading 2" } } },
|
||||
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||
{ "w:next": { _attr: { "w:val": "Normal" } } },
|
||||
{ "w:qFormat": {} },
|
||||
{ "w:qFormat": EMPTY_OBJECT },
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -68,7 +70,7 @@ describe("Default Styles", () => {
|
||||
{ "w:name": { _attr: { "w:val": "Heading 3" } } },
|
||||
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||
{ "w:next": { _attr: { "w:val": "Normal" } } },
|
||||
{ "w:qFormat": {} },
|
||||
{ "w:qFormat": EMPTY_OBJECT },
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -82,7 +84,7 @@ describe("Default Styles", () => {
|
||||
{ "w:name": { _attr: { "w:val": "Heading 4" } } },
|
||||
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||
{ "w:next": { _attr: { "w:val": "Normal" } } },
|
||||
{ "w:qFormat": {} },
|
||||
{ "w:qFormat": EMPTY_OBJECT },
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -96,7 +98,7 @@ describe("Default Styles", () => {
|
||||
{ "w:name": { _attr: { "w:val": "Heading 5" } } },
|
||||
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||
{ "w:next": { _attr: { "w:val": "Normal" } } },
|
||||
{ "w:qFormat": {} },
|
||||
{ "w:qFormat": EMPTY_OBJECT },
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -110,7 +112,7 @@ describe("Default Styles", () => {
|
||||
{ "w:name": { _attr: { "w:val": "Heading 6" } } },
|
||||
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||
{ "w:next": { _attr: { "w:val": "Normal" } } },
|
||||
{ "w:qFormat": {} },
|
||||
{ "w:qFormat": EMPTY_OBJECT },
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -123,7 +125,7 @@ describe("Default Styles", () => {
|
||||
{ _attr: { "w:type": "paragraph", "w:styleId": "ListParagraph" } },
|
||||
{ "w:name": { _attr: { "w:val": "List Paragraph" } } },
|
||||
{ "w:basedOn": { _attr: { "w:val": "Normal" } } },
|
||||
{ "w:qFormat": {} },
|
||||
{ "w:qFormat": EMPTY_OBJECT },
|
||||
],
|
||||
});
|
||||
});
|
||||
@ -176,10 +178,10 @@ describe("Default Styles", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:semiHidden": {},
|
||||
"w:semiHidden": EMPTY_OBJECT,
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": {},
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -211,12 +213,12 @@ describe("Default Styles", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": {},
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{ "w:basedOn": { _attr: { "w:val": "DefaultParagraphFont" } } },
|
||||
|
||||
{
|
||||
"w:semiHidden": {},
|
||||
"w:semiHidden": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -255,12 +257,12 @@ describe("Default Styles", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": {},
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{ "w:basedOn": { _attr: { "w:val": "DefaultParagraphFont" } } },
|
||||
{ "w:link": { _attr: { "w:val": "FootnoteText" } } },
|
||||
{
|
||||
"w:semiHidden": {},
|
||||
"w:semiHidden": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
});
|
||||
@ -284,7 +286,7 @@ describe("Default Styles", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": {},
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
{ "w:basedOn": { _attr: { "w:val": "DefaultParagraphFont" } } },
|
||||
],
|
||||
|
@ -4,6 +4,8 @@ import { Formatter } from "export/formatter";
|
||||
|
||||
import { ParagraphStyle } from "./paragraph-style";
|
||||
|
||||
import { EMPTY_OBJECT } from "file/xml-components";
|
||||
|
||||
describe("ParagraphStyle", () => {
|
||||
describe("#constructor", () => {
|
||||
it("should set the style type to paragraph and use the given style id", () => {
|
||||
@ -42,7 +44,7 @@ describe("ParagraphStyle", () => {
|
||||
const style = new ParagraphStyle("myStyleId").quickFormat();
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:qFormat": {} }],
|
||||
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:qFormat": EMPTY_OBJECT }],
|
||||
});
|
||||
});
|
||||
|
||||
@ -216,7 +218,7 @@ describe("ParagraphStyle", () => {
|
||||
const style = new ParagraphStyle("myStyleId").keepLines();
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:pPr": [{ "w:keepLines": {} }] }],
|
||||
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:pPr": [{ "w:keepLines": EMPTY_OBJECT }] }],
|
||||
});
|
||||
});
|
||||
|
||||
@ -224,7 +226,7 @@ describe("ParagraphStyle", () => {
|
||||
const style = new ParagraphStyle("myStyleId").keepNext();
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:pPr": [{ "w:keepNext": {} }] }],
|
||||
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:pPr": [{ "w:keepNext": EMPTY_OBJECT }] }],
|
||||
});
|
||||
});
|
||||
|
||||
@ -439,7 +441,7 @@ describe("ParagraphStyle", () => {
|
||||
const style = new ParagraphStyle("myStyleId").semiHidden();
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:semiHidden": {} }],
|
||||
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:semiHidden": EMPTY_OBJECT }],
|
||||
});
|
||||
});
|
||||
|
||||
@ -464,7 +466,7 @@ describe("ParagraphStyle", () => {
|
||||
const style = new ParagraphStyle("myStyleId").unhideWhenUsed();
|
||||
const tree = new Formatter().format(style);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:unhideWhenUsed": {} }],
|
||||
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:unhideWhenUsed": EMPTY_OBJECT }],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -6,6 +6,8 @@ import { CharacterStyle, ParagraphStyle } from "./style";
|
||||
|
||||
import { Styles } from "./styles";
|
||||
|
||||
import { EMPTY_OBJECT } from "file/xml-components";
|
||||
|
||||
describe("Styles", () => {
|
||||
let styles: Styles;
|
||||
|
||||
@ -64,7 +66,7 @@ describe("Styles", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": {},
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -88,7 +90,7 @@ describe("Styles", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
"w:unhideWhenUsed": {},
|
||||
"w:unhideWhenUsed": EMPTY_OBJECT,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
Reference in New Issue
Block a user