From 26eb141ff6f0167a2506ffb5bf6a65cf2773f409 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 16 Aug 2015 15:55:58 +0100 Subject: Add style map to relationships for document --- tests/docx/style-map.tests.js | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/docx/style-map.tests.js b/tests/docx/style-map.tests.js index d120289..99f1d99 100644 --- a/tests/docx/style-map.tests.js +++ b/tests/docx/style-map.tests.js @@ -8,28 +8,49 @@ var test = require("../testing").test; describe("zipfile", function() { test('embedded style map can be read after being written', function() { - var zip = emptyZipFile(); + var zip = normalDocx(); - styleMap.writeStyleMap(zip, "p => h1"); - - return styleMap.readStyleMap(zip).then(function(contents) { - assert.equal(contents, "p => h1"); + return styleMap.writeStyleMap(zip, "p => h1").then(function() { + return styleMap.readStyleMap(zip).then(function(contents) { + assert.equal(contents, "p => h1"); + }); }); }); test('embedded style map is written to separate file', function() { - var zip = emptyZipFile(); + var zip = normalDocx(); + + return styleMap.writeStyleMap(zip, "p => h1").then(function() { + return zip.read("mammoth/style-map", "utf8").then(function(contents) { + assert.equal(contents, "p => h1"); + }); + }); + }); + + test('embedded style map is referenced in relationships', function() { + var zip = normalDocx(); - styleMap.writeStyleMap(zip, "p => h1"); + var expectedRelationshipsXml = '' + + '' + + '' + + '' + + ''; - return zip.read("mammoth/style-map", "utf8").then(function(contents) { - assert.equal(contents, "p => h1"); + return styleMap.writeStyleMap(zip, "p => h1").then(function() { + return zip.read("word/_rels/document.xml.rels", "utf8").then(function(contents) { + assert.equal(contents, expectedRelationshipsXml); + }); }); }); }); -function emptyZipFile() { +function normalDocx() { var zip = new JSZip(); + var originalRelationshipsXml = '' + + '' + + '' + + ''; + zip.file("word/_rels/document.xml.rels", originalRelationshipsXml); var buffer = zip.generate({type: "arraybuffer"}); return zipfile.openArrayBuffer(buffer); } -- cgit v1.2.3