working
[mkws-moved-to-github.git] / test / spec / mkws-pazpar2.js
1 /* Copyright (c) 2013 IndexData ApS. http://indexdata.com
2  *
3  * perform papzpar2 / pz2.js search & retrieve request in the browser
4  *
5  */
6
7 describe("Check pazpar2 search", function () {
8     it("pazpar2 was successfully initialize", function () {
9         expect(mkws_config.error).toBe(undefined);
10     });
11
12     it("validate HTML id's", function () {
13         expect($("input#mkwsQuery").length == 1).toBe(true);
14         expect($("input#mkwsButton").length == 1).toBe(true);
15
16         expect($("#mkwsNext").length == 1).toBe(false);
17         expect($("#mkwsPrev").length == 1).toBe(false);
18     });
19
20     it("run search query", function () {
21         $("input#mkwsQuery").val("freebsd");
22         expect($("input#mkwsQuery").val()).toMatch(/^freebsd$/);
23
24         setTimeout(function () {
25             $("input#mkwsButton").trigger("click");
26         }, 3 * 1000);
27     });
28 });
29
30
31 describe("Check pazpar2 navigation", function () {
32     // Asynchronous part
33     it("check running search next/prev", function () {
34         expect($("#mkwsPager").length == 1).toBe(true);
35
36         function my_click(id, time) {
37             setTimeout(function () {
38                 debug("trigger click on id: " + id);
39                 $(id).trigger("click");
40                 expect(time >= 0).toBeTruthy();
41             }, time * 1000);
42         }
43
44         runs(function () {
45             // click next/prev after N seconds
46             my_click("#mkwsNext", 7);
47             my_click("#mkwsNext", 10);
48             my_click("#mkwsPrev", 12);
49         });
50     });
51 });
52
53
54 describe("Check pazpar2 hit counter", function () {
55     it("check running search hit counter", function () {
56         var max_time = 13;
57         var j_time = 0;
58         var j_hits = 0;
59
60         function found(time, none) {
61             describe("found hits", function () {
62                 setTimeout(function () {
63                     j_time = time;
64
65                     var found = $("#mkwsPager").text();
66                     var re = /found: ([0-9]+)/;
67                     re.exec(found);
68                     var hits = -1;
69
70                     if (RegExp.$1) {
71                         hits = RegExp.$1;
72                         expect(hits).toBeGreaterThan(0);
73                     }
74
75                     // debug("found: " + found);
76                     if (none) {
77                         expect(hits < 0).toBeTruthy();
78                     } else {
79                         j_hits = hits;
80                     }
81
82                     debug("mkws pager found records: '" + hits + "'");
83                     debug("time state: " + j_time);
84
85                     expect(time >= 0).toBeTruthy();
86                 }, time * 1000);
87             });
88         }
89
90         runs(function () {
91             // check hit counter after N seconds
92             found(0, true);
93             found(5);
94             found(10);
95             found(15);
96             found(max_time);
97         });
98
99         waitsFor(function () {
100             return j_time == max_time ? true : false;
101         }, "The Value should be 20 seconds", 30 * 1000); // (max_time + 1) * 1000);
102         runs(function () {
103             expect($("#mkwsPager").length == 1).toBe(true);
104         })
105
106         runs(function () {
107             expect(j_time <= max_time).toBeTruthy();
108             expect(j_hits > 0).toBeTruthy();
109         });
110     });
111 });