Fix tests and linting

This commit is contained in:
Dolan Miu
2022-06-19 00:31:36 +01:00
parent d6ec275778
commit 233a29bfef
9 changed files with 42 additions and 13 deletions

View File

@ -23,7 +23,7 @@ describe("Compiler", () => {
const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name); const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name);
expect(fileNames).is.an.instanceof(Array); expect(fileNames).is.an.instanceof(Array);
expect(fileNames).has.length(16); expect(fileNames).has.length(17);
expect(fileNames).to.include("word/document.xml"); expect(fileNames).to.include("word/document.xml");
expect(fileNames).to.include("word/styles.xml"); expect(fileNames).to.include("word/styles.xml");
expect(fileNames).to.include("docProps/core.xml"); expect(fileNames).to.include("docProps/core.xml");
@ -33,6 +33,7 @@ describe("Compiler", () => {
expect(fileNames).to.include("word/footnotes.xml"); expect(fileNames).to.include("word/footnotes.xml");
expect(fileNames).to.include("word/_rels/footnotes.xml.rels"); expect(fileNames).to.include("word/_rels/footnotes.xml.rels");
expect(fileNames).to.include("word/settings.xml"); expect(fileNames).to.include("word/settings.xml");
expect(fileNames).to.include("word/comments.xml");
expect(fileNames).to.include("word/_rels/document.xml.rels"); expect(fileNames).to.include("word/_rels/document.xml.rels");
expect(fileNames).to.include("[Content_Types].xml"); expect(fileNames).to.include("[Content_Types].xml");
expect(fileNames).to.include("_rels/.rels"); expect(fileNames).to.include("_rels/.rels");
@ -76,7 +77,7 @@ describe("Compiler", () => {
const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name); const fileNames = Object.keys(zipFile.files).map((f) => zipFile.files[f].name);
expect(fileNames).is.an.instanceof(Array); expect(fileNames).is.an.instanceof(Array);
expect(fileNames).has.length(24); expect(fileNames).has.length(25);
expect(fileNames).to.include("word/header1.xml"); expect(fileNames).to.include("word/header1.xml");
expect(fileNames).to.include("word/_rels/header1.xml.rels"); expect(fileNames).to.include("word/_rels/header1.xml.rels");

View File

@ -406,6 +406,10 @@ export class Compiler {
}, },
Comments: { Comments: {
data: (() => { data: (() => {
if (!file.Comments) {
return;
}
const data = xml( const data = xml(
this.formatter.format(file.Comments, { this.formatter.format(file.Comments, {
viewWrapper: file.Document, viewWrapper: file.Document,

View File

@ -8,7 +8,7 @@ export enum PrettityType {
NONE = "", NONE = "",
WITH_2_BLANKS = " ", WITH_2_BLANKS = " ",
WITH_4_BLANKS = " ", WITH_4_BLANKS = " ",
WITH_TAB = "\t" WITH_TAB = "\t",
} }
export class Packer { export class Packer {

View File

@ -102,7 +102,7 @@ describe("ContentTypes", () => {
contentTypes.addFooter(102); contentTypes.addFooter(102);
const tree = new Formatter().format(contentTypes); const tree = new Formatter().format(contentTypes);
expect(tree["Types"][16]).to.deep.equal({ expect(tree["Types"][17]).to.deep.equal({
Override: { Override: {
_attr: { _attr: {
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml", ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml",
@ -111,7 +111,7 @@ describe("ContentTypes", () => {
}, },
}); });
expect(tree["Types"][17]).to.deep.equal({ expect(tree["Types"][18]).to.deep.equal({
Override: { Override: {
_attr: { _attr: {
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml", ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml",
@ -128,7 +128,7 @@ describe("ContentTypes", () => {
contentTypes.addHeader(202); contentTypes.addHeader(202);
const tree = new Formatter().format(contentTypes); const tree = new Formatter().format(contentTypes);
expect(tree["Types"][16]).to.deep.equal({ expect(tree["Types"][17]).to.deep.equal({
Override: { Override: {
_attr: { _attr: {
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml", ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml",
@ -137,7 +137,7 @@ describe("ContentTypes", () => {
}, },
}); });
expect(tree["Types"][17]).to.deep.equal({ expect(tree["Types"][18]).to.deep.equal({
Override: { Override: {
_attr: { _attr: {
ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml", ContentType: "application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml",

View File

@ -1,5 +1,6 @@
import { Comments } from './../paragraph/run/comment-run'; import { Comments } from "file/paragraph/run/comment-run";
import { StringContainer, XmlComponent } from "file/xml-components"; import { StringContainer, XmlComponent } from "file/xml-components";
import { ICustomPropertyOptions } from "../custom-properties"; import { ICustomPropertyOptions } from "../custom-properties";
import { IDocumentBackgroundOptions } from "../document"; import { IDocumentBackgroundOptions } from "../document";

View File

@ -31,11 +31,27 @@ describe("Document", () => {
"xmlns:w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main", "xmlns:w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main",
"xmlns:w14": "http://schemas.microsoft.com/office/word/2010/wordml", "xmlns:w14": "http://schemas.microsoft.com/office/word/2010/wordml",
"xmlns:w15": "http://schemas.microsoft.com/office/word/2012/wordml", "xmlns:w15": "http://schemas.microsoft.com/office/word/2012/wordml",
"xmlns:w16": "http://schemas.microsoft.com/office/word/2018/wordml",
"xmlns:w16cex": "http://schemas.microsoft.com/office/word/2018/wordml/cex",
"xmlns:w16cid": "http://schemas.microsoft.com/office/word/2016/wordml/cid",
"xmlns:w16sdtdh": "http://schemas.microsoft.com/office/word/2020/wordml/sdtdatahash",
"xmlns:w16se": "http://schemas.microsoft.com/office/word/2015/wordml/symex",
"xmlns:wpg": "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup", "xmlns:wpg": "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup",
"xmlns:wpi": "http://schemas.microsoft.com/office/word/2010/wordprocessingInk", "xmlns:wpi": "http://schemas.microsoft.com/office/word/2010/wordprocessingInk",
"xmlns:wne": "http://schemas.microsoft.com/office/word/2006/wordml", "xmlns:wne": "http://schemas.microsoft.com/office/word/2006/wordml",
"xmlns:wps": "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", "xmlns:wps": "http://schemas.microsoft.com/office/word/2010/wordprocessingShape",
"mc:Ignorable": "w14 w15 wp14", "mc:Ignorable": "w14 w15 wp14",
"xmlns:aink": "http://schemas.microsoft.com/office/drawing/2016/ink",
"xmlns:am3d": "http://schemas.microsoft.com/office/drawing/2017/model3d",
"xmlns:cx": "http://schemas.microsoft.com/office/drawing/2014/chartex",
"xmlns:cx1": "http://schemas.microsoft.com/office/drawing/2015/9/8/chartex",
"xmlns:cx2": "http://schemas.microsoft.com/office/drawing/2015/10/21/chartex",
"xmlns:cx3": "http://schemas.microsoft.com/office/drawing/2016/5/9/chartex",
"xmlns:cx4": "http://schemas.microsoft.com/office/drawing/2016/5/10/chartex",
"xmlns:cx5": "http://schemas.microsoft.com/office/drawing/2016/5/11/chartex",
"xmlns:cx6": "http://schemas.microsoft.com/office/drawing/2016/5/12/chartex",
"xmlns:cx7": "http://schemas.microsoft.com/office/drawing/2016/5/13/chartex",
"xmlns:cx8": "http://schemas.microsoft.com/office/drawing/2016/5/14/chartex",
}, },
}, },
{ {

View File

@ -1,4 +1,3 @@
import { Comments } from "./paragraph/run/comment-run";
import { AppProperties } from "./app-properties/app-properties"; import { AppProperties } from "./app-properties/app-properties";
import { ContentTypes } from "./content-types/content-types"; import { ContentTypes } from "./content-types/content-types";
import { CoreProperties, IPropertiesOptions } from "./core-properties"; import { CoreProperties, IPropertiesOptions } from "./core-properties";
@ -13,6 +12,7 @@ import { HeaderWrapper, IDocumentHeader } from "./header-wrapper";
import { Media } from "./media"; import { Media } from "./media";
import { Numbering } from "./numbering"; import { Numbering } from "./numbering";
import { Paragraph } from "./paragraph"; import { Paragraph } from "./paragraph";
import { Comments } from "./paragraph/run/comment-run";
import { Relationships } from "./relationships"; import { Relationships } from "./relationships";
import { Settings } from "./settings"; import { Settings } from "./settings";
import { Styles } from "./styles"; import { Styles } from "./styles";

View File

@ -1,6 +1,4 @@
import { CommentRangeStart, CommentRangeEnd, CommentReference, Comments, Comment } from "./run/comment-run";
// http://officeopenxml.com/WPparagraph.php // http://officeopenxml.com/WPparagraph.php
import { uniqueId } from "convenience-functions"; import { uniqueId } from "convenience-functions";
import { FootnoteReferenceRun } from "file/footnotes/footnote/run/reference-run"; import { FootnoteReferenceRun } from "file/footnotes/footnote/run/reference-run";
import { IContext, IXmlableObject, XmlComponent } from "file/xml-components"; import { IContext, IXmlableObject, XmlComponent } from "file/xml-components";
@ -12,6 +10,7 @@ import { Bookmark, ConcreteHyperlink, ExternalHyperlink, InternalHyperlink } fro
import { Math } from "./math"; import { Math } from "./math";
import { IParagraphPropertiesOptions, ParagraphProperties } from "./properties"; import { IParagraphPropertiesOptions, ParagraphProperties } from "./properties";
import { ImageRun, Run, SequentialIdentifier, SimpleField, SimpleMailMergeField, SymbolRun, TextRun } from "./run"; import { ImageRun, Run, SequentialIdentifier, SimpleField, SimpleMailMergeField, SymbolRun, TextRun } from "./run";
import { Comment, CommentRangeEnd, CommentRangeStart, CommentReference, Comments } from "./run/comment-run";
export type ParagraphChild = export type ParagraphChild =
| TextRun | TextRun

View File

@ -1,6 +1,7 @@
import { Paragraph } from "file/paragraph";
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
import { TextRun } from "./text-run"; import { TextRun } from "./text-run";
import { Paragraph } from "./../paragraph";
import { XmlAttributeComponent, XmlComponent } from "../../../file/xml-components";
interface ICommentOptions { interface ICommentOptions {
readonly id: string; readonly id: string;
@ -119,6 +120,7 @@ interface ICommentsAttrs {
export class CommentRangeStart extends XmlComponent { export class CommentRangeStart extends XmlComponent {
constructor(options: ICommentOptions) { constructor(options: ICommentOptions) {
super("w:commentRangeStart"); super("w:commentRangeStart");
this.root.push(new CommentAttributes(options)); this.root.push(new CommentAttributes(options));
} }
} }
@ -126,6 +128,7 @@ export class CommentRangeStart extends XmlComponent {
export class CommentRangeEnd extends XmlComponent { export class CommentRangeEnd extends XmlComponent {
constructor(options: ICommentOptions) { constructor(options: ICommentOptions) {
super("w:commentRangeEnd"); super("w:commentRangeEnd");
this.root.push(new CommentAttributes(options)); this.root.push(new CommentAttributes(options));
} }
} }
@ -133,6 +136,7 @@ export class CommentRangeEnd extends XmlComponent {
export class CommentReference extends XmlComponent { export class CommentReference extends XmlComponent {
constructor(options: ICommentOptions) { constructor(options: ICommentOptions) {
super("w:commentReference"); super("w:commentReference");
this.root.push(new CommentAttributes(options)); this.root.push(new CommentAttributes(options));
} }
} }
@ -140,14 +144,18 @@ export class CommentReference extends XmlComponent {
export class Comment extends XmlComponent { export class Comment extends XmlComponent {
constructor(options: ICommentOptions, text: string) { constructor(options: ICommentOptions, text: string) {
super("w:comment"); super("w:comment");
this.root.push(new CommentAttributes(options)); this.root.push(new CommentAttributes(options));
this.addChildElement(new Paragraph({ children: [new TextRun(text)] })); this.addChildElement(new Paragraph({ children: [new TextRun(text)] }));
} }
} }
export class Comments extends XmlComponent { export class Comments extends XmlComponent {
constructor(comments: Comment[]) { constructor(comments: Comment[]) {
super("w:comments"); super("w:comments");
this.root.push(new RootCommentsAttributes(COMMENT_ATTRIBUTES_MAP)); this.root.push(new RootCommentsAttributes(COMMENT_ATTRIBUTES_MAP));
comments.forEach((comment) => { comments.forEach((comment) => {
this.addChildElement(comment); this.addChildElement(comment);
}); });