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)
15 var found = $("#mkwsPager").text();
16 var re = /\([A-Za-z]+:\s+([0-9]+)\)/;
21 hits = parseInt(RegExp.$1);
22 expect(hits).toBeGreaterThan(0);
25 //debug("Hits: " + hits);
29 describe("Check pazpar2 search", function () {
30 it("pazpar2 was successfully initialize", function () {
31 expect(mkws_config.error).toBe(undefined);
34 it("validate HTML id's", function () {
35 expect($("input#mkwsQuery").length).toBe(1);
36 expect($("input#mkwsButton").length).toBe(1);
38 expect($("#mkwsNext").length).not.toBe(1);
39 expect($("#mkwsPrev").length).not.toBe(1);
42 it("run search query", function () {
43 var search_query = "freebsd"; // short hit counter with some paging
44 $("input#mkwsQuery").val(search_query);
45 debug("set search query: " + search_query)
46 expect($("input#mkwsQuery").val()).toMatch("^" + search_query + "$");
48 // wait for service proxy auth
49 waitsFor(function () {
50 return mkws.authenticated;
51 }, "SP auth done", 10 * 1000);
54 debug("Click on submit button");
55 var click = $("input#mkwsButton").trigger("click");
56 expect(click.length).toBe(1);
63 * This part runs in background. It should be rewritten with
64 * async jasmine functions
67 describe("Check pazpar2 navigation", function () {
69 it("check running search next/prev", function () {
70 expect($("#mkwsPager").length).toBe(1);
72 function my_click(id, time) {
73 setTimeout(function () {
74 debug("trigger click on id: " + id);
75 var click = $(id).trigger("click");
77 debug("next/prev: " + id + " click is success: " + click.length);
78 expect(click.length).toBe(1);
82 waitsFor(function () {
83 return $("div#mkwsPager div:nth-child(2) a").length >= 2 ? true : false;
84 }, "Expect next link 2", 10 * 1000);
87 // click next/prev after N seconds
88 my_click("#mkwsNext", 0);
91 waitsFor(function () {
92 return $("div#mkwsPager div:nth-child(2) a").length >= 3 ? true : false;
93 }, "Expect next link 3", 5 * 1000);
96 // click next/prev after N seconds
97 my_click("#mkwsNext", 0);
98 my_click("#mkwsPrev", 0.2);
103 describe("Check pazpar2 hit counter", function () {
104 it("check running search hit counter", function () {
105 var max_time = 16; // in seconds
106 var expected_hits = 80; // at least expected hit counter
109 waitsFor(function () {
110 hits = get_hit_counter();
112 return hits > expected_hits;
113 }, "Expect " + expected_hits + " hits", max_time * 1000);
117 debug("mkws pager found records: '" + hits + "'");
118 expect($("#mkwsPager").length).toBe(1);
119 expect(hits).toBeGreaterThan(expected_hits);
124 describe("Check Termlist", function () {
125 it("found Termlist", function () {
126 var termlist = $("div#mkwsTermlists");
127 debug("Termlist success: " + termlist.length);
128 expect(termlist.length).toBe(1);
130 waitsFor(function () {
131 return $("div#mkwsFacetSources").length == 1 ? true : false;
132 }, "check for facet sources", 2 * 1000);
135 // everything displayed?
137 var sources = $("div#mkwsFacetSources");
138 debug("Termlist sources success: " + sources.length);
139 expect(sources.length).toBe(1);
141 var subjects = $("div#mkwsFacetSubjects");
142 expect(subjects.length).toBe(1);
144 var authors = $("div#mkwsFacetAuthors");
145 expect(authors.length).toBe(1);
148 waitsFor(function () {
149 return $("div#mkwsFacetAuthors div.term").length >= 2 ? true : false;
150 }, "At least one author link displayed", 2 * 1000);
153 expect($("div#mkwsFacetAuthors div.term").length).toBeGreaterThan(1);
157 it("limit search to first author", function () {
158 var hits_all_targets = get_hit_counter();
160 var click = $("div#mkwsFacetAuthors div.term:nth-child(2) a").trigger("click");
161 debug("limit author click is success: " + click.length);
162 expect(click.length).toBe(1);
164 waitsFor(function () {
165 return get_hit_counter() < hits_all_targets ? true : false;
166 }, "Limited author search for less than " + hits_all_targets + " hits", 8 * 1000);
169 var hits_single_target = get_hit_counter();
170 debug("get less hits for authors: " + hits_all_targets + " > " + hits_single_target);
171 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
175 it("limit search to first source", function () {
176 var hits_all_targets = get_hit_counter();
177 var source_number = 2; // 2=first source
178 var source_name = $("div#mkwsFacetSources div.term:nth-child(" + source_number + ") a").text();
179 // do not click on wikipedia link - no author or subject facets possible
180 if (source_name.match(/wikipedia/i)) {
184 var click = $("div#mkwsFacetSources div.term:nth-child(" + source_number + ") a").trigger("click");
185 debug("limit source click " + (source_number - 1) + " is success: " + click.length);
186 expect(click.length).toBe(1);
188 waitsFor(function () {
189 if ($("div#mkwsNavi").length && $("div#mkwsNavi").text().match(/Source: /)) {
194 }, "Search for source in navi bar", 1000);
196 waitsFor(function () {
197 return get_hit_counter() < hits_all_targets ? true : false;
198 }, "Limited source earch for less than " + hits_all_targets + " hits", 9 * 1000);
201 var hits_single_target = get_hit_counter();
202 debug("get less hits for sources: " + hits_all_targets + " > " + hits_single_target);
203 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
208 describe("Show record", function () {
209 var record_number = 1; // the Nth record in hit list
210 it("show record author", function () {
211 var click = $("div#mkwsRecords div.record:nth-child(" + record_number + ") a").trigger("click");
212 debug("show record click is success: " + click.length);
213 expect(click.length).toBe(1);
215 // wait until the record pops up
216 waitsFor(function () {
217 var show = $("div#mkwsRecords div.record:nth-child(" + record_number + ") div");
218 return show != null && show.length ? true : false;
219 }, "wait some miliseconds to show up a record", 2 * 1000);
222 debug("show record pop up");
223 expect($("div#mkwsRecords div.record:nth-child(" + record_number + ") div")).not.toBe(null);
227 it("extract URL", function () {
228 var url = $("div#mkwsRecords div.record:nth-child(" + record_number + ") div table tbody tr td a").text();
229 debug("extracted URL from record: " + url);
231 expect(url).not.toBe(null);
232 expect(url).toMatch(/^http:\/\/[a-z0-9]+\.[0-9a-z].*\//i);
236 describe("Check switch menu Records/Targets", function () {
237 it("check mkwsSwitch", function () {
238 expect($("div#mkwsSwitch").length).toBe(1);
240 // expect 2 clickable links
241 expect($("div#mkwsSwitch a").length).toBe(2);
244 it("switch to target view", function () {
245 var click = $("a#mkwsSwitch_targets").trigger("click");
246 debug("target view click is success: " + click.length);
247 expect(click.length).toBe(1);
249 // now the target table must be visible
250 expect($("div#mkwsBytarget").is(":visible")).toBe(true);
251 expect($("div#mkwsRecords").is(":visible")).toBe(false);
253 // wait a half second, to show the target view
254 var time = (new Date).getTime();
255 waitsFor(function () {
256 return (new Date).getTime() - time > 700 ? true : false;
257 }, "wait some miliseconds", 1 * 1000);
259 // look for table header
261 expect($("div#mkwsBytarget").html()).toMatch(/Target ID/);
265 it("switch back to record view", function () {
266 var click = $("a#mkwsSwitch_records").trigger("click");
267 debug("record view click is success: " + click.length);
268 expect(click.length).toBe(1);
270 // now the target table must be visible
271 expect($("div#mkwsBytarget").is(":visible")).toBe(false);
272 expect($("div#mkwsRecords").is(":visible")).toBe(true);
276 describe("Check status client counter", function () {
277 function get_time() {
278 var date = new Date();
279 return date.getTime();
281 var time = get_time();
283 it("check status clients", function () {
284 waitsFor(function () {
285 var clients = $("div#mkwsStat span.clients");
286 if (clients.length == 1 && clients.text().match("0/1$")) {
292 }, "wait for Active clients: 0/1", 4 * 1000);
296 var clients = $("div#mkwsStat span.clients");
297 debug("span.clients: " + clients.text());
298 expect(clients.text()).toEqual("0/1");
307 describe("All tests are done", function () {
308 it(">>> hooray <<<", function () {});