1 /* Copyright (c) 2013 IndexData ApS. http://indexdata.com
3 * perform papzpar2 / pz2.js search & retrieve request in the browser
7 var debug = mkws.debug;
9 var get_hit_counter = function () {
11 if ($("#mkwsPager").length == 0) return -1;
13 var found = $("#mkwsPager").text();
14 var re = /\([A-Za-z]+:\s+([0-9]+)\)/;
19 hits = parseInt(RegExp.$1);
20 expect(hits).toBeGreaterThan(0);
23 //debug("Hits: " + hits);
27 describe("Check pazpar2 search", function () {
28 it("pazpar2 was successfully initialize", function () {
29 expect(mkws_config.error).toBe(undefined);
32 it("validate HTML id's", function () {
33 expect($("input#mkwsQuery").length).toBe(1);
34 expect($("input#mkwsButton").length).toBe(1);
36 expect($("#mkwsNext").length).not.toBe(1);
37 expect($("#mkwsPrev").length).not.toBe(1);
40 it("run search query", function () {
41 var search_query = "freebsd"; // short hit counter with some paging
42 $("input#mkwsQuery").val(search_query);
43 debug("set search query: " + search_query)
44 expect($("input#mkwsQuery").val()).toMatch("^" + search_query + "$");
46 // wait for service proxy auth
47 waitsFor(function () {
48 return mkws.service_proxy_auth;
49 }, "SP auth done", 10 * 1000);
52 debug("Click on submit button");
53 var click = $("input#mkwsButton").trigger("click");
54 expect(click.length).toBe(1);
60 describe("Check pazpar2 navigation", function () {
62 it("check running search next/prev", function () {
63 expect($("#mkwsPager").length).toBe(1);
65 function my_click(id, time) {
66 setTimeout(function () {
67 debug("trigger click on id: " + id);
68 var click = $(id).trigger("click");
70 debug("next click is success: " + click.length);
71 expect(click.length).toBe(1);
75 waitsFor(function () {
76 return $("div#mkwsPager div:nth-child(2) a").length >= 2 ? true : false;
77 }, "Expect next link 2", 10 * 1000);
80 // click next/prev after N seconds
81 my_click("#mkwsNext", 0);
84 waitsFor(function () {
85 return $("div#mkwsPager div:nth-child(2) a").length >= 3 ? true : false;
86 }, "Expect next link 3", 5 * 1000);
89 // click next/prev after N seconds
90 my_click("#mkwsNext", 0);
91 my_click("#mkwsPrev", 0.2);
96 describe("Check pazpar2 hit counter", function () {
97 it("check running search hit counter", function () {
98 var max_time = 16; // in seconds
99 var expected_hits = 80; // at least expected hit counter
102 waitsFor(function () {
103 hits = get_hit_counter();
105 return hits > expected_hits;
106 }, "Expect " + expected_hits + " hits", max_time * 1000);
110 debug("mkws pager found records: '" + hits + "'");
111 expect($("#mkwsPager").length).toBe(1);
112 expect(hits).toBeGreaterThan(expected_hits);
117 describe("Check Termlist", function () {
118 it("found Termlist", function () {
119 var termlist = $("div#mkwsTermlists");
120 debug("Termlist success: " + termlist.length);
121 expect(termlist.length).toBe(1);
123 waitsFor(function () {
124 return $("div#mkwsFacetSources").length == 1 ? true : false;
125 }, "check for facet sources", 2 * 1000);
128 // everything displayed?
130 var sources = $("div#mkwsFacetSources");
131 debug("Termlist sources success: " + sources.length);
132 expect(sources.length).toBe(1);
134 var subjects = $("div#mkwsFacetSubjects");
135 expect(subjects.length).toBe(1);
137 var authors = $("div#mkwsFacetAuthors");
138 expect(authors.length).toBe(1);
141 waitsFor(function () {
142 return $("div#mkwsFacetAuthors div.term").length >= 2 ? true : false;
143 }, "At least one author link displayed", 2 * 1000);
146 expect($("div#mkwsFacetAuthors div.term").length).toBeGreaterThan(1);
150 it("limit search to first author", function () {
151 var hits_all_targets = get_hit_counter();
153 var click = $("div#mkwsFacetAuthors div.term:nth-child(2) a").trigger("click");
154 debug("limit author click is success: " + click.length);
155 expect(click.length).toBe(1);
157 waitsFor(function () {
158 return get_hit_counter() < hits_all_targets ? true : false;
159 }, "Limited author search for less than " + hits_all_targets + " hits", 8 * 1000);
162 var hits_single_target = get_hit_counter();
163 debug("get less hits for authors: " + hits_all_targets + " > " + hits_single_target);
164 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
168 it("limit search to first source", function () {
169 var hits_all_targets = get_hit_counter();
170 var source_number = 2; // 2=first source
171 var source_name = $("div#mkwsFacetSources div.term:nth-child(" + source_number + ") a").text();
172 // do not click on wikipedia link - no author or subject facets possible
173 if (source_name.match(/wikipedia/i)) {
177 var click = $("div#mkwsFacetSources div.term:nth-child(" + source_number + ") a").trigger("click");
178 debug("limit source click " + (source_number - 1) + " is success: " + click.length);
179 expect(click.length).toBe(1);
181 waitsFor(function () {
182 if ($("div#mkwsNavi").length && $("div#mkwsNavi").text().match(/^Source/)) {
187 }, "Search for source in navi bar", 1000);
189 waitsFor(function () {
190 return get_hit_counter() < hits_all_targets ? true : false;
191 }, "Limited source earch for less than " + hits_all_targets + " hits", 9 * 1000);
194 var hits_single_target = get_hit_counter();
195 debug("get less hits for sources: " + hits_all_targets + " > " + hits_single_target);
196 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
201 describe("Show record", function () {
202 var record_number = 1; // the Nth record in hit list
203 it("show record author", function () {
204 var click = $("div#mkwsRecords div.record:nth-child(" + record_number + ") :nth-child(2)").trigger("click");
205 debug("show click is success: " + click.length);
206 expect(click.length).toBe(1);
208 // wait until the record pops up
209 waitsFor(function () {
210 var show = $("div#mkwsRecords div.record:nth-child(" + record_number + ") div");
211 return show != null && show.length ? true : false;
212 }, "wait some miliseconds to show up a record", 2 * 1000);
215 debug("show record pop up");
216 expect($("div#mkwsRecords div.record:nth-child(" + record_number + ") div")).not.toBe(null);
220 it("extract URL", function () {
221 var url = $("div#mkwsRecords div.record:nth-child(" + record_number + ") div table tbody tr td a").text();
222 debug("extracted URL from record: " + url);
224 expect(url).not.toBe(null);
225 expect(url).toMatch(/^http:\/\/[a-z0-9]+\.[0-9a-z].*\//i);
229 describe("Check switch menu Records/Targets", function () {
230 it("check mkwsSwitch", function () {
231 expect($("div#mkwsSwitch").length).toBe(1);
233 // expect 2 clickable links
234 expect($("div#mkwsSwitch a").length).toBe(2);
237 it("switch to target view", function () {
238 var click = $("a#mkwsSwitch_targets").trigger("click");
239 debug("target click is success: " + click.length);
240 expect(click.length).toBe(1);
242 // now the target table must be visible
243 expect($("div#mkwsBytarget").is(":visible")).toBe(true);
244 expect($("div#mkwsRecords").is(":visible")).toBe(false);
246 // wait a half second, to show the target view
247 var time = (new Date).getTime();
248 waitsFor(function () {
249 return (new Date).getTime() - time > 700 ? true : false;
250 }, "wait some miliseconds", 1 * 1000);
252 // look for table header
254 expect($("div#mkwsBytarget").html()).toMatch(/Target ID/);
258 it("switch back to record view", function () {
259 var click = $("a#mkwsSwitch_records").trigger("click");
260 debug("record click is success: " + click.length);
261 expect(click.length).toBe(1);
263 // now the target table must be visible
264 expect($("div#mkwsBytarget").is(":visible")).toBe(false);
265 expect($("div#mkwsRecords").is(":visible")).toBe(true);
269 describe("Check status client counter", function () {
270 function get_time() {
271 var date = new Date();
272 return date.getTime();
274 var time = get_time();
276 it("check status clients", function () {
277 waitsFor(function () {
278 var clients = $("div#mkwsStat span.clients");
279 if (clients.length == 1 && clients.text() == "0/1") {
285 }, "wait for status", 4 * 1000);
288 var clients = $("div#mkwsStat span.clients");
289 debug("span.clients: " + clients.text());
290 expect(clients.text()).toEqual("0/1");
298 describe("All tests are done", function () {
299 it(">>> hooray <<<", function () {});