relationships-reader.tests.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. var assert = require("assert");
  2. var readRelationships = require("../../lib/docx/relationships-reader").readRelationships;
  3. var xml = require("../../lib/xml");
  4. var test = require("../test")(module);
  5. test("relationships can be found by ID", function() {
  6. var relationships = readRelationships(relationshipsElement([
  7. relationshipElement({
  8. "Id": "rId1",
  9. "Target": "http://example.com/",
  10. "Type": "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
  11. }),
  12. relationshipElement({
  13. "Id": "rId2",
  14. "Target": "http://example.net/",
  15. "Type": "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink"
  16. })
  17. ]));
  18. assert.equal(relationships.findTargetByRelationshipId("rId1"), "http://example.com/");
  19. });
  20. test("relationships can be found by type", function() {
  21. var relationships = readRelationships(relationshipsElement([
  22. relationshipElement({
  23. "Id": "rId2",
  24. "Target": "docProps/core.xml",
  25. "Type": "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties"
  26. }),
  27. relationshipElement({
  28. "Id": "rId1",
  29. "Target": "word/document.xml",
  30. "Type": "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
  31. }),
  32. relationshipElement({
  33. "Id": "rId3",
  34. "Target": "word/document2.xml",
  35. "Type": "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
  36. })
  37. ]));
  38. assert.deepEqual(
  39. relationships.findTargetsByType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"),
  40. ["word/document.xml", "word/document2.xml"]
  41. );
  42. });
  43. test("when there are no relationships of requested type then empty array is returned", function() {
  44. var relationships = readRelationships(relationshipsElement([]));
  45. assert.deepEqual(
  46. relationships.findTargetsByType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"),
  47. []
  48. );
  49. });
  50. function relationshipsElement(children) {
  51. return xml.element("relationships:Relationships", {}, children);
  52. }
  53. function relationshipElement(attributes) {
  54. return xml.element("relationships:Relationship", attributes, []);
  55. }