1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-05 15:32:55 +02:00

Updated Chapter to use cloned document, added find method to get cfi of a string within the chapter, Added Book.chapter method to load a chapter from URL

This commit is contained in:
Fred Chasen 2014-07-09 00:34:49 -07:00
parent 8829d14186
commit 02fba7d148
6 changed files with 197 additions and 13 deletions

80
tests/chapter.js Normal file
View file

@ -0,0 +1,80 @@
module('Chapter');
asyncTest("Create a Chapter", 2, function() {
var book = ePub('/reader/moby-dick/', { width: 400, height: 600 });
book.ready.all.then(function(){
var chapter = book.chapter("chapter_001.xhtml");
equal(chapter.spinePos, 6, "Chapter Pos is correct" );
equal(chapter.href, "chapter_001.xhtml", "Chapter href is correct" );
start();
});
});
asyncTest("Load a Chapter", 2, function() {
var book = ePub('/reader/moby-dick/', { width: 400, height: 600 });
book.ready.all.then(function(){
var chapter = book.chapter("chapter_001.xhtml");
// var loaded = chapter.load();
start();
equal(chapter.href, "chapter_001.xhtml", "Chapter href is correct" );
stop();
chapter.loaded.then(function(){
equal(chapter.document.firstChild.nodeName, "html", "Document HTML is loaded" );
start();
});
});
});
asyncTest("Find a single query in a Chapter", 3, function() {
var book = ePub('/reader/moby-dick/', { width: 400, height: 600 });
book.ready.all.then(function(){
var chapter = book.chapter("chapter_001.xhtml");
// var loaded = chapter.load();
start();
equal(chapter.href, "chapter_001.xhtml", "Chapter href is correct" );
stop();
chapter.loaded.then(function(){
var results = chapter.find("pythagorean maxim");
equal(results.length, 1, "Results are returned" );
equal(results[0], "epubcfi(/6/14[xchapter_001]!4/2/24/2[c001p0011]/1:227,4/2/24/2[c001p0011]/1:244)", "CFI is generated");
start();
});
});
});
asyncTest("Find a query with several results in a Chapter", 3, function() {
var book = ePub('/reader/moby-dick/', { width: 400, height: 600 });
book.ready.all.then(function(){
var chapter = book.chapter("chapter_001.xhtml");
// var loaded = chapter.load();
start();
equal(chapter.href, "chapter_001.xhtml", "Chapter href is correct");
stop();
chapter.loaded.then(function(){
var results = chapter.find("yet");
equal(results.length, 4, "Results are returned" );
equal(results[3], "epubcfi(/6/14[xchapter_001]!4/2/28/2[c001p0015]/1:314,4/2/28/2[c001p0015]/1:317)", "CFI is generated");
start();
});
});
});