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("Submit search");
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);
77 // click next/prev after N seconds
78 my_click("#mkwsNext", 7);
79 my_click("#mkwsNext", 8);
80 my_click("#mkwsPrev", 9);
86 describe("Check pazpar2 hit counter", function () {
88 it("check running search hit counter", function () {
89 var max_time = 10; // in seconds
90 var expected_hits = 116; //
94 function found(time, none) {
95 setTimeout(function () {
97 hits = get_hit_counter();
99 // debug("found: " + found);
101 expect(hits < 0).toBeTruthy();
106 debug("mkws pager found records: '" + hits + "'");
107 debug("time state: " + j_time);
109 expect(time >= 0).toBeTruthy();
114 // check hit counter after N seconds
122 waitsFor(function () {
123 return j_time == max_time ? true : false;
124 }, "The Value should be 20 seconds", max_time * 1000);
128 expect($("#mkwsPager").length == 1).toBe(true);
132 expect(j_time <= max_time).toBeTruthy();
133 expect(j_hits).toBeGreaterThan(expected_hits);
138 describe("Check Termlist", function () {
139 function show_record() {
140 var click = $("div#mkwsRecords div.record:nth-child(3) :nth-child(2)").trigger("click");
141 debug("show click is success: " + click.length);
142 expect(click.length == 1).toBe(true);
146 it("found Termlist", function () {
147 var termlist = $("div#mkwsTermlists");
148 debug("Termlist success: " + termlist.length);
149 expect(termlist.length == 1).toBe(true);
151 var sources = $("div#mkwsFacetSources");
152 expect(sources.length == 1).toBe(true);
154 var subjects = $("div#mkwsFacetSubjects");
155 expect(subjects.length == 1).toBe(true);
157 var authors = $("div#mkwsFacetAuthors");
158 expect(authors.length == 1).toBe(true);
161 it("limit search to first source", function () {
162 var hits_all_targets = get_hit_counter();
164 var click = $("div#mkwsFacetSources div.term:nth-child(2) a").trigger("click");
165 debug("limit source click is success: " + click.length);
166 expect(click.length == 1).toBe(true);
168 waitsFor(function () {
169 if ($("div#mkwsNavi").length && $("div#mkwsNavi").text().match(/^Source/)) {
174 }, "Search for source in navi bar", 1000);
176 waitsFor(function () {
177 return get_hit_counter() < hits_all_targets ? true : false;
178 }, "Search for with less hits", 9 * 1000);
181 var hits_single_target = get_hit_counter();
182 debug("get less hits for sources: " + hits_all_targets + " > " + hits_single_target);
183 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
187 it("limit search to first author", function () {
188 var hits_all_targets = get_hit_counter();
190 var click = $("div#mkwsFacetAuthors div.term:nth-child(2) a").trigger("click");
191 debug("limit author click is success: " + click.length);
192 expect(click.length == 1).toBe(true);
194 waitsFor(function () {
195 return get_hit_counter() < hits_all_targets ? true : false;
196 }, "Search for with less hits", 9 * 1000);
199 var hits_single_target = get_hit_counter();
200 debug("get less hits for authors: " + hits_all_targets + " > " + hits_single_target);
201 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
205 it("show record author", function () {
210 describe("Check status client counter", function () {
211 function get_time() {
212 var date = new Date();
213 return date.getTime();
215 var time = get_time();
217 it("check status clients", function () {
219 waitsFor(function () {
220 var clients = $("div#mkwsStat span.clients");
221 if (clients.length == 1 && clients.text() == "0/1") {
227 }, "wait for status", 4 * 1000);
231 var clients = $("div#mkwsStat span.clients");
232 debug("span.clients: " + clients.text());
233 expect(clients.text()).toEqual("0/1");