:test: update test for complex script

This commit is contained in:
wangfengming
2020-07-15 12:46:46 +08:00
parent 437e83ab78
commit 75a03f1576
3 changed files with 626 additions and 301 deletions

View File

@ -283,23 +283,41 @@ describe("AbstractNumbering", () => {
}); });
describe("formatting methods: run properties", () => { describe("formatting methods: run properties", () => {
it("#size", () => { const sizeTests = [
{
size: 24,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
},
{
size: 24,
sizeComplexScript: true,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
},
{
size: 24,
sizeComplexScript: false,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }],
},
{
size: 24,
sizeComplexScript: 26,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 26 } } }],
},
];
sizeTests.forEach(({ size, sizeComplexScript, expected }) => {
it(`#size ${size} cs ${sizeComplexScript}`, () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: "lowerRoman",
text: "%0.", text: "%0.",
style: { style: {
run: { run: { size, sizeComplexScript },
size: 24,
sizeComplexScript: false,
},
}, },
}, },
]); ]);
const tree = new Formatter().format(abstractNumbering); const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected });
"w:rPr": [{ "w:sz": { _attr: { "w:val": 24 } } }],
}); });
}); });
@ -479,87 +497,185 @@ describe("AbstractNumbering", () => {
}); });
}); });
it("#bold", () => { const boldTests = [
const abstractNumbering = new AbstractNumbering(1, [ {
bold: true,
expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }],
},
{
bold: true,
boldComplexScript: true,
expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }],
},
{ {
level: 0,
format: "lowerRoman",
text: "%0.",
style: {
run: {
bold: true, bold: true,
boldComplexScript: false, boldComplexScript: false,
expected: [{ "w:b": { _attr: { "w:val": true } } }],
}, },
}, ];
}, boldTests.forEach(({ bold, boldComplexScript, expected }) => {
]); it(`#bold ${bold} cs ${boldComplexScript}`, () => {
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
"w:rPr": [{ "w:b": { _attr: { "w:val": true } } }],
});
});
it("#italics", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: "lowerRoman",
text: "%0.", text: "%0.",
style: { style: {
run: { run: { bold, boldComplexScript },
},
},
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected });
});
});
const italicsTests = [
{
italics: true,
expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }],
},
{
italics: true,
italicsComplexScript: true,
expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }],
},
{
italics: true, italics: true,
italicsComplexScript: false, italicsComplexScript: false,
expected: [{ "w:i": { _attr: { "w:val": true } } }],
}, },
}, ];
}, italicsTests.forEach(({ italics, italicsComplexScript, expected }) => {
]); it(`#italics ${italics} cs ${italicsComplexScript}`, () => {
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
"w:rPr": [{ "w:i": { _attr: { "w:val": true } } }],
});
});
it("#highlight", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: "lowerRoman",
text: "%0.", text: "%0.",
style: { style: {
run: { run: { italics, italicsComplexScript },
},
},
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected });
});
});
const highlightTests = [
{
highlight: "005599",
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }],
},
{
highlight: "005599",
highlightComplexScript: true,
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }],
},
{
highlight: "005599", highlight: "005599",
highlightComplexScript: false, highlightComplexScript: false,
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }],
}, },
{
highlight: "005599",
highlightComplexScript: "550099",
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "550099" } } }],
}, },
}, ];
]); highlightTests.forEach(({ highlight, highlightComplexScript, expected }) => {
const tree = new Formatter().format(abstractNumbering); it(`#highlight ${highlight} cs ${highlightComplexScript}`, () => {
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
"w:rPr": [{ "w:highlight": { _attr: { "w:val": "005599" } } }],
});
});
it("#shadow", () => {
const abstractNumbering = new AbstractNumbering(1, [ const abstractNumbering = new AbstractNumbering(1, [
{ {
level: 0, level: 0,
format: "lowerRoman", format: "lowerRoman",
text: "%0.", text: "%0.",
style: { style: {
run: { run: { highlight, highlightComplexScript },
},
},
]);
const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected });
});
});
const shadingTests = [
{
shadow: { shadow: {
type: ShadingType.PERCENT_10, type: ShadingType.PERCENT_10,
fill: "00FFFF", fill: "00FFFF",
color: "FF0000", color: "FF0000",
}, },
shadingComplexScript: false, expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
],
}, },
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: true,
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: false,
expected: [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "00FF00",
},
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "00FF00" } } },
],
},
];
shadingTests.forEach(({ shadow, shading, shadingComplexScript, expected }) => {
it("#shadow correctly", () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: "lowerRoman",
text: "%0.",
style: {
run: { shadow, shading, shadingComplexScript },
}, },
}, },
]); ]);
const tree = new Formatter().format(abstractNumbering); const tree = new Formatter().format(abstractNumbering);
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected });
"w:rPr": [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }],
}); });
}); });

