mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
72 lines
2.5 KiB
JavaScript
72 lines
2.5 KiB
JavaScript
// Generated by CoffeeScript 1.6.3
|
|
describe('Annotator.Plugin.Markdown', function() {
|
|
var input, output, plugin;
|
|
input = 'Is **this** [Markdown](http://daringfireball.com)?';
|
|
output = '<p>Is <strong>this</strong> <a href="http://daringfireball.com">Markdown</a>?</p>';
|
|
plugin = null;
|
|
beforeEach(function() {
|
|
return plugin = new Annotator.Plugin.Markdown($('<div />')[0]);
|
|
});
|
|
describe("events", function() {
|
|
return it("should call Markdown#updateTextField() when annotationViewerTextField event is fired", function() {
|
|
var annotation, field;
|
|
field = $('<div />')[0];
|
|
annotation = {
|
|
text: 'test'
|
|
};
|
|
sinon.spy(plugin, 'updateTextField');
|
|
plugin.publish('annotationViewerTextField', [field, annotation]);
|
|
return assert.isTrue(plugin.updateTextField.calledWith(field, annotation));
|
|
});
|
|
});
|
|
describe("constructor", function() {
|
|
it("should create a new instance of Showdown", function() {
|
|
return assert.ok(plugin.converter);
|
|
});
|
|
return it("should log an error if Showdown is not loaded", function() {
|
|
var converter;
|
|
sinon.stub(console, 'error');
|
|
converter = Showdown.converter;
|
|
Showdown.converter = null;
|
|
plugin = new Annotator.Plugin.Markdown($('<div />')[0]);
|
|
assert(console.error.calledOnce);
|
|
Showdown.converter = converter;
|
|
return console.error.restore();
|
|
});
|
|
});
|
|
describe("updateTextField", function() {
|
|
var annotation, field;
|
|
field = null;
|
|
annotation = null;
|
|
beforeEach(function() {
|
|
field = $('<div />')[0];
|
|
annotation = {
|
|
text: input
|
|
};
|
|
sinon.stub(plugin, 'convert').returns(output);
|
|
sinon.stub(Annotator.Util, 'escape').returns(input);
|
|
return plugin.updateTextField(field, annotation);
|
|
});
|
|
afterEach(function() {
|
|
return Annotator.Util.escape.restore();
|
|
});
|
|
it('should process the annotation text as Markdown', function() {
|
|
return assert.isTrue(plugin.convert.calledWith(input));
|
|
});
|
|
it('should update the content in the field', function() {
|
|
return assert.equal($(field).html(), output);
|
|
});
|
|
return it("should escape any existing HTML to prevent XSS", function() {
|
|
return assert.isTrue(Annotator.Util.escape.calledWith(input));
|
|
});
|
|
});
|
|
return describe("convert", function() {
|
|
return it("should convert the provided text into markdown", function() {
|
|
return assert.equal(plugin.convert(input), output);
|
|
});
|
|
});
|
|
});
|
|
|
|
/*
|
|
//@ sourceMappingURL=markdown_spec.map
|
|
*/
|