X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=BookReaderIA%2Ftest%2Funit%2FPreview.js;fp=BookReaderIA%2Ftest%2Funit%2FPreview.js;h=87e2415fd3f85d4b8676a096b6435428f0ce740a;hb=e989a6f61e97001285682a73193b757649139abc;hp=3a34306f6d01cb53e5845aa353571d6eb1086f96;hpb=073fd3241f3e653e58c4e8a5ee4bdc51c6ade305;p=bookreader.git diff --git a/BookReaderIA/test/unit/Preview.js b/BookReaderIA/test/unit/Preview.js index 3a34306..87e2415 100644 --- a/BookReaderIA/test/unit/Preview.js +++ b/BookReaderIA/test/unit/Preview.js @@ -4,56 +4,75 @@ module("Preview"); -var identifiers = [ - 'coloritsapplicat00andriala', - 'lietuvostsrmoksl50liet', - 'oldtestamentrevi02slsn', - 'bokeofsaintalban00bernuoft' +function Book(identifier, previewWidth, coverWidth, titleWidth) { + this.identifier = identifier; + this.previewWidth = previewWidth; + this.coverWidth = coverWidth; + this.titleWidth = titleWidth; +} + +var books = [ + new Book('coloritsapplicat00andriala', 1974, 2346, 1974), + new Book('lietuvostsrmoksl50liet', 1887, 1747, 1887), + new Book('oldtestamentrevi02slsn', 2019, 2371, 2019) ]; -for (index in identifiers) { - var identifier = identifiers[index]; - asyncTest("Load preview for " + identifier, function() { - expect(1); - - var pageURI = previewURL(identifier, identifier, 'preview'); - var img = new Image(); - $(img).bind( 'load error', function(eventObj) { - equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called'); - start(); - }) - .attr('src', pageURI); - - img = null; - }); +for (index in books) { + (function() { + var i = index; // closure - asyncTest("Load cover for " + identifier, function() { - expect(1); - - var pageURI = previewURL(identifier, identifier, 'cover'); - var img = new Image(); - $(img).bind( 'load error', function(eventObj) { - equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called'); - start(); - }) - .attr('src', pageURI); - - img = null; - }); + asyncTest("Load preview for " + books[index].identifier, function() { + expect(2); - asyncTest("Load title for " + identifier, function() { - expect(1); + var book = books[i]; + var identifier = book.identifier; + + var pageURI = previewURL(identifier, identifier, 'preview'); + var img = new Image(); + $(img).bind( 'load error', function(eventObj) { + equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called'); + equals(this.width, book.previewWidth, 'Preview width'); + start(); + }) + .attr('src', pageURI); + + img = null; + }); - var pageURI = previewURL(identifier, identifier, 'title'); - var img = new Image(); - $(img).bind( 'load error', function(eventObj) { - equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called'); - start(); - }) - .attr('src', pageURI); + asyncTest("Load cover for " + books[index].identifier, function() { + expect(2); + + var book = books[i]; + var identifier = book.identifier; + + var pageURI = previewURL(identifier, identifier, 'cover'); + var img = new Image(); + $(img).bind( 'load error', function(eventObj) { + equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called'); + equals(this.width, book.coverWidth, 'Cover width'); + start(); + }) + .attr('src', pageURI); + + img = null; + }); - img = null; - }); - - + asyncTest("Load title for " + books[index].identifier, function() { + expect(2); + + var book = books[i]; + var identifier = book.identifier; + + var pageURI = previewURL(identifier, identifier, 'title'); + var img = new Image(); + $(img).bind( 'load error', function(eventObj) { + equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called'); + equals(this.width, book.titleWidth, 'Title image width'); + start(); + }) + .attr('src', pageURI); + + img = null; + }); + })(); } \ No newline at end of file