mirror of
https://github.com/futurepress/epub.js.git
synced 2025-10-03 14:59:18 +02:00
127 lines
4.3 KiB
JavaScript
127 lines
4.3 KiB
JavaScript
// Generated by CoffeeScript 1.6.3
|
|
describe('Util.flatten()', function() {
|
|
return it("flattens the contents of an Array", function() {
|
|
var flattened;
|
|
flattened = Util.flatten([[1, 2], 'lorem ipsum', [{}]]);
|
|
return assert.deepEqual(flattened, [1, 2, 'lorem ipsum', {}]);
|
|
});
|
|
});
|
|
|
|
describe('Util.getTextNodes()', function() {
|
|
var $fix;
|
|
$fix = null;
|
|
beforeEach(function() {
|
|
addFixture('textnodes');
|
|
return $fix = $(fix());
|
|
});
|
|
afterEach(function() {
|
|
return clearFixtures();
|
|
});
|
|
it("returns an element's textNode descendants", function() {
|
|
var expectation, node, nodes, text;
|
|
nodes = Util.getTextNodes($fix);
|
|
text = (function() {
|
|
var _i, _len, _results;
|
|
_results = [];
|
|
for (_i = 0, _len = nodes.length; _i < _len; _i++) {
|
|
node = nodes[_i];
|
|
_results.push(node.nodeValue);
|
|
}
|
|
return _results;
|
|
})();
|
|
expectation = ['\n ', 'lorem ipsum', '\n ', 'dolor sit', '\n', '\n', 'dolor sit ', 'amet', '. humpty dumpty. etc.'];
|
|
return assert.deepEqual(text, expectation);
|
|
});
|
|
it("returns an empty jQuery collection when called in undefined node", function() {
|
|
var result;
|
|
result = Util.getTextNodes($(void 0));
|
|
assert.instanceOf(result, jQuery);
|
|
return assert.lengthOf(result, 0);
|
|
});
|
|
return it("returns an element's TextNodes after Text.splitText() text has been called", function() {
|
|
var first, fixture, para, text;
|
|
fixture = document.getElementById('fixtures') || $('body')[0];
|
|
fixture.innerHTML = '';
|
|
para = document.createElement('p');
|
|
text = document.createTextNode('this is a paragraph of text');
|
|
para.appendChild(text);
|
|
fixture.appendChild(para);
|
|
assert.lengthOf(para.childNodes, 1);
|
|
first = text.splitText(14);
|
|
assert.equal(first.nodeValue, 'graph of text');
|
|
assert.equal(text.nodeValue, 'this is a para');
|
|
assert.equal(para.firstChild.nodeValue, 'this is a para');
|
|
assert.equal(para.lastChild.nodeValue, 'graph of text');
|
|
return assert.lengthOf(Util.getTextNodes($(para)), 2);
|
|
});
|
|
});
|
|
|
|
describe('Util.xpathFromNode', function() {
|
|
var $fix;
|
|
$fix = null;
|
|
beforeEach(function() {
|
|
addFixture('xpath');
|
|
return $fix = $(fix());
|
|
});
|
|
afterEach(function() {
|
|
return clearFixtures();
|
|
});
|
|
it("generates an XPath string for an element's position in the document", function() {
|
|
var pathToFixHTML;
|
|
pathToFixHTML = '/html[1]/body[1]/div[1]';
|
|
assert.deepEqual(Util.xpathFromNode($fix.find('p')), [pathToFixHTML + '/p[1]', pathToFixHTML + '/p[2]']);
|
|
assert.deepEqual(Util.xpathFromNode($fix.find('span')), [pathToFixHTML + '/ol[1]/li[2]/span[1]']);
|
|
return assert.deepEqual(Util.xpathFromNode($fix.find('strong')), [pathToFixHTML + '/p[2]/strong[1]']);
|
|
});
|
|
return it("takes an optional parameter determining the element from which XPaths should be calculated", function() {
|
|
var ol;
|
|
ol = $fix.find('ol').get(0);
|
|
assert.deepEqual(Util.xpathFromNode($fix.find('li'), ol), ['/li[1]', '/li[2]', '/li[3]']);
|
|
return assert.deepEqual(Util.xpathFromNode($fix.find('span'), ol), ['/li[2]/span[1]']);
|
|
});
|
|
});
|
|
|
|
describe('Util.escape()', function() {
|
|
return it("should escape any HTML special characters into entities", function() {
|
|
return assert.equal(Util.escape('<>"&'), '<>"&');
|
|
});
|
|
});
|
|
|
|
describe('Util.uuid()', function() {
|
|
return it("should return a unique id on each call", function() {
|
|
var counter, current, results, _results;
|
|
counter = 100;
|
|
results = [];
|
|
_results = [];
|
|
while (counter--) {
|
|
current = Util.uuid();
|
|
assert.equal(results.indexOf(current), -1);
|
|
_results.push(results.push(current));
|
|
}
|
|
return _results;
|
|
});
|
|
});
|
|
|
|
describe('Util.preventEventDefault()', function() {
|
|
return it("should call prevent default if the method exists", function() {
|
|
var event;
|
|
event = {
|
|
preventDefault: sinon.spy()
|
|
};
|
|
Util.preventEventDefault(event);
|
|
assert(event.preventDefault.calledOnce);
|
|
assert.doesNotThrow((function() {
|
|
return Util.preventEventDefault(1);
|
|
}), Error);
|
|
assert.doesNotThrow((function() {
|
|
return Util.preventEventDefault(null);
|
|
}), Error);
|
|
return assert.doesNotThrow((function() {
|
|
return Util.preventEventDefault(void 0);
|
|
}), Error);
|
|
});
|
|
});
|
|
|
|
/*
|
|
//@ sourceMappingURL=util_spec.map
|
|
*/
|