summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2018-01-26 23:30:13 +0000
committerMichael Williamson <mike@zwobble.org>2018-01-26 23:30:13 +0000
commit8b9ca6ca68fec89926cfb02a96506bbee54a5b2c (patch)
tree34f701ec9078d533d86ad63fc6aa11dbd91ad278 /test
parent9196e8bc6f2ff2c59a9b4fde4813e7bc26b8c23d (diff)
Find comments part using document relationships
Diffstat (limited to 'test')
-rw-r--r--test/docx/docx-reader.tests.js38
-rw-r--r--test/zipfile.tests.js9
2 files changed, 47 insertions, 0 deletions
diff --git a/test/docx/docx-reader.tests.js b/test/docx/docx-reader.tests.js
index 0556405..0d51f45 100644
--- a/test/docx/docx-reader.tests.js
+++ b/test/docx/docx-reader.tests.js
@@ -113,5 +113,43 @@ test("part paths", {
return docxReader._findPartPaths(docxFile).then(function(partPaths) {
assert.equal(partPaths.mainDocument, "word/document.xml");
});
+ },
+
+ "comments part is found using main document relationships": function() {
+ var docxFile = createFakeDocxFile({
+ "_rels/.rels": createPackageRelationships("word/document.xml"),
+ "word/document.xml": " ",
+ "word/_rels/document.xml.rels": xml.writeString(xml.element("r:Relationships", {}, [
+ xml.element("r:Relationship", {
+ "Type": "http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments",
+ "Target": "comments2.xml"
+ })
+ ]), relationshipNamespaces),
+ "word/comments2.xml": " "
+ });
+ return docxReader._findPartPaths(docxFile).then(function(partPaths) {
+ assert.equal(partPaths.comments, "word/comments2.xml");
+ });
+ },
+
+ "word/comments.xml is used as fallback location for comments part": function() {
+ var docxFile = createFakeDocxFile({
+ "_rels/.rels": createPackageRelationships("word/document.xml"),
+ "word/document.xml": " ",
+ "word/comments.xml": " "
+ });
+ return docxReader._findPartPaths(docxFile).then(function(partPaths) {
+ assert.equal(partPaths.comments, "word/comments.xml");
+ });
}
});
+
+
+function createPackageRelationships(mainDocumentPath) {
+ return xml.writeString(xml.element("r:Relationships", {}, [
+ xml.element("r:Relationship", {
+ "Type": "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument",
+ "Target": mainDocumentPath
+ })
+ ]), relationshipNamespaces);
+}
diff --git a/test/zipfile.tests.js b/test/zipfile.tests.js
index 3087dc8..5383c49 100644
--- a/test/zipfile.tests.js
+++ b/test/zipfile.tests.js
@@ -39,6 +39,7 @@ test("when path has no forward slashes then splitPath returns empty dirname", fu
test("joinPath joins arguments with forward slashes", function() {
assert.equal(zipfile.joinPath("a", "b"), "a/b");
assert.equal(zipfile.joinPath("a/b", "c"), "a/b/c");
+ assert.equal(zipfile.joinPath("a", "b/c"), "a/b/c");
assert.equal(zipfile.joinPath("/a/b", "c"), "/a/b/c");
});
@@ -48,3 +49,11 @@ test("empty parts are ignored when joining paths", function() {
assert.equal(zipfile.joinPath("", "b"), "b");
assert.equal(zipfile.joinPath("a", "", "b"), "a/b");
});
+
+
+test("when joining paths then absolute paths ignore earlier paths", function() {
+ assert.equal(zipfile.joinPath("a", "/b"), "/b");
+ assert.equal(zipfile.joinPath("a", "/b", "c"), "/b/c");
+ assert.equal(zipfile.joinPath("/a", "/b"), "/b");
+ assert.equal(zipfile.joinPath("/a"), "/a");
+});