add support for floating drawings

- added need elements and test for them
This commit is contained in:
Igor Bulovski
2018-06-08 16:03:04 +02:00
parent ac40a40ec0
commit 97b254ee7b
27 changed files with 746 additions and 21 deletions

View File

@ -2,14 +2,12 @@ import { assert } from "chai";
import * as fs from "fs";
import { Utility } from "../../tests/utility";
import { Drawing } from "./";
import { Drawing, DrawingOptions, PlacementPosition } from "./";
describe("Drawing", () => {
let currentBreak: Drawing;
beforeEach(() => {
const path = "./demo/images/image1.jpeg";
currentBreak = new Drawing({
function createDrawing(drawingOptions?: DrawingOptions) {
const path = "./demo/images/image1.jpeg";
return new Drawing(
{
fileName: "test.jpg",
referenceId: 1,
stream: fs.createReadStream(path),
@ -24,14 +22,33 @@ describe("Drawing", () => {
y: 100 * 9525,
},
},
});
});
},
drawingOptions,
);
}
describe("Drawing", () => {
let currentBreak: Drawing;
describe("#constructor()", () => {
it("should create a Drawing with correct root key", () => {
currentBreak = createDrawing();
const newJson = Utility.jsonify(currentBreak);
assert.equal(newJson.rootKey, "w:drawing");
// console.log(JSON.stringify(newJson, null, 2));
});
it("should create a drawing with inline element when there are no options passed", () => {
currentBreak = createDrawing();
const newJson = Utility.jsonify(currentBreak);
assert.equal(newJson.root[0].rootKey, "wp:inline");
});
it("should create a drawing with anchor element when there options are passed", () => {
currentBreak = createDrawing({
position: PlacementPosition.FLOATING,
});
const newJson = Utility.jsonify(currentBreak);
assert.equal(newJson.root[0].rootKey, "wp:anchor");
});
});
});