From 0bc36d924ffd05fe044e50d025782aa87b7ba0ad Mon Sep 17 00:00:00 2001 From: Dolan Date: Sat, 13 Mar 2021 22:10:00 +0000 Subject: [PATCH] Write tests --- .nycrc | 8 ++--- .../app-properties-attributes.ts | 6 ++-- .../content-types/content-types-attributes.ts | 6 ++-- .../default/default-attributes.ts | 6 ++-- .../override/override-attributes.ts | 6 ++-- .../styles/latent-styles/exceptions.spec.ts | 32 +++++++++++++++++ src/file/styles/latent-styles/index.ts | 13 +------ .../latent-styles/latent-styles.spec.ts | 34 +++++++++++++++++++ .../styles/latent-styles/latent-styles.ts | 12 +++++++ 9 files changed, 91 insertions(+), 32 deletions(-) create mode 100644 src/file/styles/latent-styles/exceptions.spec.ts create mode 100644 src/file/styles/latent-styles/latent-styles.spec.ts create mode 100644 src/file/styles/latent-styles/latent-styles.ts diff --git a/.nycrc b/.nycrc index b50b7553fb..23a3fdfe39 100644 --- a/.nycrc +++ b/.nycrc @@ -1,9 +1,9 @@ { "check-coverage": true, - "lines": 98.31, - "functions": 95.83, - "branches": 95.38, - "statements": 98.29, + "lines": 98.47, + "functions": 96.44, + "branches": 95.39, + "statements": 98.45, "include": [ "src/**/*.ts" ], diff --git a/src/file/app-properties/app-properties-attributes.ts b/src/file/app-properties/app-properties-attributes.ts index fa36937ebf..dfd26d6fcb 100644 --- a/src/file/app-properties/app-properties-attributes.ts +++ b/src/file/app-properties/app-properties-attributes.ts @@ -1,11 +1,9 @@ import { XmlAttributeComponent } from "file/xml-components"; -export interface IAppPropertiesAttributes { +export class AppPropertiesAttributes extends XmlAttributeComponent<{ readonly xmlns: string; readonly vt: string; -} - -export class AppPropertiesAttributes extends XmlAttributeComponent { +}> { protected readonly xmlKeys = { xmlns: "xmlns", vt: "xmlns:vt", diff --git a/src/file/content-types/content-types-attributes.ts b/src/file/content-types/content-types-attributes.ts index 1d940bdda1..0338cfc1b7 100644 --- a/src/file/content-types/content-types-attributes.ts +++ b/src/file/content-types/content-types-attributes.ts @@ -1,10 +1,8 @@ import { XmlAttributeComponent } from "file/xml-components"; -export interface IContentTypeAttributes { +export class ContentTypeAttributes extends XmlAttributeComponent<{ readonly xmlns?: string; -} - -export class ContentTypeAttributes extends XmlAttributeComponent { +}> { protected readonly xmlKeys = { xmlns: "xmlns", }; diff --git a/src/file/content-types/default/default-attributes.ts b/src/file/content-types/default/default-attributes.ts index 727cb80c6f..dd9872f3f9 100644 --- a/src/file/content-types/default/default-attributes.ts +++ b/src/file/content-types/default/default-attributes.ts @@ -1,11 +1,9 @@ import { XmlAttributeComponent } from "file/xml-components"; -export interface IDefaultAttributes { +export class DefaultAttributes extends XmlAttributeComponent<{ readonly contentType: string; readonly extension?: string; -} - -export class DefaultAttributes extends XmlAttributeComponent { +}> { protected readonly xmlKeys = { contentType: "ContentType", extension: "Extension", diff --git a/src/file/content-types/override/override-attributes.ts b/src/file/content-types/override/override-attributes.ts index 7370aabfd5..9f5e5eca34 100644 --- a/src/file/content-types/override/override-attributes.ts +++ b/src/file/content-types/override/override-attributes.ts @@ -1,11 +1,9 @@ import { XmlAttributeComponent } from "file/xml-components"; -export interface IOverrideAttributes { +export class OverrideAttributes extends XmlAttributeComponent<{ readonly contentType: string; readonly partName?: string; -} - -export class OverrideAttributes extends XmlAttributeComponent { +}> { protected readonly xmlKeys = { contentType: "ContentType", partName: "PartName", diff --git a/src/file/styles/latent-styles/exceptions.spec.ts b/src/file/styles/latent-styles/exceptions.spec.ts new file mode 100644 index 0000000000..2fc477b762 --- /dev/null +++ b/src/file/styles/latent-styles/exceptions.spec.ts @@ -0,0 +1,32 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { LatentStyleException } from "./exceptions"; + +describe("LatentStyleException", () => { + describe("#constructor()", () => { + it("should create", () => { + const currentLatentStyleException = new LatentStyleException({ + name: "test-name", + uiPriority: "test-uiPriority", + qFormat: "test-qFormat", + semiHidden: "test-semiHidden", + unhideWhenUsed: "test-unhideWhenUsed", + }); + + const tree = new Formatter().format(currentLatentStyleException); + expect(tree).to.deep.equal({ + "w:lsdException": { + _attr: { + "w:name": "test-name", + "w:qFormat": "test-qFormat", + "w:semiHidden": "test-semiHidden", + "w:uiPriority": "test-uiPriority", + "w:unhideWhenUsed": "test-unhideWhenUsed", + }, + }, + }); + }); + }); +}); diff --git a/src/file/styles/latent-styles/index.ts b/src/file/styles/latent-styles/index.ts index 47a48f0a61..5fd2ec64cf 100644 --- a/src/file/styles/latent-styles/index.ts +++ b/src/file/styles/latent-styles/index.ts @@ -1,12 +1 @@ -import { XmlComponent } from "file/xml-components"; -import { LatentStyleException } from "./exceptions"; - -export class LatentStyles extends XmlComponent { - constructor() { - super("w:latentStyles"); - } - - public push(latentException: LatentStyleException): void { - this.root.push(latentException); - } -} +export * from "./latent-styles"; diff --git a/src/file/styles/latent-styles/latent-styles.spec.ts b/src/file/styles/latent-styles/latent-styles.spec.ts new file mode 100644 index 0000000000..78807c0306 --- /dev/null +++ b/src/file/styles/latent-styles/latent-styles.spec.ts @@ -0,0 +1,34 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { LatentStyleException } from "./exceptions"; +import { LatentStyles } from "./latent-styles"; + +describe("LatentStyles", () => { + describe("#constructor()", () => { + it("should create", () => { + const currentLatentStyles = new LatentStyles(); + + const tree = new Formatter().format(currentLatentStyles); + expect(tree).to.deep.equal({ + "w:latentStyles": {}, + }); + }); + + it("should create with exception", () => { + const currentLatentStyles = new LatentStyles(new LatentStyleException({})); + + const tree = new Formatter().format(currentLatentStyles); + expect(tree).to.deep.equal({ + "w:latentStyles": [ + { + "w:lsdException": { + _attr: {}, + }, + }, + ], + }); + }); + }); +}); diff --git a/src/file/styles/latent-styles/latent-styles.ts b/src/file/styles/latent-styles/latent-styles.ts new file mode 100644 index 0000000000..d0f9bd3034 --- /dev/null +++ b/src/file/styles/latent-styles/latent-styles.ts @@ -0,0 +1,12 @@ +import { XmlComponent } from "file/xml-components"; +import { LatentStyleException } from "./exceptions"; + +export class LatentStyles extends XmlComponent { + constructor(latentException?: LatentStyleException) { + super("w:latentStyles"); + + if (latentException) { + this.root.push(latentException); + } + } +}