disable dummy test EOF
[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 var debug = mkws.debug;
8
9 var get_hit_counter = function () {
10     if ($("#mkwsPager").length == 0) return -1;
11
12     var found = $("#mkwsPager").text();
13     var re = /\([A-Za-z]+:\s+([0-9]+)\)/;
14     re.exec(found);
15     var hits = -1;
16
17     if (RegExp.$1) {
18         hits = parseInt(RegExp.$1);
19         expect(hits).toBeGreaterThan(0);
20     }
21
22     //debug("Hits: " + hits);
23     return hits;
24 }
25
26 describe("Check pazpar2 search", function () {
27     it("pazpar2 was successfully initialize", function () {
28         expect(mkws_config.error).toBe(undefined);
29     });
30
31     it("validate HTML id's", function () {
32         expect($("input#mkwsQuery").length == 1).toBe(true);
33         expect($("input#mkwsButton").length == 1).toBe(true);
34
35         expect($("#mkwsNext").length == 1).toBe(false);
36         expect($("#mkwsPrev").length == 1).toBe(false);
37     });
38
39     it("run search query", function () {
40         var search_query = "freebsd"; // short hit counter with some paging
41
42         $("input#mkwsQuery").val(search_query);
43         debug("set search query: " + search_query)
44         expect($("input#mkwsQuery").val()).toMatch("^" + search_query + "$");
45
46         // wait for service proxy auth
47         waitsFor(function () {
48             return mkws.service_proxy_auth;
49         }, "SP auth done", 10 * 1000);
50
51         runs(function () {
52             debug("Click on submit button");
53             var click = $("input#mkwsButton").trigger("click");
54             expect(click.length == 1).toBe(true);
55         })
56     });
57 });
58
59
60 describe("Check pazpar2 navigation", function () {
61     // Asynchronous part
62     it("check running search next/prev", function () {
63         expect($("#mkwsPager").length == 1).toBe(true);
64
65         function my_click(id, time) {
66             setTimeout(function () {
67                 debug("trigger click on id: " + id);
68                 var click = $(id).trigger("click");
69
70                 debug("next click is success: " + click.length);
71                 expect(click.length == 1).toBe(true);
72
73             }, time * 1000);
74         }
75
76         runs(function () {
77             // click next/prev after N seconds
78             my_click("#mkwsNext", 7);
79             my_click("#mkwsNext", 8);
80             my_click("#mkwsPrev", 9);
81         });
82     });
83 });
84
85 describe("Check pazpar2 hit counter", function () {
86     it("check running search hit counter", function () {
87         var max_time = 10; // in seconds
88         var expected_hits = 116; // at least expected hit counter
89
90         var hits = 0;
91
92         waitsFor(function () {
93             hits = get_hit_counter();
94
95             return hits >= expected_hits;
96         }, "Expect N hits in x seconds", max_time * 1000);
97
98
99         runs(function () {
100             debug("mkws pager found records: '" + hits + "'");
101             expect($("#mkwsPager").length == 1).toBe(true);
102             expect(hits).toBeGreaterThan(expected_hits);
103         });
104     });
105 });
106
107 describe("Check Termlist", function () {
108     function show_record() {
109         var click = $("div#mkwsRecords div.record:nth-child(3) :nth-child(2)").trigger("click");
110         debug("show click is success: " + click.length);
111         expect(click.length == 1).toBe(true);
112     }
113
114     // show_record();
115     it("found Termlist", function () {
116         var termlist = $("div#mkwsTermlists");
117         debug("Termlist success: " + termlist.length);
118         expect(termlist.length == 1).toBe(true);
119
120         var sources = $("div#mkwsFacetSources");
121         expect(sources.length == 1).toBe(true);
122
123         var subjects = $("div#mkwsFacetSubjects");
124         expect(subjects.length == 1).toBe(true);
125
126         var authors = $("div#mkwsFacetAuthors");
127         expect(authors.length == 1).toBe(true);
128     });
129
130     it("limit search to first source", function () {
131         var hits_all_targets = get_hit_counter();
132
133         var click = $("div#mkwsFacetSources div.term:nth-child(2) a").trigger("click");
134         debug("limit source click is success: " + click.length);
135         expect(click.length == 1).toBe(true);
136
137         waitsFor(function () {
138             if ($("div#mkwsNavi").length && $("div#mkwsNavi").text().match(/^Source/)) {
139                 return true;
140             } else {
141                 return false;
142             }
143         }, "Search for source in navi bar", 1000);
144
145         waitsFor(function () {
146             return get_hit_counter() < hits_all_targets ? true : false;
147         }, "Search for with less hits", 9 * 1000);
148
149         runs(function () {
150             var hits_single_target = get_hit_counter();
151             debug("get less hits for sources: " + hits_all_targets + " > " + hits_single_target);
152             expect(hits_all_targets).toBeGreaterThan(hits_single_target);
153         });
154     });
155
156     it("limit search to first author", function () {
157         var hits_all_targets = get_hit_counter();
158
159         var click = $("div#mkwsFacetAuthors div.term:nth-child(2) a").trigger("click");
160         debug("limit author click is success: " + click.length);
161         expect(click.length == 1).toBe(true);
162
163         waitsFor(function () {
164             return get_hit_counter() < hits_all_targets ? true : false;
165         }, "Search for with less hits", 9 * 1000);
166
167         runs(function () {
168             var hits_single_target = get_hit_counter();
169             debug("get less hits for authors: " + hits_all_targets + " > " + hits_single_target);
170             expect(hits_all_targets).toBeGreaterThan(hits_single_target);
171         });
172     });
173
174     it("show record author", function () {
175         show_record();
176     });
177 });
178
179 describe("Check status client counter", function () {
180     function get_time() {
181         var date = new Date();
182         return date.getTime();
183     }
184     var time = get_time();
185
186     it("check status clients", function () {
187
188         waitsFor(function () {
189             var clients = $("div#mkwsStat span.clients");
190             if (clients.length == 1 && clients.text() == "0/1") {
191                 return true;
192             } else {
193                 return false;
194             }
195
196         }, "wait for status", 4 * 1000);
197
198     });
199     runs(function () {
200         var clients = $("div#mkwsStat span.clients");
201         debug("span.clients: " + clients.text());
202         expect(clients.text()).toEqual("0/1");
203     });
204
205 });
206
207
208
209 /* dummy EOF */
210 /*
211 describe("All tests are done", function () {
212     it(">>> hooray!!! <<<", function () {
213     });
214 });
215 */