1 /* Copyright (c) 2013 IndexData ApS. http://indexdata.com
3 * perform papzpar2 / pz2.js search & retrieve request in the browser
7 // get references from mkws.js, lazy evaluation
8 var debug = function (text) {
9 mkws.debug_function(text)
12 var get_hit_counter = function () {
14 if ($("#mkwsPager").length == 0) return -1;
16 var found = $("#mkwsPager").text();
17 var re = /\([A-Za-z]+:\s+([0-9]+)\)/;
22 hits = parseInt(RegExp.$1);
23 expect(hits).toBeGreaterThan(0);
26 //debug("Hits: " + hits);
30 describe("Check pazpar2 search", function () {
31 it("pazpar2 was successfully initialize", function () {
32 expect(mkws_config.error).toBe(undefined);
35 it("validate HTML id's", function () {
36 expect($("input#mkwsQuery").length).toBe(1);
37 expect($("input#mkwsButton").length).toBe(1);
39 expect($("#mkwsNext").length).not.toBe(1);
40 expect($("#mkwsPrev").length).not.toBe(1);
43 it("run search query", function () {
44 var search_query = "freebsd"; // short hit counter with some paging
45 $("input#mkwsQuery").val(search_query);
46 debug("set search query: " + search_query)
47 expect($("input#mkwsQuery").val()).toMatch("^" + search_query + "$");
49 if (mkws_config.use_service_proxy) {
50 // wait for service proxy auth
51 waitsFor(function () {
52 return mkws.authenticated;
53 }, "SP auth done", 10 * 1000);
55 debug("running raw pp2, don't wait for mkws auth");
59 debug("Click on submit button");
60 var click = $("input#mkwsButton").trigger("click");
61 expect(click.length).toBe(1);
68 * This part runs in background. It should be rewritten with
69 * async jasmine functions
72 describe("Check pazpar2 navigation", function () {
74 it("check running search next/prev", function () {
75 expect($("#mkwsPager").length).toBe(1);
77 function my_click(id, time) {
78 setTimeout(function () {
79 debug("trigger click on id: " + id);
80 var click = $(id).trigger("click");
82 debug("next/prev: " + id + " click is success: " + click.length);
83 expect(click.length).toBe(1);
87 waitsFor(function () {
88 return $("div#mkwsPager div:nth-child(2) a").length >= 2 ? true : false;
89 }, "Expect next link 2", 10 * 1000);
92 // click next/prev after N seconds
93 my_click("#mkwsNext", 0);
96 waitsFor(function () {
97 return $("div#mkwsPager div:nth-child(2) a").length >= 3 ? true : false;
98 }, "Expect next link 3", 5 * 1000);
101 // click next/prev after N seconds
102 my_click("#mkwsNext", 0);
103 my_click("#mkwsPrev", 0.2);
108 describe("Check pazpar2 hit counter", function () {
109 it("check running search hit counter", function () {
110 var max_time = 16; // in seconds
111 var expected_hits = 80; // at least expected hit counter
114 waitsFor(function () {
115 hits = get_hit_counter();
117 return hits > expected_hits;
118 }, "Expect " + expected_hits + " hits", max_time * 1000);
122 debug("mkws pager found records: '" + hits + "'");
123 expect($("#mkwsPager").length).toBe(1);
124 expect(hits).toBeGreaterThan(expected_hits);
129 describe("Check Termlist", function () {
130 it("found Termlist", function () {
131 var termlist = $("div#mkwsTermlists");
132 debug("Termlist success: " + termlist.length);
133 expect(termlist.length).toBe(1);
135 waitsFor(function () {
136 return $("div#mkwsFacetSources").length == 1 ? true : false;
137 }, "check for facet sources", 2 * 1000);
140 // everything displayed?
142 var sources = $("div#mkwsFacetSources");
143 debug("Termlist sources success: " + sources.length);
144 expect(sources.length).toBe(1);
146 var subjects = $("div#mkwsFacetSubjects");
147 expect(subjects.length).toBe(1);
149 var authors = $("div#mkwsFacetAuthors");
150 expect(authors.length).toBe(1);
153 waitsFor(function () {
154 return $("div#mkwsFacetAuthors div.term").length >= 2 ? true : false;
155 }, "At least one author link displayed", 2 * 1000);
158 expect($("div#mkwsFacetAuthors div.term").length).toBeGreaterThan(1);
162 it("limit search to first author", function () {
163 var hits_all_targets = get_hit_counter();
165 var click = $("div#mkwsFacetAuthors div.term:nth-child(2) a").trigger("click");
166 debug("limit author click is success: " + click.length);
167 expect(click.length).toBe(1);
169 waitsFor(function () {
170 return get_hit_counter() < hits_all_targets ? true : false;
171 }, "Limited author search for less than " + hits_all_targets + " hits", 8 * 1000);
174 var hits_single_target = get_hit_counter();
175 debug("get less hits for authors: " + hits_all_targets + " > " + hits_single_target);
176 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
180 it("limit search to first source", function () {
181 var hits_all_targets = get_hit_counter();
182 var source_number = 2; // 2=first source
183 var source_name = $("div#mkwsFacetSources div.term:nth-child(" + source_number + ") a").text();
184 // do not click on wikipedia link - no author or subject facets possible
185 if (source_name.match(/wikipedia/i)) {
189 var click = $("div#mkwsFacetSources div.term:nth-child(" + source_number + ") a").trigger("click");
190 debug("limit source click " + (source_number - 1) + " is success: " + click.length);
191 expect(click.length).toBe(1);
193 waitsFor(function () {
194 if ($("div#mkwsNavi").length && $("div#mkwsNavi").text().match(/Source: /)) {
199 }, "Search for source in navi bar", 1000);
201 waitsFor(function () {
202 return get_hit_counter() < hits_all_targets ? true : false;
203 }, "Limited source earch for less than " + hits_all_targets + " hits", 9 * 1000);
206 var hits_single_target = get_hit_counter();
207 debug("get less hits for sources: " + hits_all_targets + " > " + hits_single_target);
208 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
213 describe("Show record", function () {
214 var record_number = 1; // the Nth record in hit list
215 it("show record author", function () {
216 var click = $("div#mkwsRecords div.record:nth-child(" + record_number + ") a").trigger("click");
217 debug("show record click is success: " + click.length);
218 expect(click.length).toBe(1);
220 // wait until the record pops up
221 waitsFor(function () {
222 var show = $("div#mkwsRecords div.record:nth-child(" + record_number + ") div");
223 return show != null && show.length ? true : false;
224 }, "wait some miliseconds to show up a record", 2 * 1000);
227 debug("show record pop up");
228 expect($("div#mkwsRecords div.record:nth-child(" + record_number + ") div")).not.toBe(null);
232 it("extract URL", function () {
233 var url = $("div#mkwsRecords div.record:nth-child(" + record_number + ") div table tbody tr td a").text();
234 debug("extracted URL from record: " + url);
236 expect(url).not.toBe(null);
237 expect(url).toMatch(/^http:\/\/[a-z0-9]+\.[0-9a-z].*\//i);
241 describe("Check switch menu Records/Targets", function () {
242 it("check mkwsSwitch", function () {
243 expect($("div#mkwsSwitch").length).toBe(1);
245 // expect 2 clickable links
246 expect($("div#mkwsSwitch a").length).toBe(2);
249 it("switch to target view", function () {
250 var click = $("a#mkwsSwitch_targets").trigger("click");
251 debug("target view click is success: " + click.length);
252 expect(click.length).toBe(1);
254 // now the target table must be visible
255 expect($("div#mkwsBytarget").is(":visible")).toBe(true);
256 expect($("div#mkwsRecords").is(":visible")).toBe(false);
258 // wait a half second, to show the target view
259 var time = (new Date).getTime();
260 waitsFor(function () {
261 return (new Date).getTime() - time > 700 ? true : false;
262 }, "wait some miliseconds", 1 * 1000);
264 // look for table header
266 expect($("div#mkwsBytarget").html()).toMatch(/Target ID/);
270 it("switch back to record view", function () {
271 var click = $("a#mkwsSwitch_records").trigger("click");
272 debug("record view click is success: " + click.length);
273 expect(click.length).toBe(1);
275 // now the target table must be visible
276 expect($("div#mkwsBytarget").is(":visible")).toBe(false);
277 expect($("div#mkwsRecords").is(":visible")).toBe(true);
281 describe("Check status client counter", function () {
282 function get_time() {
283 var date = new Date();
284 return date.getTime();
286 var time = get_time();
288 it("check status clients", function () {
289 waitsFor(function () {
290 var clients = $("div#mkwsStat span.clients");
291 if (clients.length == 1 && clients.text().match("0/1$")) {
297 }, "wait for Active clients: 0/1", 4 * 1000);
301 var clients = $("div#mkwsStat span.clients");
302 debug("span.clients: " + clients.text());
303 expect(clients.text()).toEqual("0/1");
312 describe("All tests are done", function () {
313 it(">>> hooray <<<", function () {});