var assert = require("assert");
var path = require("path");
var fs = require("fs");
var promises = require("../lib/promises");
var mammoth = require("../")
var htmlPaths = require("../lib/html-paths");
var documentMatchers = require("../lib/document-matchers");
var testing = require("./testing");
var test = testing.test;
var testData = testing.testData;
var createFakeDocxFile = testing.createFakeDocxFile;
describe('mammoth', function() {
test('should convert docx containing one paragraph to single p element', function() {
var docxPath = path.join(__dirname, "test-data/single-paragraph.docx");
return mammoth.convertToHtml({path: docxPath}).then(function(result) {
assert.equal(result.value, "
Walking on imported air
");
assert.deepEqual(result.messages, []);
});
});
test('style map can be expressed as string', function() {
var docxFile = createFakeDocxFile({
"word/document.xml": testData("simple/word/document.xml")
});
var options = {
styleMap: "p => h1"
};
return mammoth.convertToHtml({file: docxFile}, options).then(function(result) {
assert.equal("Hello.
", result.value);
});
});
test('style map can be expressed as array of styles', function() {
var docxFile = createFakeDocxFile({
"word/document.xml": testData("simple/word/document.xml")
});
var options = {
styleMap: [mammoth.styleMapping("p => h1")]
};
return mammoth.convertToHtml({file: docxFile}, options).then(function(result) {
assert.equal("Hello.
", result.value);
});
});
test('options are passed to document converter when calling mammoth.convertToHtml', function() {
var docxFile = createFakeDocxFile({
"word/document.xml": testData("simple/word/document.xml")
});
var options = {
styleMap: "p => h1"
};
return mammoth.convertToHtml({file: docxFile}, options).then(function(result) {
assert.equal("Hello.
", result.value);
});
});
test('options.transformDocument is used to transform document if set', function() {
var docxFile = createFakeDocxFile({
"word/document.xml": testData("simple/word/document.xml")
});
var options = {
transformDocument: function(document) {
document.children[0].styleName = "Heading1";
return document;
}
};
return mammoth.convertToHtml({file: docxFile}, options).then(function(result) {
assert.equal("Hello.
", result.value);
});
});
test('inline images are included in output', function() {
var docxPath = path.join(__dirname, "test-data/tiny-picture.docx");
return mammoth.convertToHtml({path: docxPath}).then(function(result) {
assert.equal(result.value, '
');
});
});
test('simple list is converted to list elements', function() {
var docxPath = path.join(__dirname, "test-data/simple-list.docx");
return mammoth.convertToHtml({path: docxPath}).then(function(result) {
assert.equal(result.value, '');
});
});
})