move run-fonts to docx/run and add a test

This commit is contained in:
felipe
2017-03-08 19:48:32 +01:00
parent a454ff9643
commit 237be76d33
3 changed files with 26 additions and 4 deletions

View File

@ -1,9 +1,9 @@
import {XmlAttributeComponent, XmlComponent} from "../docx/xml-components";
import {XmlAttributeComponent, XmlComponent} from "../xml-components";
interface IRunFontAttributesProperties {
ascii: string;
hAnsi: string;
hint: string;
hint?: string;
}
class RunFontAttributes extends XmlAttributeComponent {
@ -19,7 +19,7 @@ class RunFontAttributes extends XmlAttributeComponent {
export class RunFonts extends XmlComponent {
constructor(ascii: string, hint: string) {
constructor(ascii: string, hint?: string) {
super("w:rFonts");
this.root.push(new RunFontAttributes({
ascii: ascii,

View File

@ -1,11 +1,11 @@
import * as _ from "lodash";
import { DocumentAttributes } from "../docx/document/document-attributes";
import { RunFonts } from "../docx/run/run-fonts";
import { MultiPropertyXmlComponent } from "../docx/xml-components";
import { AbstractNumbering } from "./abstract-numbering";
import { Indent } from "./indent";
import { Level } from "./level";
import { Num } from "./num";
import { RunFonts } from "./run-fonts";
export class Numbering extends MultiPropertyXmlComponent {
private nextId: number;

View File

@ -0,0 +1,22 @@
import { expect } from "chai";
import { RunFonts } from "../../../docx/run/run-fonts";
import { Formatter } from "../../../export/formatter";
describe("RunFonts", () => {
describe("#constructor()", () => {
it("uses the font name for both ascii and hAnsi", () => {
const tree = new Formatter().format(new RunFonts("Times"));
expect(tree).to.deep.equal({
"w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times"}}],
});
});
it("uses hint if given", () => {
const tree = new Formatter().format(new RunFonts("Times", "default"));
expect(tree).to.deep.equal({
"w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times", "w:hint": "default"}}],
});
});
});
});