View File

@ -334,19 +334,39 @@ describe("CharacterStyle", () => {
}); });
describe("formatting methods: run properties", () => { describe("formatting methods: run properties", () => {
it("#size", () => { const sizeTests = [
{
size: 24,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
},
{
size: 24,
sizeComplexScript: true,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
},
{
size: 24,
sizeComplexScript: false,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }],
},
{
size: 24,
sizeComplexScript: 26,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 26 } } }],
},
];
sizeTests.forEach(({ size, sizeComplexScript, expected }) => {
it(`#size ${size} cs ${sizeComplexScript}`, () => {
const style = new CharacterStyle({ const style = new CharacterStyle({
id: "myStyleId", id: "myStyleId",
run: { run: { size, sizeComplexScript },
size: 24,
},
}); });
const tree = new Formatter().format(style); const tree = new Formatter().format(style);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:style": [ "w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, { _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{ {
"w:rPr": [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }], "w:rPr": expected,
}, },
{ {
"w:uiPriority": { "w:uiPriority": {
@ -361,6 +381,7 @@ describe("CharacterStyle", () => {
], ],
}); });
}); });
});
describe("#underline", () => { describe("#underline", () => {
it("should set underline to 'single' if no arguments are given", () => { it("should set underline to 'single' if no arguments are given", () => {
@ -577,20 +598,34 @@ describe("CharacterStyle", () => {
}); });
}); });
it("#bold", () => { const boldTests = [
const style = new CharacterStyle({ {
id: "myStyleId", bold: true,
run: { expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }],
},
{
bold: true,
boldComplexScript: true,
expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }],
},
{
bold: true, bold: true,
boldComplexScript: false, boldComplexScript: false,
expected: [{ "w:b": { _attr: { "w:val": true } } }],
}, },
];
boldTests.forEach(({ bold, boldComplexScript, expected }) => {
it(`#bold ${bold} cs ${boldComplexScript}`, () => {
const style = new CharacterStyle({
id: "myStyleId",
run: { bold, boldComplexScript },
}); });
const tree = new Formatter().format(style); const tree = new Formatter().format(style);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:style": [ "w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, { _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{ {
"w:rPr": [{ "w:b": { _attr: { "w:val": true } } }], "w:rPr": expected,
}, },
{ {
"w:uiPriority": { "w:uiPriority": {
@ -605,21 +640,36 @@ describe("CharacterStyle", () => {
], ],
}); });
}); });
});
it("#italics", () => { const italicsTests = [
const style = new CharacterStyle({ {
id: "myStyleId", italics: true,
run: { expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }],
},
{
italics: true,
italicsComplexScript: true,
expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }],
},
{
italics: true, italics: true,
italicsComplexScript: false, italicsComplexScript: false,
expected: [{ "w:i": { _attr: { "w:val": true } } }],
}, },
];
italicsTests.forEach(({ italics, italicsComplexScript, expected }) => {
it(`#italics ${italics} cs ${italicsComplexScript}`, () => {
const style = new CharacterStyle({
id: "myStyleId",
run: { italics, italicsComplexScript },
}); });
const tree = new Formatter().format(style); const tree = new Formatter().format(style);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:style": [ "w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, { _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{ {
"w:rPr": [{ "w:i": { _attr: { "w:val": true } } }], "w:rPr": expected,
}, },
{ {
"w:uiPriority": { "w:uiPriority": {
@ -634,6 +684,7 @@ describe("CharacterStyle", () => {
], ],
}); });
}); });
});
it("#link", () => { it("#link", () => {
const style = new CharacterStyle({ id: "myStyleId", link: "MyLink" }); const style = new CharacterStyle({ id: "myStyleId", link: "MyLink" });
@ -675,20 +726,39 @@ describe("CharacterStyle", () => {
}); });
}); });
it("#highlight", () => { const highlightTests = [
const style = new CharacterStyle({ {
id: "myStyleId", highlight: "005599",
run: { expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }],
},
{
highlight: "005599",
highlightComplexScript: true,
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }],
},
{
highlight: "005599", highlight: "005599",
highlightComplexScript: false, highlightComplexScript: false,
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }],
}, },
{
highlight: "005599",
highlightComplexScript: "550099",
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "550099" } } }],
},
];
highlightTests.forEach(({ highlight, highlightComplexScript, expected }) => {
it(`#highlight ${highlight} cs ${highlightComplexScript}`, () => {
const style = new CharacterStyle({
id: "myStyleId",
run: { highlight, highlightComplexScript },
}); });
const tree = new Formatter().format(style); const tree = new Formatter().format(style);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:style": [ "w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, { _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{ {
"w:rPr": [{ "w:highlight": { _attr: { "w:val": "005599" } } }], "w:rPr": expected,
}, },
{ {
"w:uiPriority": { "w:uiPriority": {
@ -703,35 +773,81 @@ describe("CharacterStyle", () => {
], ],
}); });
}); });
});
it("#shadow", () => { const shadingTests = [
const style = new CharacterStyle({ {
id: "myStyleId",
run: {
shadow: { shadow: {
type: ShadingType.PERCENT_10, type: ShadingType.PERCENT_10,
fill: "00FFFF", fill: "00FFFF",
color: "FF0000", color: "FF0000",
}, },
shadingComplexScript: false, expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
],
}, },
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: true,
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: false,
expected: [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "00FF00",
},
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "00FF00" } } },
],
},
];
shadingTests.forEach(({ shadow, shading, shadingComplexScript, expected }) => {
it("#shadow correctly", () => {
const style = new CharacterStyle({
id: "myStyleId",
run: { shadow, shading, shadingComplexScript },
}); });
const tree = new Formatter().format(style); const tree = new Formatter().format(style);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:style": [ "w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, { _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{ {
"w:rPr": [ "w:rPr": expected,
{
"w:shd": {
_attr: {
"w:val": "pct10",
"w:fill": "00FFFF",
"w:color": "FF0000",
},
},
},
],
}, },
{ {
"w:uiPriority": { "w:uiPriority": {
@ -748,3 +864,4 @@ describe("CharacterStyle", () => {
}); });
}); });
}); });
});

