Improve tests
[bookreader.git] / BookReaderIA / test / unit / Preview.js
1 // Tests for BookReaderPreview.php
2
3 // Depends on common.js
4
5 module("Preview");
6
7 function Book(identifier, previewWidth, coverWidth, titleWidth) {
8     this.identifier = identifier;
9     this.previewWidth = previewWidth;
10     this.coverWidth = coverWidth;
11     this.titleWidth = titleWidth;
12 }
13
14 var books = [
15     new Book('coloritsapplicat00andriala', 1974, 2346, 1974),
16     new Book('lietuvostsrmoksl50liet', 1887, 1747, 1887),
17     new Book('oldtestamentrevi02slsn', 2019, 2371, 2019)
18 ];
19
20 for (index in books) {
21     (function() {
22         var i = index; // closure
23     
24         asyncTest("Load preview for " + books[index].identifier, function() {
25             expect(2);
26     
27             var book = books[i];    
28             var identifier = book.identifier;            
29             
30             var pageURI = previewURL(identifier, identifier, 'preview');
31             var img = new Image();
32             $(img).bind( 'load error', function(eventObj) {
33                 equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
34                 equals(this.width, book.previewWidth, 'Preview width');
35                 start();
36             })
37             .attr('src', pageURI);
38             
39             img = null;
40         });
41         
42         asyncTest("Load cover for " + books[index].identifier, function() {
43             expect(2);
44     
45             var book = books[i];    
46             var identifier = book.identifier;
47             
48             var pageURI = previewURL(identifier, identifier, 'cover');
49             var img = new Image();
50             $(img).bind( 'load error', function(eventObj) {
51                 equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
52                 equals(this.width, book.coverWidth, 'Cover width');
53                 start();
54             })
55             .attr('src', pageURI);
56             
57             img = null;
58         });
59         
60         asyncTest("Load title for " + books[index].identifier, function() {
61             expect(2);
62             
63             var book = books[i];    
64             var identifier = book.identifier;
65             
66             var pageURI = previewURL(identifier, identifier, 'title');
67             var img = new Image();
68             $(img).bind( 'load error', function(eventObj) {
69                 equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
70                 equals(this.width, book.titleWidth, 'Title image width');
71                 start();
72             })
73             .attr('src', pageURI);
74             
75             img = null;
76         });
77     })();
78 }