1 /* Copyright (c) 2013 IndexData ApS. http://indexdata.com
3 * perform papzpar2 / pz2.js search & retrieve request in the browser
7 describe("Check pazpar2 search", function () {
8 it("pazpar2 was successfully initialize", function () {
9 expect(mkws_config.error).toBe(undefined);
12 it("validate HTML id's", function () {
13 expect($("input#mkwsQuery").length == 1).toBe(true);
14 expect($("input#mkwsButton").length == 1).toBe(true);
16 expect($("#mkwsNext").length == 1).toBe(false);
17 expect($("#mkwsPrev").length == 1).toBe(false);
20 it("run search query", function () {
21 $("input#mkwsQuery").val("freebsd");
22 expect($("input#mkwsQuery").val()).toMatch(/^freebsd$/);
24 setTimeout(function () {
25 $("input#mkwsButton").trigger("click");
31 describe("Check pazpar2 navigation", function () {
33 it("check running search next/prev", function () {
34 expect($("#mkwsPager").length == 1).toBe(true);
36 function my_click(id, time) {
37 setTimeout(function () {
38 debug("trigger click on id: " + id);
39 var click = $(id).trigger("click");
41 debug("next click is success: " + click.length);
42 expect(click.length == 1).toBe(true);
48 // click next/prev after N seconds
49 my_click("#mkwsNext", 7);
50 my_click("#mkwsNext", 8);
51 my_click("#mkwsPrev", 9);
57 describe("Check pazpar2 hit counter", function () {
58 function get_hit_counter() {
59 if ($("#mkwsPager").length == 0) return -1;
61 var found = $("#mkwsPager").text();
62 var re = /found: ([0-9]+)/;
67 hits = parseInt(RegExp.$1);
68 expect(hits).toBeGreaterThan(0);
71 debug("Hits: " + hits);
75 function show_record() {
76 var click = $("div#mkwsRecords div.record:nth-child(3) :nth-child(2)").trigger("click");
77 debug("show click is success: " + click.length);
78 expect(click.length == 1).toBe(true);
81 it("check running search hit counter", function () {
82 var max_time = 10; // in seconds
83 var expected_hits = 116; //
87 function found(time, none) {
88 setTimeout(function () {
90 hits = get_hit_counter();
92 // debug("found: " + found);
94 expect(hits < 0).toBeTruthy();
99 debug("mkws pager found records: '" + hits + "'");
100 debug("time state: " + j_time);
102 expect(time >= 0).toBeTruthy();
107 // check hit counter after N seconds
115 waitsFor(function () {
116 return j_time == max_time ? true : false;
117 }, "The Value should be 20 seconds", max_time * 1000);
121 expect($("#mkwsPager").length == 1).toBe(true);
125 expect(j_time <= max_time).toBeTruthy();
126 expect(j_hits).toBeGreaterThan(expected_hits);
131 it("found Termlist", function () {
132 var termlist = $("div#mkwsTermlists");
133 debug("Termlist success: " + termlist.length);
134 expect(termlist.length == 1).toBe(true);
136 var sources = $("div#mkwsFacetSources");
137 expect(sources.length == 1).toBe(true);
139 var subjects = $("div#mkwsFacetSubjects");
140 expect(subjects.length == 1).toBe(true);
142 var authors = $("div#mkwsFacetAuthors");
143 expect(authors.length == 1).toBe(true);
146 it("Limit search to first source", function () {
147 var hits_all_targets = get_hit_counter();
149 var click = $("div#mkwsFacetSources div.term:nth-child(2) a").trigger("click");
150 debug("limit source click is success: " + click.length);
151 expect(click.length == 1).toBe(true);
153 waitsFor(function () {
154 if ($("div#mkwsNavi").length && $("div#mkwsNavi").text().match(/^Source/)) {
159 }, "Search for source in navi bar", 1000);
161 waitsFor(function () {
162 return get_hit_counter() < hits_all_targets ? true : false;
163 }, "Search for with less hits", 9 * 1000);
166 var hits_single_target = get_hit_counter();
167 debug("get less hits for sources: " + hits_all_targets + " > " + hits_single_target);
168 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
172 it("Show record", function () {
173 function get_time() {
174 var date = new Date();
175 return date.getTime();
177 var time = get_time();
179 waitsFor(function () {
180 return get_time() > time ? true : false;
181 }, "wait a second", 1 * 1000);
189 it("Limit search to first author", function () {
190 var hits_all_targets = get_hit_counter();
192 var click = $("div#mkwsFacetAuthors div.term:nth-child(2) a").trigger("click");
193 debug("limit author click is success: " + click.length);
194 expect(click.length == 1).toBe(true);
196 waitsFor(function () {
197 return get_hit_counter() < hits_all_targets ? true : false;
198 }, "Search for with less hits", 9 * 1000);
201 var hits_single_target = get_hit_counter();
202 debug("get less hits for authors: " + hits_all_targets + " > " + hits_single_target);
203 expect(hits_all_targets).toBeGreaterThan(hits_single_target);
207 it("Show record", function () {