Add unit test for preview image of book in subdir!
authorMichael Ang <mang@archive.org>
Thu, 22 Jul 2010 22:57:47 +0000 (22:57 +0000)
committerMichael Ang <mang@archive.org>
Thu, 22 Jul 2010 22:57:47 +0000 (22:57 +0000)
BookReaderIA/test/unit/Common.js
BookReaderIA/test/unit/Images.js
BookReaderIA/test/unit/Preview.js

index 0a5f8bd..b416494 100644 (file)
@@ -24,6 +24,14 @@ function jsLocateURL(identifier, book) {
     return bookURL;
 }
 
-function previewURL(identifier, bookId, page) {
-    return common.testHost + '/download/' + identifier + '/page/' + bookId + '_' + page + '.jpg';
+function previewURL(identifier, subPrefix, page) {
+    var imageURL = common.testHost + '/download/' + identifier;
+    var bookPrefix = identifier;
+    if (subPrefix) {
+        imageURL += '/' + subPrefix;
+        var subPrefixParts = subPrefix.split('/')
+        bookPrefix = subPrefixParts[subPrefixParts.length - 1];
+    }
+    imageURL += '/page/' + bookPrefix + '_' + page + '.jpg';
+    return imageURL;
 }
\ No newline at end of file
index 0427def..8334cdc 100644 (file)
@@ -184,4 +184,3 @@ asyncTest('Load jpg image from tar file - https://bugs.launchpad.net/bookreader/
     })
     .attr('src', pageURI);
 });
-
index d83bece..8e095bc 100644 (file)
@@ -18,7 +18,7 @@ function Book(identifier, previewWidth, coverWidth, titleWidth, bookId) {
 var books = [
     new Book('coloritsapplicat00andriala', 1974, 2346, 1974),
     new Book('lietuvostsrmoksl50liet', 1887, 1747, 1887),
-    new Book('oldtestamentrevi02slsn', 2019, 2371, 2019)
+    new Book('oldtestamentrevi02slsn', 2019, 2371, 2019),
 ];
 
 for (index in books) {
@@ -83,7 +83,7 @@ for (index in books) {
 
 // Multi-book item
 var identifier = 'SubBookTest';
-asyncTest("Load title for " + identifier, function() {
+asyncTest("Load title for book without title specified " + identifier, function() {
     expect(1);
         
     var pageURI = previewURL(identifier, identifier, 'title');
@@ -97,13 +97,15 @@ asyncTest("Load title for " + identifier, function() {
     img = null;
 });
 
-asyncTest("Load title for " + identifier, function() {
-    expect(1);
+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, identifier, 'title');
+    var pageURI = previewURL(identifier, subPrefix, 'title');
     var img = new Image();
     $(img).bind( 'load error', function(eventObj) {
-        equals(eventObj.type, 'error', 'Load image (' + pageURI + '). Event handler called');
+        equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
+        equals(this.width, 5100, 'Preview image width');
         start();
     })
     .attr('src', pageURI);