Add privs check to metadata generator. Update unit 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, bookId = undefined) {
8     this.identifier = identifier;
9     this.previewWidth = previewWidth;
10     this.coverWidth = coverWidth;
11     this.titleWidth = titleWidth;
12     if (bookId === undefined) {
13         bookId = identifier;
14     }
15     this.bookId = bookId;
16 }
17
18 var books = [
19     new Book('coloritsapplicat00andriala', 1974, 2346, 1974),
20     new Book('lietuvostsrmoksl50liet', 1887, 1747, 1887),
21     new Book('oldtestamentrevi02slsn', 2019, 2371, 2019)
22 ];
23
24 for (index in books) {
25     (function() {
26         var i = index; // closure
27     
28         asyncTest("Load preview for " + books[index].identifier, function() {
29             expect(2);
30     
31             var book = books[i];    
32             var identifier = book.identifier;            
33             
34             var pageURI = previewURL(identifier, book.bookId, 'preview');
35             var img = new Image();
36             $(img).bind( 'load error', function(eventObj) {
37                 equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
38                 equals(this.width, book.previewWidth, 'Preview width');
39                 start();
40             })
41             .attr('src', pageURI);
42             
43             img = null;
44         });
45         
46         asyncTest("Load cover for " + books[index].identifier, function() {
47             expect(2);
48     
49             var book = books[i];    
50             var identifier = book.identifier;
51             
52             var pageURI = previewURL(identifier, book.bookId, 'cover');
53             var img = new Image();
54             $(img).bind( 'load error', function(eventObj) {
55                 equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
56                 equals(this.width, book.coverWidth, 'Cover width');
57                 start();
58             })
59             .attr('src', pageURI);
60             
61             img = null;
62         });
63         
64         asyncTest("Load title for " + books[index].identifier, function() {
65             expect(2);
66             
67             var book = books[i];    
68             var identifier = book.identifier;
69             
70             var pageURI = previewURL(identifier, book.bookId, 'title');
71             var img = new Image();
72             $(img).bind( 'load error', function(eventObj) {
73                 equals(eventObj.type, 'load', 'Load image (' + pageURI + '). Event handler called');
74                 equals(this.width, book.titleWidth, 'Title image width');
75                 start();
76             })
77             .attr('src', pageURI);
78             
79             img = null;
80         });
81     })();
82 }
83
84 // Multi-book item
85 var identifier = 'SubBookTest';
86 asyncTest("Load title for " + identifier, function() {
87     expect(1);
88         
89     var pageURI = previewURL(identifier, identifier, 'title');
90     var img = new Image();
91     $(img).bind( 'load error', function(eventObj) {
92         equals(eventObj.type, 'error', 'Load image (' + pageURI + '). Event handler called');
93         start();
94     })
95     .attr('src', pageURI);
96     
97     img = null;
98 });
99
100 asyncTest("Load title for " + identifier, function() {
101     expect(1);
102         
103     var pageURI = previewURL(identifier, identifier, 'title');
104     var img = new Image();
105     $(img).bind( 'load error', function(eventObj) {
106         equals(eventObj.type, 'error', 'Load image (' + pageURI + '). Event handler called');
107         start();
108     })
109     .attr('src', pageURI);
110     
111     img = null;
112 });