#2733 Add error if level exceeds 9

This commit is contained in:
Dolan
2021-12-18 15:42:35 +00:00
parent ed8b4180f8
commit 6d3ebf90c1
7 changed files with 92 additions and 9 deletions

View File

@ -0,0 +1,25 @@
import { expect } from "chai";
import { LevelFormat, LevelSuffix } from ".";
import { AlignmentType } from "..";
import { Level } from "./level";
describe("Level", () => {
describe("#constructor", () => {
it("should throw an error if level exceeds 9", () => {
expect(
() =>
new Level({
level: 10,
format: LevelFormat.BULLET,
text: "test",
alignment: AlignmentType.BOTH,
start: 3,
style: { run: {}, paragraph: {} },
suffix: LevelSuffix.SPACE,
}),
).to.throw();
});
});
});

View File

@ -161,6 +161,12 @@ export class LevelBase extends XmlComponent {
this.root.push(this.paragraphProperties);
this.root.push(this.runProperties);
if (level > 9) {
throw new Error(
"Level cannot be greater than 9. Read more here: https://answers.microsoft.com/en-us/msoffice/forum/all/does-word-support-more-than-9-list-levels/d130fdcd-1781-446d-8c84-c6c79124e4d7",
);
}
this.root.push(
new LevelAttributes({
ilvl: decimalNumber(level),