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 () {
10 if ($("#mkwsPager").length == 0) return -1;
12 var found = $("#mkwsPager").text();
13 var re = /\([A-Za-z]+:\s+([0-9]+)\)/;
18 hits = parseInt(RegExp.$1);
19 expect(hits).toBeGreaterThan(0);
22 //debug("Hits: " + hits);
26 describe("Check pazpar2 search", function () {
27 it("pazpar2 was successfully initialize", function () {
28 expect(mkws_config.error).toBe(undefined);
31 it("validate HTML id's", function () {
32 expect($("input#mkwsQuery").length == 1).toBe(true);
33 expect($("input#mkwsButton").length == 1).toBe(true);
35 expect($("#mkwsNext").length == 1).toBe(false);
36 expect($("#mkwsPrev").length == 1).toBe(false);
39 it("run search query", function () {
40 var search_query = "freebsd"; // short hit counter with some paging
41 $("input#mkwsQuery").val(search_query);
42 debug("set search query: " + search_query)
43 expect($("input#mkwsQuery").val()).toMatch("^" + search_query + "$");
45 // wait for service proxy auth
46 waitsFor(function () {
47 return mkws.service_proxy_auth;
48 }, "SP auth done", 10 * 1000);
51 debug("Click on submit button");
52 var click = $("input#mkwsButton").trigger("click");
53 expect(click.length == 1).toBe(true);
59 describe("Check pazpar2 navigation", function () {
61 it("check running search next/prev", function () {
62 expect($("#mkwsPager").length == 1).toBe(true);
64 function my_click(id, time) {
65 setTimeout(function () {
66 debug("trigger click on id: " + id);
67 var click = $(id).trigger("click");
69 debug("next click is success: " + click.length);
70 expect(click.length == 1).toBe(true);
74 waitsFor(function () {
75 return $("div#mkwsPager div:nth-child(2) a").length >= 2 ? true : false;
76 }, "Expect next link 2", 5 * 1000);
79 // click next/prev after N seconds
80 my_click("#mkwsNext", 0);
83 waitsFor(function () {
84 return $("div#mkwsPager div:nth-child(2) a").length >= 3 ? true : false;
85 }, "Expect next link 3", 5 * 1000);
88 // click next/prev after N seconds
89 my_click("#mkwsNext", 0);
90 my_click("#mkwsPrev", 0.2);
95 describe("Check pazpar2 hit counter", function () {
96 it("check running search hit counter", function () {
97 var max_time = 10; // in seconds
98 var expected_hits = 116; // at least expected hit counter
101 waitsFor(function () {
102 hits = get_hit_counter();
104 return hits >= expected_hits;
105 }, "Expect N hits in x seconds", max_time * 1000);
109 debug("mkws pager found records: '" + hits + "'");
110 expect($("#mkwsPager").length == 1).toBe(true);
111 expect(hits).toBeGreaterThan(expected_hits);
116 describe("Check Termlist", function () {
117 function show_record() {
118 var click = $("div#mkwsRecords div.record:nth-child(3) :nth-child(2)").trigger("click");
119 debug("show click is success: " + click.length);
120 expect(click.length == 1).toBe(true);
124 it("found Termlist", function () {
125 var termlist = $("div#mkwsTermlists");
126 debug("Termlist success: " + termlist.length);
127 expect(termlist.length == 1).toBe(true);
129 var sources = $("div#mkwsFacetSources");
130 expect(sources.length == 1).toBe(true);
132 var subjects = $("div#mkwsFacetSubjects");
133 expect(subjects.length == 1).toBe(true);
135 var authors = $("div#mkwsFacetAuthors");
136 expect(authors.length == 1).toBe(true);
139 it("limit search to first source", function () {
140 var hits_all_targets = get_hit_counter();
142 var click = $("div#mkwsFacetSources div.term:nth-child(2) a").trigger("click");
143 debug("limit source click is success: " + click.length);
144 expect(click.length == 1).toBe(true);
146 waitsFor(function () {
147 if ($("div#mkwsNavi").length && $("div#mkwsNavi").text().match(/^Source/)) {
152 }, "Search for source in navi bar", 1000);
154 waitsFor(function () {
155 return get_hit_counter() < hits_all_targets ? true : false;
156 }, "Search for with less hits", 9 * 1000);
159 var hits_single_target = get_hit_counter();
160 debug("get less hits for sources: " + hits_all_targets + " > " + hits_single_target);
161 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
165 it("limit search to first author", function () {
166 var hits_all_targets = get_hit_counter();
168 var click = $("div#mkwsFacetAuthors div.term:nth-child(2) a").trigger("click");
169 debug("limit author click is success: " + click.length);
170 expect(click.length == 1).toBe(true);
172 waitsFor(function () {
173 return get_hit_counter() < hits_all_targets ? true : false;
174 }, "Search for with less hits", 9 * 1000);
177 var hits_single_target = get_hit_counter();
178 debug("get less hits for authors: " + hits_all_targets + " > " + hits_single_target);
179 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
183 it("show record author", function () {
188 describe("Check status client counter", function () {
189 function get_time() {
190 var date = new Date();
191 return date.getTime();
193 var time = get_time();
195 it("check status clients", function () {
197 waitsFor(function () {
198 var clients = $("div#mkwsStat span.clients");
199 if (clients.length == 1 && clients.text() == "0/1") {
205 }, "wait for status", 4 * 1000);
209 var clients = $("div#mkwsStat span.clients");
210 debug("span.clients: " + clients.text());
211 expect(clients.text()).toEqual("0/1");
216 describe("Check switch menu Records/Targets", function () {
217 it("check mkwsSwitch", function () {
218 expect($("div#mkwsSwitch").length).toBe(1);
220 // expect 2 clickable links
221 expect($("div#mkwsSwitch a").length).toBe(2);
224 it("switch to target view", function () {
225 var click = $("a#mkwsSwitch_targets").trigger("click");
226 debug("target click is success: " + click.length);
227 expect(click.length == 1).toBe(true);
229 // now the target table must be visible
230 expect($("div#mkwsBytarget").is(":visible")).toBe(true);
231 expect($("div#mkwsResults").is(":visible")).toBe(false);
233 // wait a half second, to show the target view
234 var time = (new Date).getTime();
235 waitsFor(function () {
236 return (new Date).getTime() - time > 700 ? true : false;
237 }, "wait some miliseconds", 1 * 1000);
238 // look for table header
240 expect($("div#mkwsBytarget").html()).toMatch(/Target ID/);
244 it("switch back to record view", function () {
245 var click = $("a#mkwsSwitch_records").trigger("click");
246 debug("record click is success: " + click.length);
247 expect(click.length == 1).toBe(true);
249 // now the target table must be visible
250 expect($("div#mkwsBytarget").is(":visible")).toBe(false);
251 expect($("div#mkwsResults").is(":visible")).toBe(true);
256 describe("All tests are done", function () {
257 it(">>> hooray <<<", function () {});