1 /* Copyright (c) 2013 IndexData ApS. http://indexdata.com
3 * perform papzpar2 / pz2.js search & retrieve request in the browser
7 function get_hit_counter() {
8 if ($("#mkwsPager").length == 0) return -1;
10 var found = $("#mkwsPager").text();
11 var re = /found: ([0-9]+)/;
16 hits = parseInt(RegExp.$1);
17 expect(hits).toBeGreaterThan(0);
20 //debug("Hits: " + hits);
24 describe("Check pazpar2 search", function () {
25 it("pazpar2 was successfully initialize", function () {
26 expect(mkws_config.error).toBe(undefined);
29 it("validate HTML id's", function () {
30 expect($("input#mkwsQuery").length == 1).toBe(true);
31 expect($("input#mkwsButton").length == 1).toBe(true);
33 expect($("#mkwsNext").length == 1).toBe(false);
34 expect($("#mkwsPrev").length == 1).toBe(false);
37 it("run search query", function () {
38 $("input#mkwsQuery").val("freebsd");
39 expect($("input#mkwsQuery").val()).toMatch(/^freebsd$/);
41 setTimeout(function () {
42 $("input#mkwsButton").trigger("click");
48 describe("Check pazpar2 navigation", function () {
50 it("check running search next/prev", function () {
51 expect($("#mkwsPager").length == 1).toBe(true);
53 function my_click(id, time) {
54 setTimeout(function () {
55 debug("trigger click on id: " + id);
56 var click = $(id).trigger("click");
58 debug("next click is success: " + click.length);
59 expect(click.length == 1).toBe(true);
65 // click next/prev after N seconds
66 my_click("#mkwsNext", 7);
67 my_click("#mkwsNext", 8);
68 my_click("#mkwsPrev", 9);
74 describe("Check pazpar2 hit counter", function () {
76 it("check running search hit counter", function () {
77 var max_time = 10; // in seconds
78 var expected_hits = 116; //
82 function found(time, none) {
83 setTimeout(function () {
85 hits = get_hit_counter();
87 // debug("found: " + found);
89 expect(hits < 0).toBeTruthy();
94 debug("mkws pager found records: '" + hits + "'");
95 debug("time state: " + j_time);
97 expect(time >= 0).toBeTruthy();
102 // check hit counter after N seconds
110 waitsFor(function () {
111 return j_time == max_time ? true : false;
112 }, "The Value should be 20 seconds", max_time * 1000);
116 expect($("#mkwsPager").length == 1).toBe(true);
120 expect(j_time <= max_time).toBeTruthy();
121 expect(j_hits).toBeGreaterThan(expected_hits);
126 describe("Check Termlist", function () {
127 function show_record() {
128 var click = $("div#mkwsRecords div.record:nth-child(3) :nth-child(2)").trigger("click");
129 debug("show click is success: " + click.length);
130 expect(click.length == 1).toBe(true);
134 it("found Termlist", function () {
135 var termlist = $("div#mkwsTermlists");
136 debug("Termlist success: " + termlist.length);
137 expect(termlist.length == 1).toBe(true);
139 var sources = $("div#mkwsFacetSources");
140 expect(sources.length == 1).toBe(true);
142 var subjects = $("div#mkwsFacetSubjects");
143 expect(subjects.length == 1).toBe(true);
145 var authors = $("div#mkwsFacetAuthors");
146 expect(authors.length == 1).toBe(true);
149 it("Limit search to first source", function () {
150 var hits_all_targets = get_hit_counter();
152 var click = $("div#mkwsFacetSources div.term:nth-child(2) a").trigger("click");
153 debug("limit source click is success: " + click.length);
154 expect(click.length == 1).toBe(true);
156 waitsFor(function () {
157 if ($("div#mkwsNavi").length && $("div#mkwsNavi").text().match(/^Source/)) {
162 }, "Search for source in navi bar", 1000);
164 waitsFor(function () {
165 return get_hit_counter() < hits_all_targets ? true : false;
166 }, "Search for with less hits", 9 * 1000);
169 var hits_single_target = get_hit_counter();
170 debug("get less hits for sources: " + hits_all_targets + " > " + hits_single_target);
171 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
175 it("Limit search to first author", function () {
176 var hits_all_targets = get_hit_counter();
178 var click = $("div#mkwsFacetAuthors div.term:nth-child(2) a").trigger("click");
179 debug("limit author click is success: " + click.length);
180 expect(click.length == 1).toBe(true);
182 waitsFor(function () {
183 return get_hit_counter() < hits_all_targets ? true : false;
184 }, "Search for with less hits", 9 * 1000);
187 var hits_single_target = get_hit_counter();
188 debug("get less hits for authors: " + hits_all_targets + " > " + hits_single_target);
189 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
193 it("Show record author", function () {
198 describe("Check status client counter", function () {
199 function get_time() {
200 var date = new Date();
201 return date.getTime();
203 var time = get_time();
205 it("Limit search to first author", function () {
207 waitsFor(function () {
208 var clients = $("div#mkwsStat span.clients");
209 if (clients.length == 1 && clients.text() == "0/1") {
215 }, "wait for status", 4 * 1000);
219 var clients = $("div#mkwsStat span.clients");
220 debug("span.clients: " + clients.text());
221 expect(clients.text()).toEqual("0/1");