Files
docx-js/src/file/settings/settings.spec.ts

226 lines
7.5 KiB
TypeScript
Raw Normal View History

2023-06-05 00:33:43 +01:00
import { describe, expect, it } from "vitest";
2018-10-26 01:04:07 +01:00
import { Formatter } from "@export/formatter";
2018-10-26 01:04:07 +01:00
import { Settings } from "./settings";
2018-09-20 10:11:59 -03:00
describe("Settings", () => {
describe("#constructor", () => {
it("should create a empty Settings with correct rootKey", () => {
const settings = new Settings({});
2018-09-20 10:11:59 -03:00
const tree = new Formatter().format(settings);
expect(Object.keys(tree)).has.length(1);
expect(tree["w:settings"]).to.be.an("array");
2018-09-20 10:11:59 -03:00
});
it("should add updateFields setting", () => {
2021-03-16 00:57:27 +00:00
const settings = new Settings({
updateFields: true,
2021-03-16 00:57:27 +00:00
});
const tree = new Formatter().format(settings);
expect(Object.keys(tree)).has.length(1);
expect(tree["w:settings"]).to.be.an("array");
expect(tree["w:settings"]).to.deep.include({
"w:updateFields": {},
2021-03-16 00:57:27 +00:00
});
2018-09-20 10:11:59 -03:00
});
it("should indicate modern word compatibility by default", () => {
const settings = new Settings({});
const tree = new Formatter().format(settings);
expect(Object.keys(tree)).has.length(1);
expect(tree["w:settings"]).to.be.an("array");
const compat = tree["w:settings"][2];
expect(compat).to.be.an("object").with.keys("w:compat");
expect(compat["w:compat"]).to.deep.include({
2021-02-27 01:40:55 +00:00
"w:compatSetting": {
_attr: {
"w:val": 15,
"w:uri": "http://schemas.microsoft.com/office/word",
"w:name": "compatibilityMode",
},
},
});
});
it("should add trackRevisions setting", () => {
2021-03-16 00:57:27 +00:00
const settings = new Settings({
trackRevisions: true,
2021-03-16 00:57:27 +00:00
});
const tree = new Formatter().format(settings);
expect(Object.keys(tree)).has.length(1);
expect(tree["w:settings"]).to.be.an("array");
2021-03-16 00:57:27 +00:00
expect(tree["w:settings"]).to.deep.include({
"w:trackRevisions": {},
2021-03-16 00:57:27 +00:00
});
});
2022-10-29 15:10:02 +01:00
it("should add compatibility setting with default compatability version", () => {
const settings = new Settings({
compatibility: {},
});
const tree = new Formatter().format(settings);
expect(Object.keys(tree)).has.length(1);
expect(tree["w:settings"]).to.be.an("array");
expect(tree["w:settings"]).to.deep.include({
"w:compat": [
{
"w:compatSetting": {
_attr: {
"w:name": "compatibilityMode",
"w:uri": "http://schemas.microsoft.com/office/word",
"w:val": 15,
},
},
},
],
});
});
it("should add compatibility setting with version", () => {
const settings = new Settings({
compatibility: {
version: 99,
},
});
const tree = new Formatter().format(settings);
expect(Object.keys(tree)).has.length(1);
expect(tree["w:settings"]).to.be.an("array");
expect(tree["w:settings"]).to.deep.include({
"w:compat": [
{
"w:compatSetting": {
_attr: {
"w:name": "compatibilityMode",
"w:uri": "http://schemas.microsoft.com/office/word",
"w:val": 99,
},
},
},
],
});
});
it("should add defaultTabStop setting with version", () => {
const settings = new Settings({
defaultTabStop: 100,
});
const tree = new Formatter().format(settings);
expect(Object.keys(tree)).has.length(1);
expect(tree["w:settings"]).to.be.an("array");
expect(tree["w:settings"]).to.deep.include({
"w:defaultTabStop": {
_attr: {
"w:val": 100,
},
},
});
});
it("should add autoHyphenation setting", () => {
const options = {
hyphenation: {
autoHyphenation: true,
},
};
const tree = new Formatter().format(new Settings(options));
expect(Object.keys(tree)).has.length(1);
expect(tree["w:settings"]).to.be.an("array");
expect(tree["w:settings"]).to.deep.include({
"w:autoHyphenation": {},
});
});
it("should add doNotHyphenateCaps setting", () => {
const options = {
hyphenation: {
doNotHyphenateCaps: true,
},
};
const tree = new Formatter().format(new Settings(options));
expect(Object.keys(tree)).has.length(1);
expect(tree["w:settings"]).to.be.an("array");
expect(tree["w:settings"]).to.deep.include({
"w:doNotHyphenateCaps": {},
});
});
it("should add hyphenationZone setting", () => {
const options = {
hyphenation: {
hyphenationZone: 200,
},
};
const tree = new Formatter().format(new Settings(options));
expect(Object.keys(tree)).has.length(1);
expect(tree["w:settings"]).to.be.an("array");
expect(tree["w:settings"]).to.deep.include({
"w:hyphenationZone": {
_attr: {
"w:val": 200,
},
},
});
});
it("should add consecutiveHyphenLimit setting", () => {
const options = {
hyphenation: {
consecutiveHyphenLimit: 3,
},
};
const tree = new Formatter().format(new Settings(options));
expect(Object.keys(tree)).has.length(1);
expect(tree["w:settings"]).to.be.an("array");
expect(tree["w:settings"]).to.deep.include({
"w:consecutiveHyphenLimit": {
_attr: {
"w:val": 3,
},
},
});
});
2022-10-29 15:10:02 +01:00
// TODO: Remove when deprecating compatibilityModeVersion
it("should add compatibility setting with legacy version", () => {
const settings = new Settings({
compatibilityModeVersion: 99,
});
const tree = new Formatter().format(settings);
expect(Object.keys(tree)).has.length(1);
expect(tree["w:settings"]).to.be.an("array");
expect(tree["w:settings"]).to.deep.include({
"w:compat": [
{
"w:compatSetting": {
_attr: {
"w:name": "compatibilityMode",
"w:uri": "http://schemas.microsoft.com/office/word",
"w:val": 99,
},
},
},
],
});
});
2021-03-16 00:57:27 +00:00
});
2018-09-20 10:11:59 -03:00
});