Commit dc00cf4c authored by Alice Wyan's avatar Alice Wyan

Remove no longer needed auxiliary file document-domain.js

Move relevant tests to annotation-metadata-test.js, and fix a bug
in annotation-metadata.js.
parent f247cb7c
......@@ -21,6 +21,10 @@ function documentMetadata(annotation) {
title = annotation.document.title[0];
}
if (domain === 'localhost') {
domain = '';
}
return {
uri: uri,
domain: domain,
......@@ -45,7 +49,7 @@ function domainAndTitle(annotation) {
titleLink = annotation.links.incontext;
}
var domainText;
var domainText = '';
if (document.uri && document.uri.indexOf('file://') === 0 && document.title) {
var parts = document.uri.split('/');
var filename = parts[parts.length - 1];
......
'use strict';
var escapeHtml = require('escape-html');
/**
* Return a nice displayable string representation of a document's domain.
*
* @returns {String} The document's domain in braces, e.g. '(example.com)'.
* Returns '' if the document has no domain or if the document's domain is
* the same as its title (because we assume that the title is already
* displayed elsewhere and displaying it twice would be redundant).
*
*/
module.exports = function documentDomain(document) {
var uri = escapeHtml(document.uri || '');
var domain = escapeHtml(document.domain || '');
var title = escapeHtml(document.title || '');
if (uri.indexOf('file://') === 0 && title) {
var parts = uri.split('/');
var filename = parts[parts.length - 1];
if (filename) {
return '(' + decodeURIComponent(filename) + ')';
}
}
if (domain && domain !== title) {
return '(' + decodeURIComponent(domain) + ')';
} else {
return '';
}
};
'use strict';
var documentDomain = require('../document-domain');
describe('documentDomain', function() {
it('returns the domain in braces', function() {
var domain = documentDomain({
domain: 'example.com'
});
assert(domain === '(example.com)');
});
it('returns an empty string if domain and title are the same', function() {
var domain = documentDomain({
domain: 'example.com',
title: 'example.com'
});
assert(domain === '');
});
it('returns an empty string if the document has no domain', function() {
var domain = documentDomain({
title: 'example.com'
});
assert(domain === '');
});
it('returns the filename for local documents with titles', function() {
var domain = documentDomain({
title: 'example.com',
uri: 'file:///home/seanh/MyFile.pdf'
});
assert(domain === '(MyFile.pdf)');
});
it('replaces %20 with " "', function() {
var domain = documentDomain({
title: 'example.com',
uri: 'file:///home/seanh/My%20File.pdf'
});
assert(domain === '(My File.pdf)');
});
it('escapes HTML in the document domain', function() {
var spamLink = '<a href="http://example.com/rubies">Buy rubies!!!</a>';
var domain = documentDomain({
title: 'title',
domain: '</a>' + spamLink
});
assert(domain.indexOf(spamLink) === -1);
});
it('escapes HTML in the document uri', function() {
var spamLink = '<a href="http://example.com/rubies">Buy rubies!!!</a>';
var domain = documentDomain({
title: 'title',
uri: 'file:///home/seanh/' + spamLink
});
assert(domain.indexOf(spamLink) === -1);
});
});
......@@ -150,6 +150,44 @@ describe('annotation-metadata', function () {
assert.equal(domainAndTitle(model).domain, 'example.pdf');
});
});
context('when domain and title are the same', function () {
it('returns an empty domain text string', function() {
var model = {
uri: 'https://example.com',
document : {
title: ['example.com'],
},
};
assert.equal(domainAndTitle(model).domain, '');
});
});
context('when the document has no domain', function () {
it('returns an empty domain text string', function() {
var model = {
document : {
title: ['example.com'],
},
};
assert.equal(domainAndTitle(model).domain, '');
});
});
context('when the document is a local file with a title', function () {
it('returns the filename', function() {
var model = {
uri: 'file:///home/seanh/MyFile.pdf',
document: {
title: ['example.com'],
},
};
assert.equal(domainAndTitle(model).domain, 'MyFile.pdf');
});
});
});
describe('.location', function () {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment