aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-08-16 15:55:58 +0100
committerMichael Williamson <mike@zwobble.org>2015-08-16 15:55:58 +0100
commit26eb141ff6f0167a2506ffb5bf6a65cf2773f409 (patch)
tree2c369c08f36a78d080c7dca79f3191d8da10bf51 /tests
parent0363f064b05698eed9826570aad6985ef47a6322 (diff)
Add style map to relationships for document
Diffstat (limited to 'tests')
-rw-r--r--tests/docx/style-map.tests.js41
1 files changed, 31 insertions, 10 deletions
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 = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
+ '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
+ '<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings" Target="settings.xml"/>' +
+ '<Relationship Id="rMammothStyleMap" Type="http://schemas.zwobble.org/mammoth/style-map" Target="/mammoth/style-map"/>' +
+ '</Relationships>';
- 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 = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' +
+ '<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">' +
+ '<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings" Target="settings.xml"/>' +
+ '</Relationships>';
+ zip.file("word/_rels/document.xml.rels", originalRelationshipsXml);
var buffer = zip.generate({type: "arraybuffer"});
return zipfile.openArrayBuffer(buffer);
}