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);
77 // click next/prev after N seconds
78 my_click("#mkwsNext", 7);
79 my_click("#mkwsNext", 8);
80 my_click("#mkwsPrev", 9);
85 describe("Check pazpar2 hit counter", function () {
86 it("check running search hit counter", function () {
87 var max_time = 10; // in seconds
88 var expected_hits = 116; // at least expected hit counter
92 waitsFor(function () {
93 hits = get_hit_counter();
95 return hits >= expected_hits;
96 }, "Expect N hits in x seconds", max_time * 1000);
100 debug("mkws pager found records: '" + hits + "'");
101 expect($("#mkwsPager").length == 1).toBe(true);
102 expect(hits).toBeGreaterThan(expected_hits);
107 describe("Check Termlist", function () {
108 function show_record() {
109 var click = $("div#mkwsRecords div.record:nth-child(3) :nth-child(2)").trigger("click");
110 debug("show click is success: " + click.length);
111 expect(click.length == 1).toBe(true);
115 it("found Termlist", function () {
116 var termlist = $("div#mkwsTermlists");
117 debug("Termlist success: " + termlist.length);
118 expect(termlist.length == 1).toBe(true);
120 var sources = $("div#mkwsFacetSources");
121 expect(sources.length == 1).toBe(true);
123 var subjects = $("div#mkwsFacetSubjects");
124 expect(subjects.length == 1).toBe(true);
126 var authors = $("div#mkwsFacetAuthors");
127 expect(authors.length == 1).toBe(true);
130 it("limit search to first source", function () {
131 var hits_all_targets = get_hit_counter();
133 var click = $("div#mkwsFacetSources div.term:nth-child(2) a").trigger("click");
134 debug("limit source click is success: " + click.length);
135 expect(click.length == 1).toBe(true);
137 waitsFor(function () {
138 if ($("div#mkwsNavi").length && $("div#mkwsNavi").text().match(/^Source/)) {
143 }, "Search for source in navi bar", 1000);
145 waitsFor(function () {
146 return get_hit_counter() < hits_all_targets ? true : false;
147 }, "Search for with less hits", 9 * 1000);
150 var hits_single_target = get_hit_counter();
151 debug("get less hits for sources: " + hits_all_targets + " > " + hits_single_target);
152 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
156 it("limit search to first author", function () {
157 var hits_all_targets = get_hit_counter();
159 var click = $("div#mkwsFacetAuthors div.term:nth-child(2) a").trigger("click");
160 debug("limit author click is success: " + click.length);
161 expect(click.length == 1).toBe(true);
163 waitsFor(function () {
164 return get_hit_counter() < hits_all_targets ? true : false;
165 }, "Search for with less hits", 9 * 1000);
168 var hits_single_target = get_hit_counter();
169 debug("get less hits for authors: " + hits_all_targets + " > " + hits_single_target);
170 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
174 it("show record author", function () {
179 describe("Check status client counter", function () {
180 function get_time() {
181 var date = new Date();
182 return date.getTime();
184 var time = get_time();
186 it("check status clients", function () {
188 waitsFor(function () {
189 var clients = $("div#mkwsStat span.clients");
190 if (clients.length == 1 && clients.text() == "0/1") {
196 }, "wait for status", 4 * 1000);
200 var clients = $("div#mkwsStat span.clients");
201 debug("span.clients: " + clients.text());
202 expect(clients.text()).toEqual("0/1");
208 describe("All tests are done", function () {
209 it(">>> hooray!!! <<<", function () {