Closes #14, closes #15. Fix recovery path used when jp2 is requested at less than...
[bookreader.git] / BookReaderIA / test / unit / Preview.js
index 87e2415..468867c 100644 (file)
@@ -4,17 +4,26 @@
 
 module("Preview");
 
-function Book(identifier, previewWidth, coverWidth, titleWidth) {
+function Book(identifier, previewWidth, coverWidth, titleWidth, imageSize, bookId) {
     this.identifier = identifier;
     this.previewWidth = previewWidth;
     this.coverWidth = coverWidth;
     this.titleWidth = titleWidth;
+    if (bookId === undefined) {
+        bookId = identifier;
+    }
+    this.bookId = bookId;
 }
 
 var books = [
-    new Book('coloritsapplicat00andriala', 1974, 2346, 1974),
-    new Book('lietuvostsrmoksl50liet', 1887, 1747, 1887),
-    new Book('oldtestamentrevi02slsn', 2019, 2371, 2019)
+    // Old books using title page as cover (ignoring marked cover)
+    new Book('coloritsapplicat00andriala', 1974, 1974, 1974),
+    new Book('lietuvostsrmoksl50liet', 1887, 1887, 1887),
+    new Book('oldtestamentrevi02slsn', 2019, 2019, 2019),
+    
+    // Protected book with marked cover returned as cover
+    new Book('joyofsoaringtrai00conw', 2571, 2571, 2419)
+    
 ];
 
 for (index in books) {
@@ -27,7 +36,7 @@ for (index in books) {
             var book = books[i];    
             var identifier = book.identifier;            
             
-            var pageURI = previewURL(identifier, identifier, 'preview');
+            var pageURI = previewURL(identifier, book.bookId, 'preview');
             var img = new Image();
             $(img).bind( 'load error', function(eventObj) {
                 equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
@@ -45,7 +54,7 @@ for (index in books) {
             var book = books[i];    
             var identifier = book.identifier;
             
-            var pageURI = previewURL(identifier, identifier, 'cover');
+            var pageURI = previewURL(identifier, book.bookId, 'cover');
             var img = new Image();
             $(img).bind( 'load error', function(eventObj) {
                 equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
@@ -63,7 +72,7 @@ for (index in books) {
             var book = books[i];    
             var identifier = book.identifier;
             
-            var pageURI = previewURL(identifier, identifier, 'title');
+            var pageURI = previewURL(identifier, book.bookId, 'title');
             var img = new Image();
             $(img).bind( 'load error', function(eventObj) {
                 equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
@@ -75,4 +84,36 @@ for (index in books) {
             img = null;
         });
     })();
-}
\ No newline at end of file
+}
+
+// Multi-book item
+var identifier = 'SubBookTest';
+asyncTest("Load title for book without title specified " + identifier, function() {
+    expect(1);
+        
+    var pageURI = previewURL(identifier, identifier, 'title');
+    var img = new Image();
+    $(img).bind( 'load error', function(eventObj) {
+        equals(eventObj.type, 'error', 'Load image (' + pageURI + '). Event handler called');
+        start();
+    })
+    .attr('src', pageURI);
+    
+    img = null;
+});
+
+var subPrefix = 'subdir/subsubdir/book3/Rfp008011ResponseInternetArchive-without-resume';
+asyncTest("Load preview for book in sub-dir " + identifier + '/' + subPrefix, function() {
+    expect(2);
+        
+    var pageURI = previewURL(identifier, subPrefix, 'title');
+    var img = new Image();
+    $(img).bind( 'load error', function(eventObj) {
+        equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
+        equals(this.width, 5100, 'Preview image width');
+        start();
+    })
+    .attr('src', pageURI);
+    
+    img = null;
+});