aboutsummaryrefslogtreecommitdiff
path: root/test/docx/content-types-reader.tests.js
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-07-03 19:19:21 +0100
committerMichael Williamson <mike@zwobble.org>2016-07-03 19:20:00 +0100
commit0b56dfce42c3944cce47e284608e6806f4c839c3 (patch)
tree5f96f9c2908f1c5b00a7192e71d4c192abd7cf47 /test/docx/content-types-reader.tests.js
parent627c4a755395e313234bdb1914d168392006c483 (diff)
Move tests to test for easier Mocha usage
Diffstat (limited to 'test/docx/content-types-reader.tests.js')
-rw-r--r--test/docx/content-types-reader.tests.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/docx/content-types-reader.tests.js b/test/docx/content-types-reader.tests.js
new file mode 100644
index 0000000..a223d09
--- /dev/null
+++ b/test/docx/content-types-reader.tests.js
@@ -0,0 +1,47 @@
+var assert = require("assert");
+
+var readContentTypesFromXml = require("../../lib/docx/content-types-reader").readContentTypesFromXml;
+var XmlElement = require("../../lib/xml").Element;
+var test = require("../testing").test;
+
+
+describe('readContentTypesFromXml', function() {
+ test('reads default-per-extension from XML', function() {
+ var contentTypes = readContentTypesFromXml({
+ root: new XmlElement("content-types:Types", {}, [
+ new XmlElement("content-types:Default", {Extension: "png", ContentType: "image/png"})
+ ])
+ });
+ assert.equal(contentTypes.findContentType("word/media/hat.png"), "image/png");
+ });
+
+ test('reads overrides in preference to defaults', function() {
+ var contentTypes = readContentTypesFromXml({
+ root: new XmlElement("content-types:Types", {}, [
+ new XmlElement("content-types:Default", {Extension: "png", ContentType: "image/png"}),
+ new XmlElement("content-types:Override", {PartName: "/word/media/hat.png", ContentType: "image/hat"})
+ ])
+ });
+ assert.equal(contentTypes.findContentType("word/media/hat.png"), "image/hat");
+ });
+
+ test('fallback content types have common image types', function() {
+ var contentTypes = readContentTypesFromXml({
+ root: new XmlElement("content-types:Types", {}, [])
+ });
+ assert.equal(contentTypes.findContentType("word/media/hat.png"), "image/png");
+ assert.equal(contentTypes.findContentType("word/media/hat.gif"), "image/gif");
+ assert.equal(contentTypes.findContentType("word/media/hat.jpg"), "image/jpeg");
+ assert.equal(contentTypes.findContentType("word/media/hat.jpeg"), "image/jpeg");
+ assert.equal(contentTypes.findContentType("word/media/hat.bmp"), "image/bmp");
+ assert.equal(contentTypes.findContentType("word/media/hat.tif"), "image/tiff");
+ assert.equal(contentTypes.findContentType("word/media/hat.tiff"), "image/tiff");
+ });
+
+ test('fallback content types are case insensitive on extension', function() {
+ var contentTypes = readContentTypesFromXml({
+ root: new XmlElement("content-types:Types", {}, [])
+ });
+ assert.equal(contentTypes.findContentType("word/media/hat.PnG"), "image/png");
+ });
+});