View File

@ -358,21 +358,37 @@ describe("ParagraphStyle", () => {
}); });
describe("formatting methods: run properties", () => { describe("formatting methods: run properties", () => {
it("#size", () => { const sizeTests = [
{
size: 24,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
},
{
size: 24,
sizeComplexScript: true,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
},
{
size: 24,
sizeComplexScript: false,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }],
},
{
size: 24,
sizeComplexScript: 26,
expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 26 } } }],
},
];
sizeTests.forEach(({ size, sizeComplexScript, expected }) => {
it(`#size ${size} cs ${sizeComplexScript}`, () => {
const style = new ParagraphStyle({ const style = new ParagraphStyle({
id: "myStyleId", id: "myStyleId",
run: { run: { size, sizeComplexScript },
size: 24,
},
}); });
const tree = new Formatter().format(style); const tree = new Formatter().format(style);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:style": [ "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:rPr": expected }],
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, });
{
"w:rPr": [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
},
],
}); });
}); });
@ -543,93 +559,169 @@ describe("ParagraphStyle", () => {
}); });
}); });
it("#bold", () => { const boldTests = [
const style = new ParagraphStyle({ {
id: "myStyleId", bold: true,
run: { expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }],
},
{
bold: true,
boldComplexScript: true,
expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }],
},
{
bold: true, bold: true,
boldComplexScript: false, boldComplexScript: false,
expected: [{ "w:b": { _attr: { "w:val": true } } }],
}, },
];
boldTests.forEach(({ bold, boldComplexScript, expected }) => {
it(`#bold ${bold} cs ${boldComplexScript}`, () => {
const style = new ParagraphStyle({
id: "myStyleId",
run: { bold, boldComplexScript },
}); });
const tree = new Formatter().format(style); const tree = new Formatter().format(style);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:style": [ "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:rPr": expected }],
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, });
{
"w:rPr": [{ "w:b": { _attr: { "w:val": true } } }],
},
],
}); });
}); });
it("#italics", () => { const italicsTests = [
const style = new ParagraphStyle({ {
id: "myStyleId", italics: true,
run: { expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }],
},
{
italics: true,
italicsComplexScript: true,
expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }],
},
{
italics: true, italics: true,
italicsComplexScript: false, italicsComplexScript: false,
expected: [{ "w:i": { _attr: { "w:val": true } } }],
}, },
];
italicsTests.forEach(({ italics, italicsComplexScript, expected }) => {
it(`#italics ${italics} cs ${italicsComplexScript}`, () => {
const style = new ParagraphStyle({
id: "myStyleId",
run: { italics, italicsComplexScript },
}); });
const tree = new Formatter().format(style); const tree = new Formatter().format(style);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:style": [ "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:rPr": expected }],
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, });
{
"w:rPr": [{ "w:i": { _attr: { "w:val": true } } }],
},
],
}); });
}); });
it("#highlight", () => { const highlightTests = [
const style = new ParagraphStyle({ {
id: "myStyleId", highlight: "005599",
run: { expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }],
},
{
highlight: "005599",
highlightComplexScript: true,
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }],
},
{
highlight: "005599", highlight: "005599",
highlightComplexScript: false, highlightComplexScript: false,
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }],
}, },
{
highlight: "005599",
highlightComplexScript: "550099",
expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "550099" } } }],
},
];
highlightTests.forEach(({ highlight, highlightComplexScript, expected }) => {
it(`#highlight ${highlight} cs ${highlightComplexScript}`, () => {
const style = new ParagraphStyle({
id: "myStyleId",
run: { highlight, highlightComplexScript },
}); });
const tree = new Formatter().format(style); const tree = new Formatter().format(style);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:style": [ "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:rPr": expected }],
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, });
{
"w:rPr": [{ "w:highlight": { _attr: { "w:val": "005599" } } }],
},
],
}); });
}); });
it("#shadow", () => { const shadingTests = [
const style = new ParagraphStyle({ {
id: "myStyleId",
run: {
shadow: { shadow: {
type: ShadingType.PERCENT_10, type: ShadingType.PERCENT_10,
fill: "00FFFF", fill: "00FFFF",
color: "FF0000", color: "FF0000",
}, },
shadingComplexScript: false, expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
],
}, },
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: true,
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: false,
expected: [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }],
},
{
shading: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: {
type: ShadingType.PERCENT_10,
fill: "00FFFF",
color: "00FF00",
},
expected: [
{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
{ "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "00FF00" } } },
],
},
];
shadingTests.forEach(({ shadow, shading, shadingComplexScript, expected }) => {
it("#shadow correctly", () => {
const style = new ParagraphStyle({
id: "myStyleId",
run: { shadow, shading, shadingComplexScript },
}); });
const tree = new Formatter().format(style); const tree = new Formatter().format(style);
expect(tree).to.deep.equal({ expect(tree).to.deep.equal({
"w:style": [ "w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:rPr": expected }],
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, });
{
"w:rPr": [
{
"w:shd": {
_attr: {
"w:val": "pct10",
"w:fill": "00FFFF",
"w:color": "FF0000",
},
},
},
],
},
],
}); });
}); });