#2733 Add error if level exceeds 9
This commit is contained in:
@ -5,21 +5,17 @@ import { Formatter } from "export/formatter";
|
||||
import { NumberProperties } from "./unordered-list";
|
||||
|
||||
describe("NumberProperties", () => {
|
||||
let numberProperties: NumberProperties;
|
||||
|
||||
beforeEach(() => {
|
||||
numberProperties = new NumberProperties(5, 10);
|
||||
});
|
||||
|
||||
describe("#constructor()", () => {
|
||||
it("should create a Number Properties with correct root key", () => {
|
||||
const numberProperties = new NumberProperties(5, 9);
|
||||
|
||||
const tree = new Formatter().format(numberProperties);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:numPr": [
|
||||
{
|
||||
"w:ilvl": {
|
||||
_attr: {
|
||||
"w:val": 10,
|
||||
"w:val": 9,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -33,5 +29,9 @@ describe("NumberProperties", () => {
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("should throw an error if level exceeds 9", () => {
|
||||
expect(() => new NumberProperties(5, 10)).to.throw();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -11,6 +11,11 @@ export class NumberProperties extends XmlComponent {
|
||||
class IndentLevel extends XmlComponent {
|
||||
constructor(level: number) {
|
||||
super("w:ilvl");
|
||||
|
||||
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 Attributes({
|
||||
val: level,
|
||||
|
Reference in New Issue
Block a user