diff options
| author | Michael Williamson <mike@zwobble.org> | 2018-01-16 22:21:21 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2018-01-16 22:21:21 +0000 |
| commit | cc1b5b19480befc5611a469424a5ae16f9ebce21 (patch) | |
| tree | 4774f2cbbae87b2b723902d7154b171c2060db78 /test/docx/relationships-reader.tests.js | |
| parent | 062eb4ff3fea9c49cfce841327d01ddd0099264e (diff) | |
Read types of relationships
Diffstat (limited to 'test/docx/relationships-reader.tests.js')
| -rw-r--r-- | test/docx/relationships-reader.tests.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/test/docx/relationships-reader.tests.js b/test/docx/relationships-reader.tests.js new file mode 100644 index 0000000..60db3b4 --- /dev/null +++ b/test/docx/relationships-reader.tests.js @@ -0,0 +1,65 @@ +var assert = require("assert"); + +var readRelationships = require("../../lib/docx/relationships-reader").readRelationships; +var xml = require("../../lib/xml"); +var test = require("../test")(module); + + +test("relationships can be found by ID", function() { + var relationships = readRelationships(relationshipsElement([ + relationshipElement({ + "Id": "rId1", + "Target": "http://example.com/", + "Type": "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" + }), + relationshipElement({ + "Id": "rId2", + "Target": "http://example.net/", + "Type": "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink" + }) + ])); + assert.equal(relationships.findTargetByRelationshipId("rId1"), "http://example.com/"); +}); + + +test("relationships can be found by type", function() { + var relationships = readRelationships(relationshipsElement([ + relationshipElement({ + "Id": "rId2", + "Target": "docProps/core.xml", + "Type": "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" + }), + relationshipElement({ + "Id": "rId1", + "Target": "word/document.xml", + "Type": "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" + }), + relationshipElement({ + "Id": "rId3", + "Target": "word/document2.xml", + "Type": "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" + }) + ])); + assert.deepEqual( + relationships.findTargetsByType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"), + ["word/document.xml", "word/document2.xml"] + ); +}); + + +test("when there are no relationships of requested type then empty array is returned", function() { + var relationships = readRelationships(relationshipsElement([])); + assert.deepEqual( + relationships.findTargetsByType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"), + [] + ); +}); + + +function relationshipsElement(children) { + return xml.element("{http://schemas.openxmlformats.org/package/2006/relationships}Relationships", {}, children) +} + +function relationshipElement(attributes) { + return xml.element("{http://schemas.openxmlformats.org/package/2006/relationships}Relationship", attributes, []) +} |
