From c7b68a40e46fdf4335072c89c2f58a6ac10f70c0 Mon Sep 17 00:00:00 2001 From: Dolan Date: Wed, 15 Jun 2022 01:44:57 +0100 Subject: [PATCH] Add tests for get media data --- src/export/packer/next-compiler.spec.ts | 50 +++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/src/export/packer/next-compiler.spec.ts b/src/export/packer/next-compiler.spec.ts index df81e057c4..e5336cbcf5 100644 --- a/src/export/packer/next-compiler.spec.ts +++ b/src/export/packer/next-compiler.spec.ts @@ -43,19 +43,27 @@ describe("Compiler", () => { sections: [ { headers: { - default: new Header(), + default: new Header({ + children: [new Paragraph("test")], + }), }, footers: { - default: new Footer(), + default: new Footer({ + children: [new Paragraph("test")], + }), }, children: [], }, { headers: { - default: new Header(), + default: new Header({ + children: [new Paragraph("test")], + }), }, footers: { - default: new Footer(), + default: new Footer({ + children: [new Paragraph("test")], + }), }, children: [], }, @@ -99,5 +107,39 @@ describe("Compiler", () => { compiler.compile(file); expect(spy.callCount).to.equal(12); }); + + it("should work with media datas", () => { + // This test is required because before, there was a case where Document was formatted twice, which was inefficient + // This also caused issues such as running prepForXml multiple times as format() was ran multiple times. + const paragraph = new Paragraph(""); + const file = new File({ + sections: [ + { + properties: {}, + children: [paragraph], + }, + ], + }); + + // tslint:disable-next-line: no-string-literal + sinon.stub(compiler["imageReplacer"], "getMediaData").returns([ + { + stream: Buffer.from(""), + fileName: "test", + transformation: { + pixels: { + x: 100, + y: 100, + }, + emus: { + x: 100, + y: 100, + }, + }, + }, + ]); + + compiler.compile(file); + }); }); });