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 // wait for service proxy auth
50 waitsFor(function () {
51 return mkws.authenticated;
52 }, "SP auth done", 10 * 1000);
55 debug("Click on submit button");
56 var click = $("input#mkwsButton").trigger("click");
57 expect(click.length).toBe(1);
64 * This part runs in background. It should be rewritten with
65 * async jasmine functions
68 describe("Check pazpar2 navigation", function () {
70 it("check running search next/prev", function () {
71 expect($("#mkwsPager").length).toBe(1);
73 function my_click(id, time) {
74 setTimeout(function () {
75 debug("trigger click on id: " + id);
76 var click = $(id).trigger("click");
78 debug("next/prev: " + id + " click is success: " + click.length);
79 expect(click.length).toBe(1);
83 waitsFor(function () {
84 return $("div#mkwsPager div:nth-child(2) a").length >= 2 ? true : false;
85 }, "Expect next link 2", 10 * 1000);
88 // click next/prev after N seconds
89 my_click("#mkwsNext", 0);
92 waitsFor(function () {
93 return $("div#mkwsPager div:nth-child(2) a").length >= 3 ? true : false;
94 }, "Expect next link 3", 5 * 1000);
97 // click next/prev after N seconds
98 my_click("#mkwsNext", 0);
99 my_click("#mkwsPrev", 0.2);
104 describe("Check pazpar2 hit counter", function () {
105 it("check running search hit counter", function () {
106 var max_time = 16; // in seconds
107 var expected_hits = 80; // at least expected hit counter
110 waitsFor(function () {
111 hits = get_hit_counter();
113 return hits > expected_hits;
114 }, "Expect " + expected_hits + " hits", max_time * 1000);
118 debug("mkws pager found records: '" + hits + "'");
119 expect($("#mkwsPager").length).toBe(1);
120 expect(hits).toBeGreaterThan(expected_hits);
125 describe("Check Termlist", function () {
126 it("found Termlist", function () {
127 var termlist = $("div#mkwsTermlists");
128 debug("Termlist success: " + termlist.length);
129 expect(termlist.length).toBe(1);
131 waitsFor(function () {
132 return $("div#mkwsFacetSources").length == 1 ? true : false;
133 }, "check for facet sources", 2 * 1000);
136 // everything displayed?
138 var sources = $("div#mkwsFacetSources");
139 debug("Termlist sources success: " + sources.length);
140 expect(sources.length).toBe(1);
142 var subjects = $("div#mkwsFacetSubjects");
143 expect(subjects.length).toBe(1);
145 var authors = $("div#mkwsFacetAuthors");
146 expect(authors.length).toBe(1);
149 waitsFor(function () {
150 return $("div#mkwsFacetAuthors div.term").length >= 2 ? true : false;
151 }, "At least one author link displayed", 2 * 1000);
154 expect($("div#mkwsFacetAuthors div.term").length).toBeGreaterThan(1);
158 it("limit search to first author", function () {
159 var hits_all_targets = get_hit_counter();
161 var click = $("div#mkwsFacetAuthors div.term:nth-child(2) a").trigger("click");
162 debug("limit author click is success: " + click.length);
163 expect(click.length).toBe(1);
165 waitsFor(function () {
166 return get_hit_counter() < hits_all_targets ? true : false;
167 }, "Limited author search for less than " + hits_all_targets + " hits", 8 * 1000);
170 var hits_single_target = get_hit_counter();
171 debug("get less hits for authors: " + hits_all_targets + " > " + hits_single_target);
172 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
176 it("limit search to first source", function () {
177 var hits_all_targets = get_hit_counter();
178 var source_number = 2; // 2=first source
179 var source_name = $("div#mkwsFacetSources div.term:nth-child(" + source_number + ") a").text();
180 // do not click on wikipedia link - no author or subject facets possible
181 if (source_name.match(/wikipedia/i)) {
185 var click = $("div#mkwsFacetSources div.term:nth-child(" + source_number + ") a").trigger("click");
186 debug("limit source click " + (source_number - 1) + " is success: " + click.length);
187 expect(click.length).toBe(1);
189 waitsFor(function () {
190 if ($("div#mkwsNavi").length && $("div#mkwsNavi").text().match(/Source: /)) {
195 }, "Search for source in navi bar", 1000);
197 waitsFor(function () {
198 return get_hit_counter() < hits_all_targets ? true : false;
199 }, "Limited source earch for less than " + hits_all_targets + " hits", 9 * 1000);
202 var hits_single_target = get_hit_counter();
203 debug("get less hits for sources: " + hits_all_targets + " > " + hits_single_target);
204 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
209 describe("Show record", function () {
210 var record_number = 1; // the Nth record in hit list
211 it("show record author", function () {
212 var click = $("div#mkwsRecords div.record:nth-child(" + record_number + ") a").trigger("click");
213 debug("show record click is success: " + click.length);
214 expect(click.length).toBe(1);
216 // wait until the record pops up
217 waitsFor(function () {
218 var show = $("div#mkwsRecords div.record:nth-child(" + record_number + ") div");
219 return show != null && show.length ? true : false;
220 }, "wait some miliseconds to show up a record", 2 * 1000);
223 debug("show record pop up");
224 expect($("div#mkwsRecords div.record:nth-child(" + record_number + ") div")).not.toBe(null);
228 it("extract URL", function () {
229 var url = $("div#mkwsRecords div.record:nth-child(" + record_number + ") div table tbody tr td a").text();
230 debug("extracted URL from record: " + url);
232 expect(url).not.toBe(null);
233 expect(url).toMatch(/^http:\/\/[a-z0-9]+\.[0-9a-z].*\//i);
237 describe("Check switch menu Records/Targets", function () {
238 it("check mkwsSwitch", function () {
239 expect($("div#mkwsSwitch").length).toBe(1);
241 // expect 2 clickable links
242 expect($("div#mkwsSwitch a").length).toBe(2);
245 it("switch to target view", function () {
246 var click = $("a#mkwsSwitch_targets").trigger("click");
247 debug("target view click is success: " + click.length);
248 expect(click.length).toBe(1);
250 // now the target table must be visible
251 expect($("div#mkwsBytarget").is(":visible")).toBe(true);
252 expect($("div#mkwsRecords").is(":visible")).toBe(false);
254 // wait a half second, to show the target view
255 var time = (new Date).getTime();
256 waitsFor(function () {
257 return (new Date).getTime() - time > 700 ? true : false;
258 }, "wait some miliseconds", 1 * 1000);
260 // look for table header
262 expect($("div#mkwsBytarget").html()).toMatch(/Target ID/);
266 it("switch back to record view", function () {
267 var click = $("a#mkwsSwitch_records").trigger("click");
268 debug("record view click is success: " + click.length);
269 expect(click.length).toBe(1);
271 // now the target table must be visible
272 expect($("div#mkwsBytarget").is(":visible")).toBe(false);
273 expect($("div#mkwsRecords").is(":visible")).toBe(true);
277 describe("Check status client counter", function () {
278 function get_time() {
279 var date = new Date();
280 return date.getTime();
282 var time = get_time();
284 it("check status clients", function () {
285 waitsFor(function () {
286 var clients = $("div#mkwsStat span.clients");
287 if (clients.length == 1 && clients.text().match("0/1$")) {
293 }, "wait for Active clients: 0/1", 4 * 1000);
297 var clients = $("div#mkwsStat span.clients");
298 debug("span.clients: " + clients.text());
299 expect(clients.text()).toEqual("0/1");
308 describe("All tests are done", function () {
309 it(">>> hooray <<<", function () {});