2013-08-20 01:52:50 +04:00
|
|
|
/**
|
|
|
|
* Test the ghostdown extension
|
|
|
|
*
|
|
|
|
* Only ever runs on the client (i.e in the editor)
|
|
|
|
* Server processes showdown without it so there can never be an image upload form in a post.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*globals describe, it */
|
2014-06-05 01:26:03 +04:00
|
|
|
/*jshint expr:true*/
|
|
|
|
var should = require('should'),
|
2013-09-06 20:07:25 +04:00
|
|
|
|
|
|
|
// Stuff we are testing
|
2014-03-20 17:52:16 +04:00
|
|
|
ghostimagepreview = require('../../shared/lib/showdown/extensions/ghostimagepreview');
|
2013-08-20 01:52:50 +04:00
|
|
|
|
2014-06-05 01:26:03 +04:00
|
|
|
// To stop jshint complaining
|
|
|
|
should.equal(true, true);
|
2013-08-20 01:52:50 +04:00
|
|
|
|
2014-06-05 01:26:03 +04:00
|
|
|
describe('Ghost Image Preview showdown extension', function () {
|
|
|
|
it('should export an array of methods for processing', function () {
|
2014-03-20 17:52:16 +04:00
|
|
|
ghostimagepreview.should.be.a.function;
|
|
|
|
ghostimagepreview().should.be.an.instanceof(Array);
|
2013-08-20 01:52:50 +04:00
|
|
|
|
2014-03-20 17:52:16 +04:00
|
|
|
ghostimagepreview().forEach(function (processor) {
|
2013-10-31 04:28:53 +04:00
|
|
|
processor.should.be.an.Object;
|
2014-06-05 01:26:03 +04:00
|
|
|
processor.should.have.property('type');
|
|
|
|
processor.should.have.property('filter');
|
2013-10-31 04:28:53 +04:00
|
|
|
processor.type.should.be.a.String;
|
|
|
|
processor.filter.should.be.a.function;
|
2013-08-20 01:52:50 +04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-06-05 01:26:03 +04:00
|
|
|
it('should accurately detect images in markdown', function () {
|
2013-08-20 01:52:50 +04:00
|
|
|
[
|
2014-06-05 01:26:03 +04:00
|
|
|
'![]',
|
|
|
|
'![]()',
|
|
|
|
'![image and another,/ image]',
|
|
|
|
'![image and another,/ image]()',
|
|
|
|
'![image and another,/ image](http://dsurl.stuff)',
|
|
|
|
'![](http://dsurl.stuff)'
|
2013-09-02 01:03:01 +04:00
|
|
|
/* No ref-style for now
|
2014-06-05 01:26:03 +04:00
|
|
|
'![][]',
|
|
|
|
'![image and another,/ image][stuff]',
|
|
|
|
'![][stuff]',
|
|
|
|
'![image and another,/ image][]'
|
2013-11-11 14:37:09 +04:00
|
|
|
*/
|
2013-08-20 01:52:50 +04:00
|
|
|
]
|
|
|
|
.forEach(function (imageMarkup) {
|
|
|
|
var processedMarkup =
|
2014-03-20 17:52:16 +04:00
|
|
|
ghostimagepreview().reduce(function (prev, processor) {
|
2013-08-20 01:52:50 +04:00
|
|
|
return processor.filter(prev);
|
|
|
|
}, imageMarkup);
|
|
|
|
|
|
|
|
// The image is the entire markup, so the image box should be too
|
|
|
|
processedMarkup.should.match(/^<section.*?section>\n*$/);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-06-05 01:26:03 +04:00
|
|
|
it('should correctly include an image', function () {
|
2013-08-20 01:52:50 +04:00
|
|
|
[
|
2014-06-05 01:26:03 +04:00
|
|
|
'![image and another,/ image](http://dsurl.stuff)',
|
|
|
|
'![](http://dsurl.stuff)'
|
2013-09-02 01:03:01 +04:00
|
|
|
/* No ref-style for now
|
2014-06-05 01:26:03 +04:00
|
|
|
'![image and another,/ image][test]\n\n[test]: http://dsurl.stuff',
|
|
|
|
'![][test]\n\n[test]: http://dsurl.stuff'
|
2013-11-11 14:37:09 +04:00
|
|
|
*/
|
2013-08-20 01:52:50 +04:00
|
|
|
]
|
|
|
|
.forEach(function (imageMarkup) {
|
|
|
|
var processedMarkup =
|
2014-03-20 17:52:16 +04:00
|
|
|
ghostimagepreview().reduce(function (prev, processor) {
|
2013-08-20 01:52:50 +04:00
|
|
|
return processor.filter(prev);
|
|
|
|
}, imageMarkup);
|
|
|
|
|
|
|
|
processedMarkup.should.match(/<img class="js-upload-target"/);
|
|
|
|
});
|
|
|
|
});
|
2014-03-04 01:41:34 +04:00
|
|
|
});
|