From 73d6d9a85c76e9305592a7a51fe60c95a79286d8 Mon Sep 17 00:00:00 2001 From: Michael Ang Date: Mon, 2 Aug 2010 23:11:22 +0000 Subject: [PATCH 1/1] Tests for permalinks --- BookReaderIA/test/unit/Permalinks.js | 101 +++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 BookReaderIA/test/unit/Permalinks.js diff --git a/BookReaderIA/test/unit/Permalinks.js b/BookReaderIA/test/unit/Permalinks.js new file mode 100644 index 0000000..73a55e6 --- /dev/null +++ b/BookReaderIA/test/unit/Permalinks.js @@ -0,0 +1,101 @@ + +// Depends on common.js + +module("Permalinks"); + +test("Permalink format - /download/{itemid}/page/{page specifier}.jpg", function() { + expect(1); + var page = 'page4.jpg'; + var itemId = 'handbookofdorking00denn'; + + var pageURI = imagePermalink(itemId, null, page); + equals(pageURI, common.testHost + '/download/handbookofdorking00denn/page/page4.jpg'); +}); + +(function() { + var page = 'page4.jpg'; + var itemId = 'handbookofdorking00denn'; + + asyncTest("Page " + page + " from " + itemId, function() { + expect(2); + + + var pageURI = imagePermalink(itemId, null, page); + + var img = new Image(); + $(img).bind( 'load error', function(eventObj) { + equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called'); + equals(this.width, 1566, 'Image width'); + start(); + }) + .attr('src', pageURI); + + img = null; + }); +})(); + +(function() { + var itemId = 'SubBookTest'; + var page = 'n9.jpg'; + var subPrefix = 'subdir/subsubdir/book3/Rfp008011ResponseInternetArchive-without-resume'; + + asyncTest("Sub-dir book - Page " + page + " from " + itemId + '/' + subPrefix, function() { + expect(2); + + var pageURI = imagePermalink(itemId, subPrefix, page); + + var img = new Image(); + $(img).bind( 'load error', function(eventObj) { + equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called'); + equals(this.width, 5100, 'Image width'); + start(); + }) + .attr('src', pageURI); + + img = null; + }); +})(); + +(function() { + var itemId = 'nasa_techdoc_20050157919'; + var page = 'n20_thumb_rotate90.jpg'; + var subPrefix = '20050157919'; + + asyncTest("Rotated thumbnail - Page " + page + " from " + itemId + '/' + subPrefix, function() { + expect(2); + + var pageURI = imagePermalink(itemId, subPrefix, page); + + var img = new Image(); + $(img).bind( 'load error', function(eventObj) { + equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called'); + equals(this.width, 179, 'Image width'); + start(); + }) + .attr('src', pageURI); + + img = null; + }); +})(); + +(function() { + var itemId = 'nasa_techdoc_20050157919'; + var page = 'preview_thumb.jpg'; + var subPrefix = null; + + asyncTest("Preview image for book in subdir without specifying sub-dir - Page " + page + " from " + itemId, function() { + expect(2); + + var pageURI = imagePermalink(itemId, subPrefix, page); + + var img = new Image(); + $(img).bind( 'load error', function(eventObj) { + equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called'); + equals(this.width, 122, 'Image width'); + start(); + }) + .attr('src', pageURI); + + img = null; + }); +})(); \ No newline at end of file -- 2.20.1