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", 10 * 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 = 16; // in seconds
98 var expected_hits = 80; // at least expected hit counter
101 waitsFor(function () {
102 hits = get_hit_counter();
104 return hits > expected_hits;
105 }, "Expect " + expected_hits + " hits", 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 it("found Termlist", function () {
118 var termlist = $("div#mkwsTermlists");
119 debug("Termlist success: " + termlist.length);
120 expect(termlist.length == 1).toBe(true);
122 var sources = $("div#mkwsFacetSources");
123 expect(sources.length == 1).toBe(true);
125 var subjects = $("div#mkwsFacetSubjects");
126 expect(subjects.length == 1).toBe(true);
128 var authors = $("div#mkwsFacetAuthors");
129 expect(authors.length == 1).toBe(true);
132 it("limit search to first author", function () {
133 var hits_all_targets = get_hit_counter();
135 var click = $("div#mkwsFacetAuthors div.term:nth-child(2) a").trigger("click");
136 debug("limit author click is success: " + click.length);
137 expect(click.length == 1).toBe(true);
139 waitsFor(function () {
140 return get_hit_counter() < hits_all_targets ? true : false;
141 }, "Search for with less hits", 9 * 1000);
144 var hits_single_target = get_hit_counter();
145 debug("get less hits for authors: " + hits_all_targets + " > " + hits_single_target);
146 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
150 it("limit search to first source", function () {
151 var hits_all_targets = get_hit_counter();
153 var click = $("div#mkwsFacetSources div.term:nth-child(2) a").trigger("click");
154 debug("limit source click is success: " + click.length);
155 expect(click.length == 1).toBe(true);
157 waitsFor(function () {
158 if ($("div#mkwsNavi").length && $("div#mkwsNavi").text().match(/^Source/)) {
163 }, "Search for source in navi bar", 1000);
165 waitsFor(function () {
166 return get_hit_counter() < hits_all_targets ? true : false;
167 }, "Search for with less hits", 9 * 1000);
170 var hits_single_target = get_hit_counter();
171 debug("get less hits for sources: " + hits_all_targets + " > " + hits_single_target);
172 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
177 describe("Show record", function () {
178 var record_number = 2; // the Nth record in hit list
179 it("show record author", function () {
180 var click = $("div#mkwsRecords div.record:nth-child(" + record_number + ") :nth-child(2)").trigger("click");
181 debug("show click is success: " + click.length);
182 expect(click.length).toBe(1);
184 // wait until the record pops up
185 waitsFor(function () {
186 var show = $("div#mkwsRecords div.record:nth-child(" + record_number + ") div");
187 return show != null && show.length ? true : false;
188 }, "wait some miliseconds", 2 * 1000);
191 debug("show record pop up");
192 expect($("div#mkwsRecords div.record:nth-child(" + record_number + ") div")).not.toBe(null);
196 it("extract URL", function () {
197 var url = $("div#mkwsRecords div.record:nth-child(" + record_number + ") div table tbody tr td a").text();
198 debug("extracted URL from record: " + url);
200 expect(url).not.toBe(null);
201 expect(url).toMatch(/^http:\/\/[a-z0-9]+\.[0-9a-z].*\//i);
205 describe("Check switch menu Records/Targets", function () {
206 it("check mkwsSwitch", function () {
207 expect($("div#mkwsSwitch").length).toBe(1);
209 // expect 2 clickable links
210 expect($("div#mkwsSwitch a").length).toBe(2);
213 it("switch to target view", function () {
214 var click = $("a#mkwsSwitch_targets").trigger("click");
215 debug("target click is success: " + click.length);
216 expect(click.length == 1).toBe(true);
218 // now the target table must be visible
219 expect($("div#mkwsBytarget").is(":visible")).toBe(true);
220 expect($("div#mkwsRecords").is(":visible")).toBe(false);
222 // wait a half second, to show the target view
223 var time = (new Date).getTime();
224 waitsFor(function () {
225 return (new Date).getTime() - time > 700 ? true : false;
226 }, "wait some miliseconds", 1 * 1000);
227 // look for table header
229 expect($("div#mkwsBytarget").html()).toMatch(/Target ID/);
233 it("switch back to record view", function () {
234 var click = $("a#mkwsSwitch_records").trigger("click");
235 debug("record click is success: " + click.length);
236 expect(click.length == 1).toBe(true);
238 // now the target table must be visible
239 expect($("div#mkwsBytarget").is(":visible")).toBe(false);
240 expect($("div#mkwsRecords").is(":visible")).toBe(true);
244 describe("Check status client counter", function () {
245 function get_time() {
246 var date = new Date();
247 return date.getTime();
249 var time = get_time();
251 it("check status clients", function () {
253 waitsFor(function () {
254 var clients = $("div#mkwsStat span.clients");
255 if (clients.length == 1 && clients.text() == "0/1") {
261 }, "wait for status", 4 * 1000);
265 var clients = $("div#mkwsStat span.clients");
266 debug("span.clients: " + clients.text());
267 expect(clients.text()).toEqual("0/1");
273 describe("All tests are done", function () {
274 it(">>> hooray <<<", function () {});