check if click on 'Next' was successfully
[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                 var click = $(id).trigger("click");
40
41                 debug("next click is success: " + click.length);
42                 expect(click.length == 1).toBe(true);
43             }, time * 1000);
44         }
45
46         runs(function () {
47             // click next/prev after N seconds
48             my_click("#mkwsNext", 7);
49             my_click("#mkwsNext", 9);
50             my_click("#mkwsPrev", 9.5);
51         });
52     });
53 });
54
55
56 describe("Check pazpar2 hit counter", function () {
57     it("check running search hit counter", function () {
58         var max_time = 10; // in seconds
59         var expected_hits = 116; //
60         var j_time = 0;
61         var j_hits = 0;
62
63         function found(time, none) {
64             setTimeout(function () {
65                 j_time = time;
66
67                 var found = $("#mkwsPager").text();
68                 var re = /found: ([0-9]+)/;
69                 re.exec(found);
70                 var hits = -1;
71
72                 if (RegExp.$1) {
73                     hits = RegExp.$1;
74                     expect(hits).toBeGreaterThan(0);
75                 }
76
77                 // debug("found: " + found);
78                 if (none) {
79                     expect(hits < 0).toBeTruthy();
80                 } else {
81                     j_hits = hits;
82                 }
83
84                 debug("mkws pager found records: '" + hits + "'");
85                 debug("time state: " + j_time);
86
87                 expect(time >= 0).toBeTruthy();
88             }, time * 1000);
89         }
90
91         runs(function () {
92             // check hit counter after N seconds
93             found(0, true);
94             found(3);
95             found(6);
96             found(8);
97             found(max_time);
98         });
99
100         waitsFor(function () {
101             return j_time == max_time ? true : false;
102         }, "The Value should be 20 seconds", max_time * 1000);
103
104
105         runs(function () {
106             expect($("#mkwsPager").length == 1).toBe(true);
107         })
108
109         runs(function () {
110             expect(j_time <= max_time).toBeTruthy();
111             expect(j_hits).toBeGreaterThan(expected_hits);
112         });
113     });
114 });