: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 = [
const abstractNumbering = new AbstractNumbering(1, [ {
{ size: 24,
level: 0, expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
format: "lowerRoman", },
text: "%0.", {
style: { size: 24,
run: { sizeComplexScript: true,
size: 24, expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
sizeComplexScript: false, },
{
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, [
{
level: 0,
format: "lowerRoman",
text: "%0.",
style: {
run: { size, sizeComplexScript },
}, },
}, },
}, ]);
]); const tree = new Formatter().format(abstractNumbering);
const tree = new Formatter().format(abstractNumbering); expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected });
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
"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,
level: 0, expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }],
format: "lowerRoman", },
text: "%0.", {
style: { bold: true,
run: { boldComplexScript: true,
bold: true, expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }],
boldComplexScript: false, },
{
bold: true,
boldComplexScript: false,
expected: [{ "w:b": { _attr: { "w:val": true } } }],
},
];
boldTests.forEach(({ bold, boldComplexScript, expected }) => {
it(`#bold ${bold} cs ${boldComplexScript}`, () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: "lowerRoman",
text: "%0.",
style: {
run: { bold, boldComplexScript },
}, },
}, },
}, ]);
]); const tree = new Formatter().format(abstractNumbering);
const tree = new Formatter().format(abstractNumbering); expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected });
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
"w:rPr": [{ "w:b": { _attr: { "w:val": true } } }],
}); });
}); });
it("#italics", () => { const italicsTests = [
const abstractNumbering = new AbstractNumbering(1, [ {
{ italics: true,
level: 0, expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }],
format: "lowerRoman", },
text: "%0.", {
style: { italics: true,
run: { italicsComplexScript: true,
italics: true, expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }],
italicsComplexScript: false, },
{
italics: true,
italicsComplexScript: false,
expected: [{ "w:i": { _attr: { "w:val": true } } }],
},
];
italicsTests.forEach(({ italics, italicsComplexScript, expected }) => {
it(`#italics ${italics} cs ${italicsComplexScript}`, () => {
const abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: "lowerRoman",
text: "%0.",
style: {
run: { italics, italicsComplexScript },
}, },
}, },
}, ]);
]); const tree = new Formatter().format(abstractNumbering);
const tree = new Formatter().format(abstractNumbering); expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected });
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
"w:rPr": [{ "w:i": { _attr: { "w:val": true } } }],
}); });
}); });
it("#highlight", () => { const highlightTests = [
const abstractNumbering = new AbstractNumbering(1, [ {
{ highlight: "005599",
level: 0, expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }],
format: "lowerRoman", },
text: "%0.", {
style: { highlight: "005599",
run: { highlightComplexScript: true,
highlight: "005599", expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }],
highlightComplexScript: false, },
{
highlight: "005599",
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 abstractNumbering = new AbstractNumbering(1, [
{
level: 0,
format: "lowerRoman",
text: "%0.",
style: {
run: { highlight, highlightComplexScript },
}, },
}, },
}, ]);
]); const tree = new Formatter().format(abstractNumbering);
const tree = new Formatter().format(abstractNumbering); expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ "w:rPr": expected });
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
"w:rPr": [{ "w:highlight": { _attr: { "w:val": "005599" } } }],
}); });
}); });
it("#shadow", () => { const shadingTests = [
const abstractNumbering = new AbstractNumbering(1, [ {
{ shadow: {
level: 0, type: ShadingType.PERCENT_10,
format: "lowerRoman", fill: "00FFFF",
text: "%0.", color: "FF0000",
style: { },
run: { expected: [
shadow: { { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
type: ShadingType.PERCENT_10, { "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
fill: "00FFFF", ],
color: "FF0000", },
}, {
shadingComplexScript: false, 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({ "w:rPr": expected });
expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({
"w:rPr": [{ "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } }],
}); });
}); });

View File

@ -334,31 +334,52 @@ describe("CharacterStyle", () => {
}); });
describe("formatting methods: run properties", () => { describe("formatting methods: run properties", () => {
it("#size", () => { const sizeTests = [
const style = new CharacterStyle({ {
id: "myStyleId", size: 24,
run: { expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
size: 24, },
}, {
}); size: 24,
const tree = new Formatter().format(style); sizeComplexScript: true,
expect(tree).to.deep.equal({ expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
"w:style": [ },
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, {
{ size: 24,
"w:rPr": [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }], sizeComplexScript: false,
}, expected: [{ "w:sz": { _attr: { "w:val": 24 } } }],
{ },
"w:uiPriority": { {
_attr: { size: 24,
"w:val": 99, 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({
id: "myStyleId",
run: { size, sizeComplexScript },
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{
"w:rPr": expected,
},
{
"w:uiPriority": {
_attr: {
"w:val": 99,
},
}, },
}, },
}, {
{ "w:unhideWhenUsed": EMPTY_OBJECT,
"w:unhideWhenUsed": EMPTY_OBJECT, },
}, ],
], });
}); });
}); });
@ -577,61 +598,91 @@ 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: false, {
}, bold: true,
}); boldComplexScript: true,
const tree = new Formatter().format(style); expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }],
expect(tree).to.deep.equal({ },
"w:style": [ {
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, bold: true,
{ boldComplexScript: false,
"w:rPr": [{ "w:b": { _attr: { "w:val": true } } }], expected: [{ "w:b": { _attr: { "w:val": true } } }],
}, },
{ ];
"w:uiPriority": { boldTests.forEach(({ bold, boldComplexScript, expected }) => {
_attr: { it(`#bold ${bold} cs ${boldComplexScript}`, () => {
"w:val": 99, const style = new CharacterStyle({
id: "myStyleId",
run: { bold, boldComplexScript },
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{
"w:rPr": expected,
},
{
"w:uiPriority": {
_attr: {
"w:val": 99,
},
}, },
}, },
}, {
{ "w:unhideWhenUsed": EMPTY_OBJECT,
"w:unhideWhenUsed": EMPTY_OBJECT, },
}, ],
], });
}); });
}); });
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: false, {
}, italics: true,
}); italicsComplexScript: true,
const tree = new Formatter().format(style); expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }],
expect(tree).to.deep.equal({ },
"w:style": [ {
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, italics: true,
{ italicsComplexScript: false,
"w:rPr": [{ "w:i": { _attr: { "w:val": true } } }], expected: [{ "w:i": { _attr: { "w:val": true } } }],
}, },
{ ];
"w:uiPriority": { italicsTests.forEach(({ italics, italicsComplexScript, expected }) => {
_attr: { it(`#italics ${italics} cs ${italicsComplexScript}`, () => {
"w:val": 99, const style = new CharacterStyle({
id: "myStyleId",
run: { italics, italicsComplexScript },
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{
"w:rPr": expected,
},
{
"w:uiPriority": {
_attr: {
"w:val": 99,
},
}, },
}, },
}, {
{ "w:unhideWhenUsed": EMPTY_OBJECT,
"w:unhideWhenUsed": EMPTY_OBJECT, },
}, ],
], });
}); });
}); });
@ -675,75 +726,141 @@ 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: false, {
}, highlight: "005599",
}); highlightComplexScript: true,
const tree = new Formatter().format(style); expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }],
expect(tree).to.deep.equal({ },
"w:style": [ {
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, highlight: "005599",
{ highlightComplexScript: false,
"w:rPr": [{ "w:highlight": { _attr: { "w:val": "005599" } } }], expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }],
}, },
{ {
"w:uiPriority": { highlight: "005599",
_attr: { highlightComplexScript: "550099",
"w:val": 99, 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);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{
"w:rPr": expected,
},
{
"w:uiPriority": {
_attr: {
"w:val": 99,
},
}, },
}, },
}, {
{ "w:unhideWhenUsed": EMPTY_OBJECT,
"w:unhideWhenUsed": EMPTY_OBJECT, },
}, ],
], });
}); });
}); });
it("#shadow", () => { const shadingTests = [
const style = new CharacterStyle({ {
id: "myStyleId", shadow: {
run: { type: ShadingType.PERCENT_10,
shadow: { fill: "00FFFF",
type: ShadingType.PERCENT_10, color: "FF0000",
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: false,
}, },
}); expected: [
const tree = new Formatter().format(style); { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
expect(tree).to.deep.equal({ { "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
"w:style": [ ],
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, },
{ {
"w:rPr": [ shading: {
{ type: ShadingType.PERCENT_10,
"w:shd": { fill: "00FFFF",
_attr: { color: "FF0000",
"w:val": "pct10", },
"w:fill": "00FFFF", expected: [
"w:color": "FF0000", { "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);
expect(tree).to.deep.equal({
"w:style": [
{ _attr: { "w:type": "character", "w:styleId": "myStyleId" } },
{
"w:rPr": expected,
},
{
"w:uiPriority": {
_attr: {
"w:val": 99,
}, },
}, },
],
},
{
"w:uiPriority": {
_attr: {
"w:val": 99,
},
}, },
}, {
{ "w:unhideWhenUsed": EMPTY_OBJECT,
"w:unhideWhenUsed": EMPTY_OBJECT, },
}, ],
], });
}); });
}); });
}); });

