mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
Added several usage examples, fixed bugs, turned off restore by default
This commit is contained in:
parent
0e08b734ec
commit
416f7ab6a0
112 changed files with 23903 additions and 3348 deletions
72
libs/annotator/lib/spec/plugin/markdown_spec.js
Normal file
72
libs/annotator/lib/spec/plugin/markdown_spec.js
Normal file
|
@ -0,0 +1,72 @@
|
|||
// 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
|
||||
*/
|
Loading…
Add table
Add a link
Reference in a new issue