UNPKG

docxtemplater

Version:

.docx generator working with templates and data (like Mustache)

62 lines (55 loc) 2.65 kB
"use strict"; var testUtils = require("./utils"); var path = require("path"); var expect = testUtils.expect; testUtils.setExamplesDirectory(path.resolve(__dirname, "..", "..", "examples")); testUtils.setStartFunction(startTest); var fileNames = ["angular-example.docx", "cyrillic.docx", "image-example.docx", "table-complex2-example.docx", "table-complex-example.docx", "tag-dash-loop.docx", "tag-dash-loop-list.docx", "tag-dash-loop-table.docx", "tag-example.docx", "tag-example-expected.docx", "tag-intelligent-loop-table.docx", "tag-intelligent-loop-table-expected.docx", "tag-loop-example.docx", "tag-produit-loop.docx", "one-raw-xml-tag.docx", "table-example.pptx", "table-example-expected.pptx", "simple-example.pptx", "loop-example.pptx", "expected-loop-example.pptx", "raw-xml-example.pptx", "image.png"]; function startTest() { require("./base"); require("./xml-templater"); require("./xml-matcher"); require("./errors"); require("./speed"); require("./lexer-parser-render"); describe("pptx generation", function () { it("should work with simple pptx", function () { var doc = testUtils.createDoc("simple-example.pptx"); var p = doc.setData({ name: "Edgar" }).render(); expect(p.getFullText()).to.be.equal("Hello Edgar"); }); it("should work with table pptx", function () { var doc = testUtils.createDoc("table-example.pptx"); doc.setData({ users: [{ msg: "hello", name: "mary" }, { msg: "hello", name: "john" }] }).render(); testUtils.shouldBeSame({ doc: doc, expectedName: "table-example-expected.pptx" }); }); it("should work with loop pptx", function () { var doc = testUtils.createDoc("loop-example.pptx"); var p = doc.setData({ users: [{ name: "Doe" }, { name: "John" }] }).render(); testUtils.shouldBeSame({ doc: doc, expectedName: "expected-loop-example.pptx" }); expect(p.getFullText()).to.be.equal(" Doe John "); }); it("should work with simple raw pptx", function () { var doc = testUtils.createDoc("raw-xml-example.pptx"); var p = doc.setData({ raw: "<p:sp><a:t>Hello World</a:t></p:sp>" }).render(); expect(p.getFullText()).to.be.equal("Hello World"); }); }); if (typeof window !== "undefined" && window) { return window.mocha.run(); } } fileNames.forEach(function (fileName) { var callback = void 0; if (fileName.indexOf(".docx") !== -1 || fileName.indexOf(".pptx") !== -1) { callback = testUtils.loadDocument; } if (fileName.indexOf(".png") !== -1) { callback = testUtils.loadImage; } if (!callback) { throw new Error("Filename " + fileName + " neither docx nor pptx nor png"); } testUtils.loadFile(fileName, callback); }); testUtils.start();