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 function get_hit_counter() {
10 if ($("#mkwsPager").length == 0) return -1;
12 var found = $("#mkwsPager").text();
13 var re = /found: ([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 $("input#mkwsQuery").val("freebsd");
41 expect($("input#mkwsQuery").val()).toMatch(/^freebsd$/);
43 setTimeout(function () {
44 $("input#mkwsButton").trigger("click");
50 describe("Check pazpar2 navigation", function () {
52 it("check running search next/prev", function () {
53 expect($("#mkwsPager").length == 1).toBe(true);
55 function my_click(id, time) {
56 setTimeout(function () {
57 debug("trigger click on id: " + id);
58 var click = $(id).trigger("click");
60 debug("next click is success: " + click.length);
61 expect(click.length == 1).toBe(true);
67 // click next/prev after N seconds
68 my_click("#mkwsNext", 7);
69 my_click("#mkwsNext", 8);
70 my_click("#mkwsPrev", 9);
76 describe("Check pazpar2 hit counter", function () {
78 it("check running search hit counter", function () {
79 var max_time = 10; // in seconds
80 var expected_hits = 116; //
84 function found(time, none) {
85 setTimeout(function () {
87 hits = get_hit_counter();
89 // debug("found: " + found);
91 expect(hits < 0).toBeTruthy();
96 debug("mkws pager found records: '" + hits + "'");
97 debug("time state: " + j_time);
99 expect(time >= 0).toBeTruthy();
104 // check hit counter after N seconds
112 waitsFor(function () {
113 return j_time == max_time ? true : false;
114 }, "The Value should be 20 seconds", max_time * 1000);
118 expect($("#mkwsPager").length == 1).toBe(true);
122 expect(j_time <= max_time).toBeTruthy();
123 expect(j_hits).toBeGreaterThan(expected_hits);
128 describe("Check Termlist", function () {
129 function show_record() {
130 var click = $("div#mkwsRecords div.record:nth-child(3) :nth-child(2)").trigger("click");
131 debug("show click is success: " + click.length);
132 expect(click.length == 1).toBe(true);
136 it("found Termlist", function () {
137 var termlist = $("div#mkwsTermlists");
138 debug("Termlist success: " + termlist.length);
139 expect(termlist.length == 1).toBe(true);
141 var sources = $("div#mkwsFacetSources");
142 expect(sources.length == 1).toBe(true);
144 var subjects = $("div#mkwsFacetSubjects");
145 expect(subjects.length == 1).toBe(true);
147 var authors = $("div#mkwsFacetAuthors");
148 expect(authors.length == 1).toBe(true);
151 it("limit search to first source", function () {
152 var hits_all_targets = get_hit_counter();
154 var click = $("div#mkwsFacetSources div.term:nth-child(2) a").trigger("click");
155 debug("limit source click is success: " + click.length);
156 expect(click.length == 1).toBe(true);
158 waitsFor(function () {
159 if ($("div#mkwsNavi").length && $("div#mkwsNavi").text().match(/^Source/)) {
164 }, "Search for source in navi bar", 1000);
166 waitsFor(function () {
167 return get_hit_counter() < hits_all_targets ? true : false;
168 }, "Search for with less hits", 9 * 1000);
171 var hits_single_target = get_hit_counter();
172 debug("get less hits for sources: " + hits_all_targets + " > " + hits_single_target);
173 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
177 it("limit search to first author", function () {
178 var hits_all_targets = get_hit_counter();
180 var click = $("div#mkwsFacetAuthors div.term:nth-child(2) a").trigger("click");
181 debug("limit author click is success: " + click.length);
182 expect(click.length == 1).toBe(true);
184 waitsFor(function () {
185 return get_hit_counter() < hits_all_targets ? true : false;
186 }, "Search for with less hits", 9 * 1000);
189 var hits_single_target = get_hit_counter();
190 debug("get less hits for authors: " + hits_all_targets + " > " + hits_single_target);
191 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
195 it("show record author", function () {
200 describe("Check status client counter", function () {
201 function get_time() {
202 var date = new Date();
203 return date.getTime();
205 var time = get_time();
207 it("check status clients", function () {
209 waitsFor(function () {
210 var clients = $("div#mkwsStat span.clients");
211 if (clients.length == 1 && clients.text() == "0/1") {
217 }, "wait for status", 4 * 1000);
221 var clients = $("div#mkwsStat span.clients");
222 debug("span.clients: " + clients.text());
223 expect(clients.text()).toEqual("0/1");