View File

@ -358,21 +358,37 @@ describe("ParagraphStyle", () => {
}); });
describe("formatting methods: run properties", () => { describe("formatting methods: run properties", () => {
it("#size", () => { const sizeTests = [
const style = new ParagraphStyle({ {
id: "myStyleId", size: 24,
run: { expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
size: 24, },
}, {
}); size: 24,
const tree = new Formatter().format(style); sizeComplexScript: true,
expect(tree).to.deep.equal({ expected: [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 24 } } }],
"w:style": [ },
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, {
{ size: 24,
"w:rPr": [{ "w:sz": { _attr: { "w:val": 24 } } }, { "w:szCs": { _attr: { "w:val": 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({
id: "myStyleId",
run: { size, sizeComplexScript },
});
const tree = new Formatter().format(style);
expect(tree).to.deep.equal({
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:rPr": expected }],
});
}); });
}); });
@ -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: false, {
}, bold: true,
}); boldComplexScript: true,
const tree = new Formatter().format(style); expected: [{ "w:b": { _attr: { "w:val": true } } }, { "w:bCs": { _attr: { "w:val": true } } }],
expect(tree).to.deep.equal({ },
"w:style": [ {
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, bold: true,
{ boldComplexScript: false,
"w:rPr": [{ "w:b": { _attr: { "w:val": true } } }], 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);
expect(tree).to.deep.equal({
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:rPr": expected }],
});
}); });
}); });
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: false, {
}, italics: true,
}); italicsComplexScript: true,
const tree = new Formatter().format(style); expected: [{ "w:i": { _attr: { "w:val": true } } }, { "w:iCs": { _attr: { "w:val": true } } }],
expect(tree).to.deep.equal({ },
"w:style": [ {
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, italics: true,
{ italicsComplexScript: false,
"w:rPr": [{ "w:i": { _attr: { "w:val": true } } }], 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);
expect(tree).to.deep.equal({
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:rPr": expected }],
});
}); });
}); });
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: false, {
}, highlight: "005599",
}); highlightComplexScript: true,
const tree = new Formatter().format(style); expected: [{ "w:highlight": { _attr: { "w:val": "005599" } } }, { "w:highlightCs": { _attr: { "w:val": "005599" } } }],
expect(tree).to.deep.equal({ },
"w:style": [ {
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, highlight: "005599",
{ highlightComplexScript: false,
"w:rPr": [{ "w:highlight": { _attr: { "w:val": "005599" } } }], 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);
expect(tree).to.deep.equal({
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:rPr": expected }],
});
}); });
}); });
it("#shadow", () => { const shadingTests = [
const style = new ParagraphStyle({ {
id: "myStyleId", shadow: {
run: { type: ShadingType.PERCENT_10,
shadow: { fill: "00FFFF",
type: ShadingType.PERCENT_10, color: "FF0000",
fill: "00FFFF",
color: "FF0000",
},
shadingComplexScript: false,
}, },
}); expected: [
const tree = new Formatter().format(style); { "w:shd": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
expect(tree).to.deep.equal({ { "w:shdCs": { _attr: { "w:val": "pct10", "w:fill": "00FFFF", "w:color": "FF0000" } } },
"w:style": [
{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } },
{
"w:rPr": [
{
"w:shd": {
_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);
expect(tree).to.deep.equal({
"w:style": [{ _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:rPr": expected }],
});
}); });
}); });