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
42 $("input#mkwsQuery").val(search_query);
43 debug("set search query: " + search_query)
44 expect($("input#mkwsQuery").val()).toMatch("^" + search_query + "$");
46 // wait for service proxy auth
47 waitsFor(function () {
48 return mkws.service_proxy_auth;
49 }, "SP auth done", 10 * 1000);
52 debug("Click on submit button");
53 var click = $("input#mkwsButton").trigger("click");
54 expect(click.length == 1).toBe(true);
60 describe("Check pazpar2 navigation", function () {
62 it("check running search next/prev", function () {
63 expect($("#mkwsPager").length == 1).toBe(true);
65 function my_click(id, time) {
66 setTimeout(function () {
67 debug("trigger click on id: " + id);
68 var click = $(id).trigger("click");
70 debug("next click is success: " + click.length);
71 expect(click.length == 1).toBe(true);
75 waitsFor(function () {
76 return $("div#mkwsPager div:nth-child(2) a").length >= 2 ? true : false;
77 }, "Expect next link 2", 5 * 1000);
80 // click next/prev after N seconds
81 my_click("#mkwsNext", 0);
84 waitsFor(function () {
85 return $("div#mkwsPager div:nth-child(2) a").length >= 3 ? true : false;
86 }, "Expect next link 3", 5 * 1000);
89 // click next/prev after N seconds
90 my_click("#mkwsNext", 0);
91 my_click("#mkwsPrev", 0.2);
96 describe("Check pazpar2 hit counter", function () {
97 it("check running search hit counter", function () {
98 var max_time = 10; // in seconds
99 var expected_hits = 116; // at least expected hit counter
103 waitsFor(function () {
104 hits = get_hit_counter();
106 return hits >= expected_hits;
107 }, "Expect N hits in x seconds", max_time * 1000);
111 debug("mkws pager found records: '" + hits + "'");
112 expect($("#mkwsPager").length == 1).toBe(true);
113 expect(hits).toBeGreaterThan(expected_hits);
118 describe("Check Termlist", function () {
119 function show_record() {
120 var click = $("div#mkwsRecords div.record:nth-child(3) :nth-child(2)").trigger("click");
121 debug("show click is success: " + click.length);
122 expect(click.length == 1).toBe(true);
126 it("found Termlist", function () {
127 var termlist = $("div#mkwsTermlists");
128 debug("Termlist success: " + termlist.length);
129 expect(termlist.length == 1).toBe(true);
131 var sources = $("div#mkwsFacetSources");
132 expect(sources.length == 1).toBe(true);
134 var subjects = $("div#mkwsFacetSubjects");
135 expect(subjects.length == 1).toBe(true);
137 var authors = $("div#mkwsFacetAuthors");
138 expect(authors.length == 1).toBe(true);
141 it("limit search to first source", function () {
142 var hits_all_targets = get_hit_counter();
144 var click = $("div#mkwsFacetSources div.term:nth-child(2) a").trigger("click");
145 debug("limit source click is success: " + click.length);
146 expect(click.length == 1).toBe(true);
148 waitsFor(function () {
149 if ($("div#mkwsNavi").length && $("div#mkwsNavi").text().match(/^Source/)) {
154 }, "Search for source in navi bar", 1000);
156 waitsFor(function () {
157 return get_hit_counter() < hits_all_targets ? true : false;
158 }, "Search for with less hits", 9 * 1000);
161 var hits_single_target = get_hit_counter();
162 debug("get less hits for sources: " + hits_all_targets + " > " + hits_single_target);
163 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
167 it("limit search to first author", function () {
168 var hits_all_targets = get_hit_counter();
170 var click = $("div#mkwsFacetAuthors div.term:nth-child(2) a").trigger("click");
171 debug("limit author click is success: " + click.length);
172 expect(click.length == 1).toBe(true);
174 waitsFor(function () {
175 return get_hit_counter() < hits_all_targets ? true : false;
176 }, "Search for with less hits", 9 * 1000);
179 var hits_single_target = get_hit_counter();
180 debug("get less hits for authors: " + hits_all_targets + " > " + hits_single_target);
181 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
185 it("show record author", function () {
190 describe("Check status client counter", function () {
191 function get_time() {
192 var date = new Date();
193 return date.getTime();
195 var time = get_time();
197 it("check status clients", function () {
199 waitsFor(function () {
200 var clients = $("div#mkwsStat span.clients");
201 if (clients.length == 1 && clients.text() == "0/1") {
207 }, "wait for status", 4 * 1000);
211 var clients = $("div#mkwsStat span.clients");
212 debug("span.clients: " + clients.text());
213 expect(clients.text()).toEqual("0/1");
218 //describe("Check switch menu Records/Targets", function () {
219 // var div = $("div#mkwsSwitch");
220 //// if (div.length == 0) {
221 //// debug("mkwsSwitch does not exists, skip test");
226 // it("check mkwsSwitch", function () {
227 // expect($("div#mkwsSwitch").length).toBe(1);
229 // // expect 2 clickable links
230 // expect( $("div#mkwsSwitch a").length).toBe(2);
233 // it("switch to target view", function () {
234 // var click = $("a#mkwsSwitch_targets").trigger("click");
235 // debug("target click is success: " + click.length);
236 // expect(click.length == 1).toBe(true);
238 // // now the target table must be visible
240 // expect($("div#mkwsBytarget").is(":visible")).toBe(true);
242 // expect($("div#mkwsResults").is(":visible")).toBe(true);
244 // // look for table header
245 // expect($("div#mkwsBytarget").html()).toMatch(/Target ID/);
249 // it("switch back to record view", function () {
250 // var click = $("div#mkwsSwitch a:nth-child(0)").trigger("click");
251 // debug("record click is success: " + click.length);
252 // expect(click.length == 1).toBe(true);
254 // // now the target table must be in-visible again
255 // var bytarget = $("div#mkwsBytarget:visible");
256 // var byrecords = $("div#mkwsResults:visible");
257 // expect(bytarget.length == 1).toBe(false);
258 // expect(byrecords.length == 1).toBe(true);
264 describe("All tests are done", function () {
265 it("xxx >>> hooray!!! <<<", function () {