1 /* Copyright (c) 2013 IndexData ApS. http://indexdata.com
3 * perform papzpar2 / pz2.js search & retrieve request in the browser
7 var debug_level = mkws.debug_level;
8 var debug = mkws.debug_function;
10 var get_hit_counter = function () {
12 if ($("#mkwsPager").length == 0) return -1;
14 var found = $("#mkwsPager").text();
15 var re = /\([A-Za-z]+:\s+([0-9]+)\)/;
20 hits = parseInt(RegExp.$1);
21 expect(hits).toBeGreaterThan(0);
24 //debug("Hits: " + hits);
28 describe("Check pazpar2 search", function () {
29 it("pazpar2 was successfully initialize", function () {
30 expect(mkws_config.error).toBe(undefined);
33 it("validate HTML id's", function () {
34 expect($("input#mkwsQuery").length).toBe(1);
35 expect($("input#mkwsButton").length).toBe(1);
37 expect($("#mkwsNext").length).not.toBe(1);
38 expect($("#mkwsPrev").length).not.toBe(1);
41 it("run search query", function () {
42 var search_query = "freebsd"; // short hit counter with some paging
43 $("input#mkwsQuery").val(search_query);
44 debug("set search query: " + search_query)
45 expect($("input#mkwsQuery").val()).toMatch("^" + search_query + "$");
47 // wait for service proxy auth
48 waitsFor(function () {
49 return mkws.authenticated;
50 }, "SP auth done", 10 * 1000);
53 debug("Click on submit button");
54 var click = $("input#mkwsButton").trigger("click");
55 expect(click.length).toBe(1);
62 * This part runs in background. It should be rewritten with
63 * async jasmine functions
66 describe("Check pazpar2 navigation", function () {
68 it("check running search next/prev", function () {
69 expect($("#mkwsPager").length).toBe(1);
71 function my_click(id, time) {
72 setTimeout(function () {
73 debug("trigger click on id: " + id);
74 var click = $(id).trigger("click");
76 debug("next/prev: " + id + " click is success: " + click.length);
77 expect(click.length).toBe(1);
81 waitsFor(function () {
82 return $("div#mkwsPager div:nth-child(2) a").length >= 2 ? true : false;
83 }, "Expect next link 2", 10 * 1000);
86 // click next/prev after N seconds
87 my_click("#mkwsNext", 0);
90 waitsFor(function () {
91 return $("div#mkwsPager div:nth-child(2) a").length >= 3 ? true : false;
92 }, "Expect next link 3", 5 * 1000);
95 // click next/prev after N seconds
96 my_click("#mkwsNext", 0);
97 my_click("#mkwsPrev", 0.2);
102 describe("Check pazpar2 hit counter", function () {
103 it("check running search hit counter", function () {
104 var max_time = 16; // in seconds
105 var expected_hits = 80; // at least expected hit counter
108 waitsFor(function () {
109 hits = get_hit_counter();
111 return hits > expected_hits;
112 }, "Expect " + expected_hits + " hits", max_time * 1000);
116 debug("mkws pager found records: '" + hits + "'");
117 expect($("#mkwsPager").length).toBe(1);
118 expect(hits).toBeGreaterThan(expected_hits);
123 describe("Check Termlist", function () {
124 it("found Termlist", function () {
125 var termlist = $("div#mkwsTermlists");
126 debug("Termlist success: " + termlist.length);
127 expect(termlist.length).toBe(1);
129 waitsFor(function () {
130 return $("div#mkwsFacetSources").length == 1 ? true : false;
131 }, "check for facet sources", 2 * 1000);
134 // everything displayed?
136 var sources = $("div#mkwsFacetSources");
137 debug("Termlist sources success: " + sources.length);
138 expect(sources.length).toBe(1);
140 var subjects = $("div#mkwsFacetSubjects");
141 expect(subjects.length).toBe(1);
143 var authors = $("div#mkwsFacetAuthors");
144 expect(authors.length).toBe(1);
147 waitsFor(function () {
148 return $("div#mkwsFacetAuthors div.term").length >= 2 ? true : false;
149 }, "At least one author link displayed", 2 * 1000);
152 expect($("div#mkwsFacetAuthors div.term").length).toBeGreaterThan(1);
156 it("limit search to first author", function () {
157 var hits_all_targets = get_hit_counter();
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).toBe(1);
163 waitsFor(function () {
164 return get_hit_counter() < hits_all_targets ? true : false;
165 }, "Limited author search for less than " + hits_all_targets + " hits", 8 * 1000);
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);
174 it("limit search to first source", function () {
175 var hits_all_targets = get_hit_counter();
176 var source_number = 2; // 2=first source
177 var source_name = $("div#mkwsFacetSources div.term:nth-child(" + source_number + ") a").text();
178 // do not click on wikipedia link - no author or subject facets possible
179 if (source_name.match(/wikipedia/i)) {
183 var click = $("div#mkwsFacetSources div.term:nth-child(" + source_number + ") a").trigger("click");
184 debug("limit source click " + (source_number - 1) + " is success: " + click.length);
185 expect(click.length).toBe(1);
187 waitsFor(function () {
188 if ($("div#mkwsNavi").length && $("div#mkwsNavi").text().match(/Source: /)) {
193 }, "Search for source in navi bar", 1000);
195 waitsFor(function () {
196 return get_hit_counter() < hits_all_targets ? true : false;
197 }, "Limited source earch for less than " + hits_all_targets + " hits", 9 * 1000);
200 var hits_single_target = get_hit_counter();
201 debug("get less hits for sources: " + hits_all_targets + " > " + hits_single_target);
202 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
207 describe("Show record", function () {
208 var record_number = 1; // the Nth record in hit list
209 it("show record author", function () {
210 var click = $("div#mkwsRecords div.record:nth-child(" + record_number + ") :nth-child(1)").trigger("click");
211 debug("show record click is success: " + click.length);
212 expect(click.length).toBe(1);
214 // wait until the record pops up
215 waitsFor(function () {
216 var show = $("div#mkwsRecords div.record:nth-child(" + record_number + ") div");
217 return show != null && show.length ? true : false;
218 }, "wait some miliseconds to show up a record", 2 * 1000);
221 debug("show record pop up");
222 expect($("div#mkwsRecords div.record:nth-child(" + record_number + ") div")).not.toBe(null);
226 it("extract URL", function () {
227 var url = $("div#mkwsRecords div.record:nth-child(" + record_number + ") div table tbody tr td a").text();
228 debug("extracted URL from record: " + url);
230 expect(url).not.toBe(null);
231 expect(url).toMatch(/^http:\/\/[a-z0-9]+\.[0-9a-z].*\//i);
235 describe("Check switch menu Records/Targets", function () {
236 it("check mkwsSwitch", function () {
237 expect($("div#mkwsSwitch").length).toBe(1);
239 // expect 2 clickable links
240 expect($("div#mkwsSwitch a").length).toBe(2);
243 it("switch to target view", function () {
244 var click = $("a#mkwsSwitch_targets").trigger("click");
245 debug("target click is success: " + click.length);
246 expect(click.length).toBe(1);
248 // now the target table must be visible
249 expect($("div#mkwsBytarget").is(":visible")).toBe(true);
250 expect($("div#mkwsRecords").is(":visible")).toBe(false);
252 // wait a half second, to show the target view
253 var time = (new Date).getTime();
254 waitsFor(function () {
255 return (new Date).getTime() - time > 700 ? true : false;
256 }, "wait some miliseconds", 1 * 1000);
258 // look for table header
260 expect($("div#mkwsBytarget").html()).toMatch(/Target ID/);
264 it("switch back to record view", function () {
265 var click = $("a#mkwsSwitch_records").trigger("click");
266 debug("record view click is success: " + click.length);
267 expect(click.length).toBe(1);
269 // now the target table must be visible
270 expect($("div#mkwsBytarget").is(":visible")).toBe(false);
271 expect($("div#mkwsRecords").is(":visible")).toBe(true);
275 describe("Check status client counter", function () {
276 function get_time() {
277 var date = new Date();
278 return date.getTime();
280 var time = get_time();
282 it("check status clients", function () {
283 waitsFor(function () {
284 var clients = $("div#mkwsStat span.clients");
285 if (clients.length == 1 && clients.text() == "0/1") {
291 }, "wait for status", 4 * 1000);
294 var clients = $("div#mkwsStat span.clients");
295 debug("span.clients: " + clients.text());
296 expect(clients.text()).toEqual("0/1");
304 describe("All tests are done", function () {
305 it(">>> hooray <<<", function () {});