1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-03 14:59:18 +02:00
epub.js/libs/annotator/lib/spec/plugin/document_spec.js

110 lines
5.1 KiB
JavaScript

// Generated by CoffeeScript 1.6.3
describe('Annotator.Plugin.Document', function() {
var $fix, annotator;
$fix = null;
annotator = null;
beforeEach(function() {
annotator = new Annotator($('<div></div>')[0], {});
return annotator.addPlugin('Document');
});
afterEach(function() {
return $(document).unbind();
});
describe('has an annotator', function() {
return it('should have an annotator', function() {
return assert.ok(annotator);
});
});
describe('has the plugin', function() {
return it('should have Document plugin', function() {
return assert.ok('Document' in annotator.plugins);
});
});
return describe('annotation should have some metadata', function() {
var annotation, head;
head = $("head");
head.append('<link rel="alternate" href="foo.pdf" type="application/pdf"></link>');
head.append('<link rel="alternate" href="foo.doc" type="application/msword"></link>');
head.append('<link rel="bookmark" href="http://example.com/bookmark"></link>');
head.append('<meta name="citation_doi" content="10.1175/JCLI-D-11-00015.1">');
head.append('<meta name="citation_title" content="Foo">');
head.append('<meta name="citation_pdf_url" content="foo.pdf">');
head.append('<meta name="dc.identifier" content="doi:10.1175/JCLI-D-11-00015.1">');
head.append('<meta name="dc.identifier" content="isbn:123456789">');
head.append('<meta name="DC.type" content="Article">');
head.append('<meta property="og:url" content="http://example.com">');
head.append('<meta name="twitter:site" content="@okfn">');
head.append('<link rel="icon" href="http://example.com/images/icon.ico"></link>');
head.append('<meta name="eprints.title" content="Computer Lib / Dream Machines">');
head.append('<meta name="prism.title" content="Literary Machines">');
annotation = null;
beforeEach(function() {
return annotation = annotator.createAnnotation();
});
it('can create annotation', function() {
return assert.ok(annotation);
});
it('should have a document', function() {
return assert.ok(annotation.document);
});
it('should have a title, derived from highwire metadata if possible', function() {
return assert.equal(annotation.document.title, 'Foo');
});
it('should have links with absoulte hrefs and types', function() {
assert.ok(annotation.document.link);
assert.equal(annotation.document.link.length, 7);
assert.match(annotation.document.link[0].href, /^.+runner.html(\?.*)?$/);
assert.equal(annotation.document.link[1].rel, "alternate");
assert.match(annotation.document.link[1].href, /^.+foo\.pdf$/);
assert.equal(annotation.document.link[1].type, "application/pdf");
assert.equal(annotation.document.link[2].rel, "alternate");
assert.match(annotation.document.link[2].href, /^.+foo\.doc$/);
assert.equal(annotation.document.link[2].type, "application/msword");
assert.equal(annotation.document.link[3].rel, "bookmark");
assert.equal(annotation.document.link[3].href, "http://example.com/bookmark");
assert.equal(annotation.document.link[4].href, "doi:10.1175/JCLI-D-11-00015.1");
assert.match(annotation.document.link[5].href, /.+foo\.pdf$/);
assert.equal(annotation.document.link[5].type, "application/pdf");
return assert.equal(annotation.document.link[6].href, "doi:10.1175/JCLI-D-11-00015.1");
});
it('should have highwire metadata', function() {
assert.ok(annotation.document.highwire);
assert.deepEqual(annotation.document.highwire.pdf_url, ['foo.pdf']);
assert.deepEqual(annotation.document.highwire.doi, ['10.1175/JCLI-D-11-00015.1']);
return assert.deepEqual(annotation.document.highwire.title, ['Foo']);
});
it('should have dublincore metadata', function() {
assert.ok(annotation.document.dc);
assert.deepEqual(annotation.document.dc.identifier, ["doi:10.1175/JCLI-D-11-00015.1", "isbn:123456789"]);
return assert.deepEqual(annotation.document.dc.type, ["Article"]);
});
it('should have facebook metadata', function() {
assert.ok(annotation.document.facebook);
return assert.deepEqual(annotation.document.facebook.url, ["http://example.com"]);
});
it('should have eprints metadata', function() {
assert.ok(annotation.document.eprints);
return assert.deepEqual(annotation.document.eprints.title, ['Computer Lib / Dream Machines']);
});
it('should have prism metadata', function() {
assert.ok(annotation.document.prism);
return assert.deepEqual(annotation.document.prism.title, ['Literary Machines']);
});
it('should have twitter card metadata', function() {
assert.ok(annotation.document.twitter);
return assert.deepEqual(annotation.document.twitter.site, ['@okfn']);
});
it('should have unique uris', function() {
var uris;
uris = annotator.plugins.Document.uris();
return assert.equal(uris.length, 5);
});
return it('should have a favicon', function() {
return assert.equal(annotation.document.favicon, 'http://example.com/images/icon.ico');
});
});
});
/*
//@ sourceMappingURL=document_spec.map
*/