add createLevel method to AbstractNumbering

This commit is contained in:
felipe
2017-03-08 18:03:24 +01:00
parent a3d2323254
commit 1fe7ab90f2
2 changed files with 19 additions and 0 deletions

View File

@ -35,6 +35,12 @@ export class AbstractNumbering extends XmlComponent {
this.root.push(level); this.root.push(level);
} }
public createLevel(num: number, format: string, text: string, align: string) {
const level = new Level(num, format, text, align);
this.addLevel(level);
return level;
}
public clearVariables(): void { public clearVariables(): void {
_.forEach(this.root, (element) => { _.forEach(this.root, (element) => {
element.clearVariables(); element.clearVariables();

View File

@ -82,4 +82,17 @@ describe("AbstractNumbering", () => {
const abstractNumbering = new AbstractNumbering(5); const abstractNumbering = new AbstractNumbering(5);
expect(abstractNumbering.id).to.equal(5); expect(abstractNumbering.id).to.equal(5);
}); });
describe("#createLevel", () => {
it("creates a level with the given characteristics", () => {
const abstractNumbering = new AbstractNumbering(1);
const level = abstractNumbering.createLevel(3, "lowerLetter", "%1)", "start");
const tree = new Formatter().format(level);
expect(tree['w:lvl']).to.include({_attr: {"w:ilvl": 3, "w15:tentative": 1}})
expect(tree['w:lvl']).to.include({"w:start": [{_attr: {"w:val": 1}}]})
expect(tree['w:lvl']).to.include({"w:lvlJc": [{_attr: {"w:val": "start"}}]})
expect(tree['w:lvl']).to.include({"w:numFmt": [{_attr: {"w:val": "lowerLetter"}}]})
expect(tree['w:lvl']).to.include({"w:lvlText": [{"_attr": {"w:val": "%1)"}}]})
});
});
}); });