#332 Compatability mode

This commit is contained in:
Dolan
2021-02-27 01:40:55 +00:00
parent 84f48446df
commit 10455a534f
8 changed files with 108 additions and 37 deletions

View File

@ -7,7 +7,7 @@ import { Settings } from "./settings";
describe("Settings", () => {
describe("#constructor", () => {
it("should create a empty Settings with correct rootKey", () => {
const settings = new Settings();
const settings = new Settings({});
const tree = new Formatter().format(settings);
let keys = Object.keys(tree);
expect(keys).is.an.instanceof(Array);
@ -15,7 +15,7 @@ describe("Settings", () => {
expect(keys[0]).to.be.equal("w:settings");
keys = Object.keys(tree["w:settings"]);
expect(keys).is.an.instanceof(Array);
expect(keys).has.length(2);
expect(keys).has.length(3);
});
});
describe("#addUpdateFields", () => {
@ -27,16 +27,16 @@ describe("Settings", () => {
expect(keys[0]).to.be.equal("w:settings");
const rootArray = tree["w:settings"];
expect(rootArray).is.an.instanceof(Array);
expect(rootArray).has.length(3);
expect(rootArray).has.length(4);
keys = Object.keys(rootArray[0]);
expect(keys).is.an.instanceof(Array);
expect(keys).has.length(1);
expect(keys[0]).to.be.equal("_attr");
keys = Object.keys(rootArray[2]);
keys = Object.keys(rootArray[3]);
expect(keys).is.an.instanceof(Array);
expect(keys).has.length(1);
expect(keys[0]).to.be.equal("w:updateFields");
const updateFields = rootArray[2]["w:updateFields"];
const updateFields = rootArray[3]["w:updateFields"];
keys = Object.keys(updateFields);
expect(keys).is.an.instanceof(Array);
expect(keys).has.length(1);
@ -45,12 +45,12 @@ describe("Settings", () => {
expect(updateFieldsAttr["w:val"]).to.be.equal(true);
};
it("should add a UpdateFields with value true", () => {
const settings = new Settings();
const settings = new Settings({});
settings.addUpdateFields();
assertSettingsWithUpdateFields(settings);
});
it("should add a UpdateFields with value true only once", () => {
const settings = new Settings();
const settings = new Settings({});
settings.addUpdateFields();
assertSettingsWithUpdateFields(settings);
settings.addUpdateFields();
@ -58,9 +58,8 @@ describe("Settings", () => {
});
});
describe("#addCompatibility", () => {
it("should add an empty Compatibility", () => {
const settings = new Settings();
settings.addCompatibility();
it("should add an empty Compatibility by default", () => {
const settings = new Settings({});
const tree = new Formatter().format(settings);
let keys: string[] = Object.keys(tree);
@ -72,15 +71,24 @@ describe("Settings", () => {
expect(keys).is.an.instanceof(Array);
expect(keys).has.length(1);
expect(keys[0]).to.be.equal("_attr");
keys = Object.keys(rootArray[2]);
keys = Object.keys(rootArray[1]);
expect(keys).is.an.instanceof(Array);
expect(keys).has.length(1);
expect(keys[0]).to.be.equal("w:compat");
expect(rootArray[1]["w:compat"][0]).to.deep.equal({
"w:compatSetting": {
_attr: {
"w:val": 15,
"w:uri": "http://schemas.microsoft.com/office/word",
"w:name": "compatibilityMode",
},
},
});
});
});
describe("#addTrackRevisions", () => {
it("should add an empty Track Revisions", () => {
const settings = new Settings();
const settings = new Settings({});
settings.addTrackRevisions();
const tree = new Formatter().format(settings);
@ -88,12 +96,12 @@ describe("Settings", () => {
expect(keys[0]).to.be.equal("w:settings");
const rootArray = tree["w:settings"];
expect(rootArray).is.an.instanceof(Array);
expect(rootArray).has.length(3);
expect(rootArray).has.length(4);
keys = Object.keys(rootArray[0]);
expect(keys).is.an.instanceof(Array);
expect(keys).has.length(1);
expect(keys[0]).to.be.equal("_attr");
keys = Object.keys(rootArray[2]);
keys = Object.keys(rootArray[3]);
expect(keys).is.an.instanceof(Array);
expect(keys).has.length(1);
expect(keys[0]).to.be.equal("w:trackRevisions");
@ -101,7 +109,7 @@ describe("Settings", () => {
});
describe("#addTrackRevisionsTwice", () => {
it("should add an empty Track Revisions if called twice", () => {
const settings = new Settings();
const settings = new Settings({});
settings.addTrackRevisions();
settings.addTrackRevisions();
@ -110,12 +118,12 @@ describe("Settings", () => {
expect(keys[0]).to.be.equal("w:settings");
const rootArray = tree["w:settings"];
expect(rootArray).is.an.instanceof(Array);
expect(rootArray).has.length(3);
expect(rootArray).has.length(4);
keys = Object.keys(rootArray[0]);
expect(keys).is.an.instanceof(Array);
expect(keys).has.length(1);
expect(keys[0]).to.be.equal("_attr");
keys = Object.keys(rootArray[2]);
keys = Object.keys(rootArray[3]);
expect(keys).is.an.instanceof(Array);
expect(keys).has.length(1);
expect(keys[0]).to.be.equal("w:trackRevisions");