var assert = require("assert");

var hamjest = require("hamjest");
var assertThat = hamjest.assertThat;
var contains = hamjest.contains;
var hasProperties = hamjest.hasProperties;

var mammoth = require("../");
var documents = require("../lib/documents");
var promises = require("../lib/promises");

var test = require("./test")(module);


test('mammoth.images.inline() should be an alias of mammoth.images.imgElement()', function() {
    assert.ok(mammoth.images.inline === mammoth.images.imgElement);
});


test('mammoth.images.dataUri() encodes images in base64', function() {
    var imageBuffer = new Buffer("abc");
    var image = new documents.Image({
        readImage: function(encoding) {
            return promises.when(imageBuffer.toString(encoding));
        },
        contentType: "image/jpeg"
    });
    
    return mammoth.images.dataUri(image).then(function(result) {
        assertThat(result, contains(
            hasProperties({tag: hasProperties({attributes: {"src": "data:image/jpeg;base64,YWJj"}})})
        ));
    });
});

@@ -130,16 +130,47 @@
 ntains;%0A
+var equalTo = hamjest.equalTo;%0A
 var hasP
@@ -204,16 +204,16 @@
 erties;%0A
-
 %0Avar mam
@@ -846,13 +846,9 @@
 %7D);%0A
-    
 %0A
+
     
@@ -1055,24 +1055,24 @@
         ));%0A
-
     %7D);%0A%7D);%0A
@@ -1067,12 +1067,1626 @@
     %7D);%0A%7D);%0A
+%0A%0Atest('mammoth.images.imgElement()', %7B%0A    'when element does not have alt text then alt attribute is not set': function() %7B%0A        var imageBuffer = new Buffer(%22abc%22);%0A        var image = new documents.Image(%7B%0A            readImage: function(encoding) %7B%0A                return promises.when(imageBuffer.toString(encoding));%0A            %7D,%0A            contentType: %22image/jpeg%22%0A        %7D);%0A%0A        var result = mammoth.images.imgElement(function(image) %7B%0A            return %7Bsrc: %22%3Csrc%3E%22%7D;%0A        %7D)(image);%0A%0A        return result.then(function(result) %7B%0A            assertThat(result, contains(%0A                hasProperties(%7B%0A                    tag: hasProperties(%7B%0A                        attributes: equalTo(%7Bsrc: %22%3Csrc%3E%22%7D)%0A                    %7D)%0A                %7D)%0A            ));%0A        %7D);%0A    %7D,%0A%0A    'when element has alt text then alt attribute is set': function() %7B%0A        var imageBuffer = new Buffer(%22abc%22);%0A        var image = new documents.Image(%7B%0A            readImage: function(encoding) %7B%0A                return promises.when(imageBuffer.toString(encoding));%0A            %7D,%0A            contentType: %22image/jpeg%22,%0A            altText: %22%3Calt%3E%22%0A        %7D);%0A%0A        var result = mammoth.images.imgElement(function(image) %7B%0A            return %7Bsrc: %22%3Csrc%3E%22%7D;%0A        %7D)(image);%0A%0A        return result.then(function(result) %7B%0A            assertThat(result, contains(%0A                hasProperties(%7B%0A                    tag: hasProperties(%7B%0A                        attributes: equalTo(%7Balt: %22%3Calt%3E%22, src: %22%3Csrc%3E%22%7D)%0A                    %7D)%0A                %7D)%0A            ));%0A        %7D);%0A    %7D%0A%7D);%0A

Test mammoth.images.imgElement directly